分类 默认分类 下的文章

在Windows Server 2012 Core上安装SQL Server 2012 Core Edition

首先要谈一下为什么要在Core模式上安装SQL。主要原因就是-这是个服务器,不需要向客户端一样的华丽的GUI,只要安装配置完成之后,基本上不愿意对它进行操作。当然更重要的是对于服务器来说最重要的是性能、稳定性、安全性、可用性这些指标。从性能上来说其实Core模式上的SQL Server并没有什么变化,所以我更看重的是安全性和可用性。毕竟对于SQL Server来说GUI是不需要的,IE也是不需要的,这样相关的补丁就少多了,如果你仔细看微软的补丁,很多都与GUI相关。如果需要GUI完全可以通过远程管理的方式来实现。在客户端上安装服务器管理工具和SSMS,也就不会在意服务器是不是有GUI了。我们需要的就是服务器能在哪里老老实实的干活,究竟是什么模式?Who Care?另外有一点不得不说,在Core模式下安装SQL Server你只能选择通过命令行来进行安装,安装的速度快很多,之前安装SQL Server 2012多数时间都是在等待UI,从部署的效率来讲,Core模式是最佳选择。

整个安装的过程非常的简单,在虚拟机上安装Windows Server 2012 Core最多10分钟就能搞定。安装完成之后需要安装一下.net framework 3.5.1,这个安装可以通过dism命令来实现,只不过需要注意一点,需要指定Source参数

DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:d:\sources\sxs

也就是说需要你提供Windows Server 2012的安装文件,否则没法安装。

安装完成之后就可以把ISO换成SQL Server的安装文件了,我的安装文件是从MSDN上下载的,不知道到Core Edition与其他的安装介质是否有区别,其他的应该也可以(没测试过),貌似这个Core Edition应该是一个子集。 安装的时候需要一些参数

Setup.exe /q /ACTION=Install /FEATURES=SQL /INSTANCENAME=MSSQLSERVER /SQLSVCACCOUNT="" /SQLSVCPASSWORD="" /SQLSYSADMINACCOUNTS="" /AGTSVCACCOUNT="NT AUTHORITY\Network Service" /IACCEPTSQLSERVERLICENSETERMS

那个SQLSYSADMINACCOUNTS是必须的,其他的启动帐号都可以可选,如果需要SQL验证,需要添加一个SecurityMode和PWD参数,具体的参数可以参考 http://msdn.microsoft.com/en-us/library/ms144259.aspx 如果只安装DB Engine,整个过程应该在15分钟左右。

在Windows server 2019 Core 版本上安装SQL2016

安装系统后,通过网络等方式先把安装ISO的文件copy过来,虚拟机则用挂一个虚拟光驱即可,然后cd进入目录,执行以下命名即可安装核心服务了:

Setup.exe /qs /ACTION=Install /FEATURES=SQLEngine,Replication /INSTANCENAME=MSSQLSERVER /SQLSVCACCOUNT="计算机名\登陆用户名" /SQLSVCPASSWORD="windows的登陆密码" /SQLSYSADMINACCOUNTS="计算机名\登陆用户名" /AGTSVCACCOUNT="NT AUTHORITY\Network Service" /TCPENABLED=1 /IACCEPTSQLSERVERLICENSETERMS /SECURITYMODE=SQL /SAPWD=sa的密码
安装完成后,后端口打开,以便管理工具连接:

netsh firewall set portopening protocol = TCP port = 1433 name = SQLPort mode = ENABLE scope = SUBNET profile = CURRENT

netsh advfirewall firewall add rule name = SQLPort dir = in protocol = tcp action = allow localport = 1433 remoteip = localsubnet profile = DOMAIN

使用sql命令行工具sqlcmd.exe进行创建数据库与执行sql查询

1、找到sqlcmd.exe路径
c:\> dir sqlcmd.exe /s
结果显示如下:
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn 的目录

2、将上面路径添加到path中
c:\> path=%path%;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn;

3、执行sqlcmd.exe进入sql命令行
c:\> sqlcmd.exe
1>

4、创建数据库test
1> create database test;
2> go
5、更改当前数据库为test
1> use test;
2> go
6、创建一个表:users
1> create table users( id int, username varchar(32), password varchar(32));
2> go
7、查询表:
1> select * from users;
2> go

https://www.cnblogs.com/linyidian/p/9703412.html
1、一台电脑的网站服务器架构
2、应用程序、文件、数据库三者分离
3、利用缓存改善网站性能
4、利用集群改善应用服务器性能——负载均衡服务器
5、数据库读写分离
6、数据库分库分表
7、利用CDN和反向代理提高网站性能
8、使用分布式存储系统
9、使用搜索引擎和NoSql
10、应用程序服务业务拆分
11、搭建分布式服务

Windows Admin Center 是一个基于浏览器的图形管理工具,可以在 Server Core 运行环境中取代服务器管理和 MMC。可以通过一台Windows Admin Center管理多台windows server core.

您可以按以下步骤安装 Windows Admin Center。

1、下载Windows Admin Center
curl -o WindowsAdminCenter1904.msi https://download.microsoft.com/download/1/0/5/1059800B-F375-451C-B37E-758FFC7C8C8B/WindowsAdminCenter1904.msi
或者
curl -o https://www.msdgq.com:4433/blog/usr/uploads/2020/01/2150990991.msi
curl -o WindowsAdminCenter2311.msi https://download.microsoft.com/download/1/0/5/1059800B-F375-451C-B37E-758FFC7C8C8B/WindowsAdminCenter2311.msi

2、安装Windows Admin Center
msiexec /i c:WindowsAdminCenter1904.msi /qn /L*v log.txt SME_PORT=443 SSL_CERTIFICATE_OPTION=generate

3、 通过浏览器访问https://ip/

4、Windows Admin Center管理的项目:

winadmincenter.jpg

基本配置

sconfig

在powershell命令cmdlet中

查看已经启用的角色与功能

Get-WindowsFeature

安装IIS角色

Install-WindowsFeature web-server

安装 .NET Extensibility4.5

install-windowsfeature Web-Net-Ext45

安装 ASP.NET 4.7

install-windowsfeature web-asp-net45

可以将上面几个命令合并在一起执行

Install-WindowsFeature web-server,Web-Net-Ext45,web-asp-net45

对比:

查看所有防火墙入站策略
netsh advfirewall firewall show rule name=all dir=in

查看所有防火墙入站策略中包含ICMP字符串
netsh advfirewall firewall show rule name=all dir=in| find "ICMP"

修改防火墙规则
name:规则名称
dir:方向,in为入站,out为出站
localport:指定端口号
action:操作,allow允许连接,block阻止连接
enable:是否启用规则: yes启用, no禁用
protocol:协议类型

netsh advfirewall firewall set rule name="文件和打印机共享(回显请求 - ICMPv4-In)" dir=in new enable=yes

案例1: 允许一个程序
netsh advfirewall firewall add rule name="My Application" dir=in action=allow program="C:\MyApp\MyApp.exe" enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=domain

netsh advfirewall firewall add rule name="My Application" dir=in action=allow program="C:\MyApp\MyApp.exe" enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=private

案例2: 允许一个端口
netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80

案例3: 删除一条规则
netsh advfirewall firewall delete rule name=rule nameprogram="C:\MyApp\MyApp.exe
netsh advfirewall firewall delete rule name=rule nameprotocol=udp localport=500

案例4: 设置ICMP
netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow

netsh advfirewall firewall add rule name="All ICMP V4" protocol=icmpv4:any,any dir=in action=allow

netsh advfirewall firewall add rule name="Block Type 13 ICMP V4" protocol=icmpv4:13,any dir=in action=block

案例5: 设置logging
netsh advfirewall set currentprofile logging filename %systemroot%\system32\LogFiles\Firewall\pfirewall.log

netsh advfirewall set currentprofile logging maxfilesize 4096
netsh advfirewall set currentprofile logging droppedconnections enable
netsh advfirewall set currentprofile logging allowedconnections enable

案例6: 开启防火墙
netsh advfirewall set currentprofile state on
netsh advfirewall set currentprofile firewallpolicy blockinboundalways,allowoutbound

案例7: 重置防火墙
netsh advfirewall reset

案例8: 允许某个服务
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes profile=domain
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes profile=private

// ===============================================================

恢复到默认设置

Netsh advfirewall reset

导出防火墙配置

netsh advfirewall export “c:\advfirewall.wfw”

导入防火墙配置

Netsh advfirewall import “c:\advfirewall.wfw”

增加一个针对messenger.exe的入站规则

  netsh advfirewall firewall add rule name="allow messenger" dir=in program="c:\programfiles\messenger\msmsgs.exe” action=allow

删除针对本地21端口的所有入站规则:

  netsh advfirewall firewall delete name rule name=all protocol=tcp localport=21

让防火墙关闭所有配置文件:

netsh advfirewall set allprofiles state off

在所有配置文件中设置默认阻挡入站并允许出站通信:

netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound

在所有配置文件中打开远程管理:

netsh advfirewall set allprofiles settings remotemanagement enable

在所有配置文件中记录被断开的连接:

netsh advfirewall set allprofiles logging droppedconnections enable

(1)启用桌面防火墙
netsh advfirewall set allprofiles state on
(2)设置默认输入和输出策略
netsh advfirewall set allprofiles firewallpolicy allowinbound,allowoutbound
以上是设置为允许,如果设置为拒绝使用blockinbound,blockoutbound

(3)关闭tcp协议的139端口

netsh advfirewall firewall add rule name="deny tcp 139" dir=in protocol=tcp localport=139 action=block

(4)关闭udp协议的139端口

netsh advfirewall firewall add rule name="deny udp 139" dir=in protocol=udp localport=139 action=block

(5)关闭tcp协议的445端口

netsh advfirewall firewall add rule name="deny tcp 445" dir=in protocol=tcp localport=445 action=block

(6)关闭udp协议的445端口

netsh advfirewall firewall add rule name="deny udp 445" dir=in protocol=udp localport=445 action=block

(7)使用相同的方法,依次关闭TCP协议的21、22、23、137、138、3389、5800、5900端口。

netsh advfirewall firewall add rule name= "deny tcp 21" dir=in protocol=tcp localport=21 action=block

netsh advfirewall firewall add rule name= "deny tcp 22" dir=in protocol=tcp localport=22 action=block

netsh advfirewall firewall add rule name= "deny tcp 23" dir=in protocol=tcp localport=23 action=block

netsh advfirewall firewall add rule name= "deny tcp 3389" dir=in protocol=tcp localport=3389 action=block

netsh advfirewall firewall add rule name= "deny tcp 5800" dir=in protocol=tcp localport=5800 action=block

netsh advfirewall firewall add rule name= "deny tcp 5900" dir=in protocol=tcp localport=5900 action=block

netsh advfirewall firewall add rule name= "deny tcp 137" dir=in protocol=tcp localport=137 action=block

netsh advfirewall firewall add rule name= "deny tcp 138" dir=in protocol=tcp localport=138 action=block

(8)执行完毕后暂停

pause

echo 按任意键退出

恢复初始配置

(1)恢复初始防火墙设置

netsh advfirewall reset

(2)关闭防火墙

netsh advfirewall set allprofiles state off

补充:

  1. 优先性

GPEDIT.MSC中的策略作用大于FIREWALL高级设置中的设置,比如:

windows 防火墙:允许入站远程桌面例外中 不圈定访问ip,那么在firewall的高级设置中,即便限制了3389端口的IP范围也没用.

2.封对外访问

netsh advfirewall firewall add rule name ="PhaseACL" dir=out remoteip=3.3.3.3 action=block

https://docs.microsoft.com/zh-cn/windows-server/administration/server-core/server-core-administerWindows
http://wangye.org/blog/archives/1222/
https://www.cnblogs.com/yorkzang/p/8891970.html
https://blog.51cto.com/yupeizhi/1955871

管理服务器核心的具体操作命令:
https://www.cnblogs.com/IPYQ/p/6800616.html

Windows PowerShell:管理服务器
https://www.cnblogs.com/edward2013/p/3534443.html

Windows Server 2016 使用 PowerShell cmdlet 安装角色、角色服务和功能
https://blog.csdn.net/sinat_28371057/article/details/90166047

文件夹权限设置

$account = "IIS_IUSRS"
$FileSystemRights = "FullControl"
$objType = [System.Security.AccessControl.AccessControlType]::Allow
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule ($account,$FileSystemRights,$objType)
$Folder = "C:\inetpub\ftproot\RbbioWeb\Web.config"
$acl = Get-Acl $Folder
$acl.SetAccessRule($accessRule)
Set-Acl -Path $Folder -AclObject $acl

Windows Admin Center 管理core

https://docs.microsoft.com/zh-cn/windows-server/manage/windows-admin-center/overview