SQL Server 2014 AlwaysOn 搭建之:PowerShell脚本

一、安装AD(10.10.10.59)

Rename-Computer -NewName WSFC -Restart
Install-WindoSQLwsFeature -Name Net-Framework-Core -source D:\sources\sxs
Install-WindowsFeature -Name PowerShell-V2 -source D:\sources\sxs
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools

Install-ADDSForest –DomainName "his.com"
Install-WindowsFeature RSAT-AD-PowerShell

二、SQL01、SQL02修改主机名,加入域控制器(10.10.10.56、57)

Rename-Computer -NewName SQL01 -Restart
Add-Computer -DomainName his.com -Restart

Rename-Computer -NewName SQL02 -Restart
Add-Computer -DomainName his.com -Restart

# 加入域控,需要开通访问AD服务器的TCP445端口
# 禁用TCP/IP上的NetBIOS
# 以administrator管理员身份登录各个节点,将dcadmin@his.com加入本地Administrator组中。

# 用以下命令替代以上命令
Add-Computer -DomainName <DomainName> -Credential (Get-Credential)

Rename-Computer -ComputerName $env:COMPUTERNAME -DomainCredential (Get-Credential) `
-NewName SQL-DR1 -Restart

三、远程安装集群节点的windows组件:

3.1、安装.Net 3.0

Install-WindowsFeature -Name Net-Framework-Core -source F:\sources\sxs -ComputerName SQL01
Install-WindowsFeature -Name PowerShell-V2 -source F:\sources\sxs -ComputerName SQL01
Get-WindowsFeature *Framework-Core* -ComputerName SQL01

Install-WindowsFeature -Name Net-Framework-Core -source O:\sources\sxs -ComputerName SQL02
Install-WindowsFeature -Name PowerShell-V2 -source O:\sources\sxs -ComputerName SQL02
Get-WindowsFeature *Framework-Core* -ComputerName SQL02

3.2、安装配置WSFC集群

创建集群:cluster,10.10.10.58
Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools -ComputerName SQL01
Get-WindowsFeature -Name "Failover-Clustering", "Telnet-Client" | Install-WindowsFeature -IncludeManagementTool  -ComputerName SQL01
Add-WindowsFeature -Name RSAT-Clustering-AutomationServer -ComputerName SQL01
Add-WindowsFeature -Name RSAT-Clustering-CmdInterface -ComputerName SQL01
Add-WindowsFeature -Name RSAT-Clustering-PowerShell -ComputerName SQL01
Add-WindowsFeature -Name RSAT-Clustering-Mgmt -ComputerName SQL01
Get-WindowsFeature *Cluster* -ComputerName SQL01
get-windowsfeature Failover*  -ComputerName SQL01

Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools -ComputerName SQL02
Get-WindowsFeature -Name "Failover-Clustering", "Telnet-Client" | Install-WindowsFeature -IncludeManagementTool  -ComputerName SQL02
Add-WindowsFeature -Name RSAT-Clustering-AutomationServer -ComputerName SQL02
Add-WindowsFeature -Name RSAT-Clustering-CmdInterface -ComputerName SQL02
Add-WindowsFeature -Name RSAT-Clustering-PowerShell -ComputerName SQL02
Add-WindowsFeature -Name RSAT-Clustering-Mgmt -ComputerName SQL02
Get-WindowsFeature *Cluster* -ComputerName SQL02
get-windowsfeature Failover*  -ComputerName SQL02

New-Cluster -Name cluster -Node SQL01,SQL02 -StaticAddress 10.10.10.58 -NoStorage -AdministrativeAccessPoint DNS 
Add-ClusterNode
添加集群共享文件夹见证:\WSFC\cluster_quorum(需要dcadmin@his.com、everyone的读写权限)
Get-Netadapter -CimSession SQL01 | Where-Object { $_.Status -eq 'Up' }

Microsoft AdvenutreWorks databases (AdventureWorks2014, AdventureWorksLegal, AdventureWorksHR, AdventureWorksFinance)

四、防火墙配置脚本:

netsh advfirewall firewall add rule name="SQL Server (TCP:1433)" dir=in localport=1433 protocol=TCP action=allow

netsh advfirewall firewall add rule name="SQL Admin Connect (TCP:1434)" dir=in localport=1434 protocol=TCP action=allow
netsh advfirewall firewall add rule name="SQL Browser (UDP:1434)" dir=in localport=1434 protocol=UDP action=allow
netsh advfirewall firewall add rule name="SQL Debugger/RPC(TCP:135)" dir=in localport=135 protocol=TCP action=allow
netsh advfirewall firewall add rule name="SQL Always On (TCP:5022)" dir=in localport=5022 protocol=TCP action=allow
netsh advfirewall firewall add rule name="SQL Service Broker (TCP:4022)" dir=in localport=5022 protocol=TCP action=allow

netsh advfirewall firewall add rule name="Medical File Service (TCP:6234)" dir=in localport=6234 protocol=TCP action=allow
netsh advfirewall firewall add rule name="SNMP(UDP:161)" dir=in localport=161 protocol=UDP action=allow
netsh advfirewall firewall add rule name="Iperf Inbound Port 5001~5099" dir=in localport=5001-5099 protocol=TCP action=allow
netsh advfirewall firewall add rule name="Cluster Communication" dir=in action=allow enable=yes remoteip=10.10.10.56-10.10.10.60

netsh advfirewall set allprofiles state on
netsh firewall set logging  %systemroot%system32LogFilesFirewallpfirewall.log 32767 ENABLE

五、安装SQL2014与SP3(略)

查询新盘,使其联机并且初始化:

Get-Disk | Where-Object { $_.FriendlyName -like "PURE FlashArray*" }

Set-Disk -Number 4 -IsOffline $false
Set-Disk -Number 5 -IsOffline $false
Initialize-Disk -Number 4
Initialize-Disk -Number 5
Set-Disk -Number 4 -IsOffline $true
Set-Disk -Number 5 -IsOffline $true

六、配置DFS

Install-WindowsFeature "RSAT-DFS-Mgmt-Con"
Install-WindowsFeature "FS-DFS-Replication"
Install-WindowsFeature "FS-DFS-namespace"
# https://bbs.huaweicloud.com/blogs/157616

New-DfsReplicationGroup -GroupName MFSRV
Add-DfsrMember -ComputerName SQL01.his.com -GroupName MFSRV
Add-DfsrMember -ComputerName SQL02.his.com -GroupName MFSRV

七、配置网络时间(在域控上操作)

w32tm /config /syncfromflags:manual /manualpeerlist:"time.windows.com pool.ntp.org"
w32tm /config /update
w32tm /resync

whoami /user

八、收尾工作

日志备份
两边系统数据库同步(账号、发布订阅、作业)

九、SQL Server 参数调整

9.1、max degree of parallelism:

参数说明:每个执行语句的CPU最大并行度,该参数值默认为0,当你在使用实例时,SQL SERVER会通过查询引擎自动的给你的每一个请求分配CPU执行计划,以通过并行执行的方式有效提升你的执行性能。
参数值对应的场景:
1.当你本地实例以查询获取结果为主,该参数值为0
2.当你本地实例以写入,更新,删除为主,该参数可设置为1

9.2、max server memory (MB)

参数说明:该参数用于控制实例上SQL SERVER数据库服务占用整个服务器的最大内存的上限
参数值对应的场景:
华为RDS SQL SERVER已经根据你的每个实例自身大小做出了对应的适当配置,该值你可不必更改,如果实在要改请注意以下限制条件。
1.不能低于2G
2.不能高于你实例最大内存的95%

9.3、user connections

参数说明:该参数用户控制实例上用户发起的最大连接数
参数值对应的场景:
该参数目前默认为1000,可根据实际情况进行调整。
1.设置为0,该实例连接数不受限制
2.不能设置1-10之间的值

十、通过SSMS远程连接SQL报错:目标主体名称不正确,无法生成 SSPI 上下文。

通过SSMS远程连接SQL报错:目标主体名称不正确,无法生成 SSPI 上下文。
SQL运行在域用户下,服务器也在域中
能通过IP连接,但是不能通过计算机名连接
测试计算机名也能正确解析
最后通过setspn解决

SQL02

RestrictedKrbHost/SQL02.his.com
RestrictedKrbHost/SQL02

setspn -D MSSQLSvc/SQL02.his.com SQL02
setspn -D MSSQLSvc/SQL02.his.com:1433 SQL02
setspn -D MSSQLSvc/sSQL02.his.com:1433
Setspn -D MSSQLSvc/server4.main.local:1433 <Account>
setspn -D MSSQLSvc/SQL02.his.com:1433 dcadmin
SETSPN -A MSSQLSvc/SQL02 SQL02
setspn -D MSSQLSvc/SQL02.his.com:1433 SQL02
点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注