env: Windows Server 2012
SQL Server 2012
一般安裝SQL Server我大多數做法是下一步下一步,但是有一天被要求在短時間並且標準化安裝數台SQL Server,這樣下一步下一步似乎存在一些瓶頸。
因此使用command成為另外一種比較突破瓶頸的方式。
1.了解ConfigurationFile.ini
ConfigurationFile.ini是安裝組態檔,內容是安裝SQL Server的設定值。
若在UI安裝,則會在下面這張圖"準備安裝"產生ConfigurationFile.ini進行安裝。
2.如何製作ConfigurationFile.ini
a.從已經安裝SQL Server的主機複製ConfigurationFile.ini
b.自行從Microsoft網站逐填入設定值
Sample ConfigurationFile.ini for SQL Server 2012 in Domain:
";"開頭表示說明,下一行則次參數名稱。
ACTION="Install"是必要參數
FEATURES=SQLENGINE,SSMS,ADV_SSMS說明安裝SQL Server Engine, SSMS
INSTALLxxxDIR開頭與結尾的字串表示安裝路徑
INSTANCEDIR表示SQL Server安裝路徑
SQLSYSADMINACCOUNTS表示SQL Server sysadmin帳戶,還有ACCOUNT結尾的帳戶需要指定
講到這裡有沒有覺得怪怪的?我們用UI安裝所輸入的密碼呢?
密碼可以透過兩種方式設定:
a.在執行安裝的指令執行
b.在ConfigurationFile.ini指定
例如:
Setup.exe /SQLSVCPASSWORD="************" /AGTSVCPASSWORD="************" /ASSVCPASSWORD="************" /ISSVCPASSWORD="************" /RSSVCPASSWORD="************" /ConfigurationFile=MyConfigurationFile.INI
參考網址:
https://docs.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-using-a-configuration-file?view=sql-server-2017
我們這裡要將密碼寫在ConfigurationFile.ini進行安裝。
所以需要使用參數:AGTSVCPASSWORD, SQLSVCPASSWORD, SAPWD參數
參考網址:
https://docs.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-from-the-command-prompt?view=sql-server-2017
可以直接將下面紅字內容複製並儲存為ConfigurationFile.ini.
;SQL Server 2012 Configuration File
[OPTIONS]
; Specifies a Setup work flow, like INSTALL, UNINSTALL, or UPGRADE. This is a required parameter.
ACTION="Install"
; Detailed help for command line argument ENU has not been defined yet.
ENU="True"
; Parameter that controls the user interface behavior. Valid values are Normal for the full UI,AutoAdvance for a simplied UI, and EnableUIOnServerCore for bypassing Server Core setup GUI block.
UIMODE="AutoAdvance"
; Setup will not display any user interface.
QUIET="False"
; Setup will display progress only, without any user interaction.
QUIETSIMPLE="False"
; Specify whether SQL Server Setup should discover and include product updates. The valid values are True and False or 1 and 0. By default SQL Server Setup will include updates that are found.
UpdateEnabled="False"
; Specifies features to install, uninstall, or upgrade. The list of top-level features include SQL, AS, RS, IS, MDS, and Tools. The SQL feature will install the Database Engine, Replication, Full-Text, and Data Quality Services (DQS) server. The Tools feature will install Management Tools, Books online components, SQL Server Data Tools, and other shared components.
FEATURES=SQLENGINE,SSMS,ADV_SSMS
; Specify the location where SQL Server Setup will obtain product updates. The valid values are "MU" to search Microsoft Update, a valid folder path, a relative path such as .\MyUpdates or a UNC share. By default SQL Server Setup will search Microsoft Update or a Windows Update service through the Window Server Update Services.
UpdateSource="MU"
; Displays the command line parameters usage
HELP="False"
; Specifies that the detailed Setup log should be piped to the console.
INDICATEPROGRESS="False"
; Specifies that Setup should install into WOW64. This command line argument is not supported on an IA64 or a 32-bit system.
X86="False"
; Specify the root installation directory for shared components. This directory remains unchanged after shared components are already installed.
INSTALLSHAREDDIR="C:\Program Files\Microsoft SQL Server"
; Specify the root installation directory for the WOW64 shared components. This directory remains unchanged after WOW64 shared components are already installed.
INSTALLSHAREDWOWDIR="C:\Program Files (x86)\Microsoft SQL Server"
; Specify a default or named instance. MSSQLSERVER is the default instance for non-Express editions and SQLExpress for Express editions. This parameter is required when installing the SQL Server Database Engine (SQL), Analysis Services (AS), or Reporting Services (RS).
INSTANCENAME="MSSQLSERVER"
; Specify the Instance ID for the SQL Server features you have specified. SQL Server directory structure, registry structure, and service names will incorporate the instance ID of the SQL Server instance.
INSTANCEID="MSSQLSERVER"
; Specify that SQL Server feature usage data can be collected and sent to Microsoft. Specify 1 or True to enable and 0 or False to disable this feature.
SQMREPORTING="False"
; Specify if errors can be reported to Microsoft to improve future SQL Server releases. Specify 1 or True to enable and 0 or False to disable this feature.
ERRORREPORTING="False"
; Specify the installation directory.
INSTANCEDIR="C:\Program Files\Microsoft SQL Server"
; Agent account name
AGTSVCACCOUNT="DBA\dbm"
AGTSVCPASSWORD="pa$$w0rd"
; Auto-start service after installation.
AGTSVCSTARTUPTYPE="Automatic"
; CM brick TCP communication port
COMMFABRICPORT="0"
; How matrix will use private networks
COMMFABRICNETWORKLEVEL="0"
; How inter brick communication will be protected
COMMFABRICENCRYPTION="0"
; TCP port used by the CM brick
MATRIXCMBRICKCOMMPORT="0"
; Startup type for the SQL Server service.
SQLSVCSTARTUPTYPE="Automatic"
; Level to enable FILESTREAM feature at (0, 1, 2 or 3).
FILESTREAMLEVEL="2"
FILESTREAMSHARENAME="MSSQLSERVER"
; Set to "1" to enable RANU for SQL Server Express.
ENABLERANU="False"
; Specifies a Windows collation or an SQL collation to use for the Database Engine.
SQLCOLLATION="SQL_Latin1_General_CP1_CI_AS"
; Account for SQL Server service: Domain\User or system account.
SQLSVCACCOUNT="DBA\dbm"
SQLSVCPASSWORD="pa$$w0rd"
; Windows account(s) to provision as SQL Server system administrators.
SQLSYSADMINACCOUNTS="DBA\dbm"
; The default is Windows Authentication. Use "SQL" for Mixed Mode Authentication.
SECURITYMODE="SQL"
SAPWD="pa$$w0rd"
; Provision current user as a Database Engine system administrator for SQL Server 2012 Express.
ADDCURRENTUSERASSQLADMIN="False"
; Specify 0 to disable or 1 to enable the TCP/IP protocol.
TCPENABLED="1"
; Specify 0 to disable or 1 to enable the Named Pipes protocol.
NPENABLED="0"
; Startup type for Browser Service.
BROWSERSVCSTARTUPTYPE="Disabled"
3.在SQL Server 2012前必須安裝".NET Framwork 3.5"
command:
dism /online /enable-feature /featurename:netfx3 /all /source:d:\sources\sxs
掛載Windows Server 2012,執行指令安裝".NET Framwork 3.5"
若Windows Server 2012掛載點不是 D:\,請將指令黃底字改為掛載點即可。
C:\Users\administrator.DBA>dism /online /enable-feature /featurename:netfx3 /all /source:d:\sources\sxs
Deployment Image Servicing and Management tool
Version: 6.2.9200.16384
Image Version: 6.2.9200.16384
Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.
C:\Users\administrator.DBA>
4.執行安裝SQL Server 2012 in silent mode
command:
setup.exe /Q /IACCEPTSQLSERVERLICENSETERMS /configurationfile=c:\ConfigurationFile_sql2k12.ini
Configuration File name:ConfigurationFile_sql2k12.ini
安裝不會有任何畫面,只有成功或失敗警告訊息。
C:\Users\administrator.DBA>cd /D d:\
The device is not ready.
C:\Users\administrator.DBA>cd /D d:\
d:\>setup.exe /Q /IACCEPTSQLSERVERLICENSETERMS /configurationfile=c:\ConfigurationFile_sql2k12.ini
Microsoft (R) SQL Server 2012 11.00.2100.60
Copyright (c) Microsoft Corporation. All rights reserved.
Microsoft (R) .NET Framework CasPol 2.0.50727.6387
Copyright (c) Microsoft Corporation. All rights reserved.
Success
Microsoft (R) .NET Framework CasPol 2.0.50727.6387
Copyright (c) Microsoft Corporation. All rights reserved.
Success