1、優勢html
aways on的優勢,a. 構建主從數據庫,分攤單點數據庫壓力。b.能夠減小數據同步時間,提高用戶體驗。c.能夠實現高可用,自動平滑切換。node
2、缺點web
及時同步最多隻能提交3臺,及時同步會致使各服務器性能降低。數據寫入只能主庫寫入。基於服務器故障轉移羣集服務,須要服務器相互之間信任,非域下,數據服務自己須要互相信任。sql
3、具體實現步驟(基於阿里雲服務器 Windows Server 2016 數據中心GUI版本)數據庫
爲了方便多臺服務器的配置,減小配置時間,一些公共的配置放在此處。服務器
至此,aways on 的配置結束。整個配置過程必須按照順序一步一步進行,不能隨意調整順序,若是調整可能會形成沒法預知的錯誤。若是出錯後不能解決,能夠考慮還原系統的方式來初始化。網絡
注意事項:併發
1. 數據庫權限問題,可使用administrator來解決。app
2. 數據庫證書導出前,必須保證能夠訪問共享文件夾,不然不可繼續,一旦繼續,則會出現沒法解決的錯誤。性能
附錄1:
導出證書
CREATE PROCEDURE CreateEndpointCert @ShareName SYSNAME , @StrongPassword SYSNAME AS BEGIN --This must be executed in the context of Master IF (DB_NAME() <> 'master') BEGIN PRINT N'This SP must be executed in master. USE master and then retry.' RETURN (-1) END DECLARE @DynamicSQL varchar(1000); DECLARE @CompName varchar(250); DECLARE @HasMasterKey INT; SELECT @CompName = CONVERT(SysName, SERVERPROPERTY('MachineName')); -- Only create a master key if it doesn't already exist SELECT @HasMasterKey = is_master_key_encrypted_by_server from sys.databases where name = 'master' IF (@HasMasterKey = 0) BEGIN --Create a MASTER KEY to encrypt the certificate. SET @DynamicSQL = CONCAT('CREATE MASTER KEY ENCRYPTION BY PASSWORD = ' , QUOTENAME(@StrongPassword, '''')); EXEC (@DynamicSQL) END --Create the certificate to authenticate the endpoint SET @DynamicSQL = CONCAT('CREATE CERTIFICATE ', QUOTENAME(@CompName + '-Certificate'), ' WITH SUBJECT = ', QUOTENAME(@CompName, ''''),',EXPIRY_DATE=',QUOTENAME(20991231 ,'''') ) EXEC (@DynamicSQL); --Create the database mirroring endpoint authenticated by the certificate. SET @DynamicSQL = CONCAT('CREATE ENDPOINT Endpoint_Mirroring STATE = STARTED AS TCP (LISTENER_PORT = 5022, LISTENER_IP = ALL) FOR DATABASE_MIRRORING (AUTHENTICATION = CERTIFICATE ',QUOTENAME(@CompName + '-Cert'), ' , ENCRYPTION = REQUIRED ALGORITHM AES, ROLE = ALL)'); EXEC (@DynamicSQL); --Back up the certificate to a common network share for import into other nodes in the cluster SET @DynamicSQL = CONCAT('BACKUP CERTIFICATE ',QUOTENAME(@CompName + '-Cert'),' To FILE = ', QUOTENAME( @ShareName + '\SQL-' + @CompName + '.cer', '''')); EXEC (@DynamicSQL); END GO
導入證書
CREATE PROCEDURE InstallEndpointCert @CompName SYSNAME, @ShareName SYSNAME, @StrongPassword SYSNAME AS BEGIN DECLARE @DynamicSQL varchar(1000); DECLARE @MyCompName varchar(250); SELECT @MyCompName = CONVERT(SysName, SERVERPROPERTY('MachineName')); --Don't need to create LOGINs for the local system IF (@MyCompName <> @CompName) BEGIN SET @DynamicSQL = CONCAT('CREATE LOGIN ', QUOTENAME (@CompName + '-Login'), ' WITH PASSWORD= ', QUOTENAME( @StrongPassword, '''')); EXEC (@DynamicSQL); SET @DynamicSQL = CONCAT('CREATE USER ', QUOTENAME( @CompName + '-User'), ' FOR LOGIN ', QUOTENAME(@CompName + '-Login')); EXEC (@DynamicSQL); SET @DynamicSQL = CONCAT('CREATE CERTIFICATE ', QUOTENAME(@CompName +'-Cert'), ' AUTHORIZATION ', QUOTENAME(@CompName +'-User'), ' FROM FILE = ', QUOTENAME(@ShareName + '\SQL-' + @CompName + '.cer' , '''')); EXEC (@DynamicSQL); SET @DynamicSQL = CONCAT('GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO ', QUOTENAME(@CompName +'-Login')); EXEC (@DynamicSQL); END END GO
附錄2:
附錄3:
修改數據庫名稱,修改後要重啓服務
if serverproperty('servername') <> @@servername begin declare @server sysname set @server = @@servername exec sp_dropserver @server = @server set @server = cast(serverproperty('servername') as sysname) exec sp_addserver @server = @server , @local = 'LOCAL' END
查詢名稱是否一致
use master go select @@servername select serverproperty('servername')
附錄4:
寫入hosts命令:
echo 172.18.12.153 iZiig0d4mlg0ksZ >> C:\Windows\System32\drivers\etc\hosts
附錄5:
十萬服務器併發設置
服務器設置:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
<processModel enable="true" maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50" minIoThreads="50" requestQueueLimit="100000"/>
在%systemroot%\System32\inetsrv\config\applicationHost.config中能夠查看到該設置:
<serverRuntime appConcurrentRequestLimit="100000" />
服務器設置set.bat 內容:
echo "開始設置" reg add HKLM\System\CurrentControlSet\Services\HTTP\Parameters /v MaxConnections /t REG_DWORD /d 100000 reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters /v MaxFieldLength /t REG_DWORD /d 32768 reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters /v MaxRequestBytes /t REG_DWORD /d 32768 reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v MaxUserPort /t REG_DWORD /d 65534 reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v TcpTimedWaitDelay /t REG_DWORD /d 30 net stop http & net start http & iisreset echo "設置結束"
參看連接:
如何在沒有域的環境中搭建AlwaysOn(一)
http://www.cnblogs.com/i6first/p/6040363.html
如何在沒有域的環境中搭建AlwaysOn(二)
http://www.cnblogs.com/i6first/p/6047538.html
ClassLink遷移示例(連接vpc和經典網絡)
https://help.aliyun.com/document_detail/57949.html?spm=5176.doc58095.6.604.5QiNT1
https://help.aliyun.com/document_detail/55051.html
SQL Server 2016 簡體中文企業版(數據庫服務安裝程序)
http://tieba.baidu.com/p/4675269271
下載 SQL Server Management Studio 17.2(數據庫客戶端)
https://docs.microsoft.com/zh-cn/sql/ssms/download-sql-server-management-studio-ssms
十萬鏈接配置
http://www.cnblogs.com/dudu/archive/2013/06/08/iis_webserver_settings.html