在Linux上無人值守安裝SQL Server 2017

來源:互聯網
上載者:User

標籤:ber   password   admin   config   執行   new   win   firewall   資料   

可以按以下步驟執行無人值守安裝:

  • 添加資料庫並安裝SQL Server。

  • 當你運行mssql-conf setup,設定環境變數並使用-n選項(不提示)。

#!/bin/bash -e# Use the following variables to control your install:# Password for the SA user (required)MSSQL_SA_PASSWORD='<YourStrong!Passw0rd>'# Product ID of the version of SQL server you're installing# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key# Defaults to developerMSSQL_PID='evaluation'# Install SQL Server Agent (recommended)SQL_INSTALL_AGENT='y'# Install SQL Server Full Text Search (optional)# SQL_INSTALL_FULLTEXT='y'# Create an additional user with sysadmin privileges (optional)# SQL_INSTALL_USER='<Username>'# SQL_INSTALL_USER_PASSWORD='<YourStrong!Passw0rd>'if [ -z $MSSQL_SA_PASSWORD ]then  echo Environment variable MSSQL_SA_PASSWORD must be set for unattended install  exit 1fiecho Adding Microsoft repositories...sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.reposudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repoecho Installing SQL Server...sudo yum install -y mssql-serverecho Running mssql-conf setup...sudo MSSQL_SA_PASSWORD=$MSSQL_SA_PASSWORD      MSSQL_PID=$MSSQL_PID      /opt/mssql/bin/mssql-conf -n setup accept-eulaecho Installing mssql-tools and unixODBC developer...sudo ACCEPT_EULA=Y yum install -y mssql-tools unixODBC-devel# Add SQL Server tools to the path by default:echo Adding SQL Server tools to your path...echo PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bash_profileecho 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc# Optional SQL Server Agent installation:if [ ! -z $SQL_INSTALL_AGENT ]then  echo Installing SQL Server Agent...  sudo yum install -y mssql-server-agentfi# Optional SQL Server Full Text Search installation:if [ ! -z $SQL_INSTALL_FULLTEXT ]then    echo Installing SQL Server Full-Text Search...    sudo yum install -y mssql-server-ftsfi# Configure firewall to allow TCP port 1433:echo Configuring firewall to allow traffic on port 1433...sudo firewall-cmd --zone=public --add-port=1433/tcp --permanentsudo firewall-cmd --reload# Example of setting post-installation configuration options# Set trace flags 1204 and 1222 for deadlock tracing:#echo Setting trace flags...#sudo /opt/mssql/bin/mssql-conf traceflag 1204 1222 on# Restart SQL Server after making configuration changes:echo Restarting SQL Server...sudo systemctl restart mssql-server# Connect to server and get the version:counter=1errstatus=1while [ $counter -le 5 ] && [ $errstatus = 1 ]do  echo Waiting for SQL Server to start...  sleep 5s  /opt/mssql-tools/bin/sqlcmd     -S localhost     -U SA     -P $MSSQL_SA_PASSWORD     -Q "SELECT @@VERSION" 2>/dev/null  errstatus=$?  ((counter++))done# Display error if connection failed:if [ $errstatus = 1 ]then  echo Cannot connect to SQL Server, installation aborted  exit $errstatusfi# Optional new user creation:if [ ! -z $SQL_INSTALL_USER ] && [ ! -z $SQL_INSTALL_USER_PASSWORD ]then  echo Creating user $SQL_INSTALL_USER  /opt/mssql-tools/bin/sqlcmd     -S localhost     -U SA     -P $MSSQL_SA_PASSWORD     -Q "CREATE LOGIN [$SQL_INSTALL_USER] WITH PASSWORD=N'$SQL_INSTALL_USER_PASSWORD', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=ON, CHECK_POLICY=ON; ALTER SERVER ROLE [sysadmin] ADD MEMBER [$SQL_INSTALL_USER]"fiecho Done!


運行該無人值守安裝指令碼:

1. 將以上指令碼儲存為install_sql.sh。

2. 指定MSSQL_SA_PASSWORD、MSSQL_PID,和你想修改的其他變數。

3. 將該指令碼修改為可執行。

chmod +x install_sql.sh

4. 運行指令碼。

./install_sql.sh


在Linux上無人值守安裝SQL Server 2017

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.