加入收藏 | 设为首页 | 会员中心 | 我要投稿 汽车网 (https://www.0577qiche.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQL Server 静默安装配置

发布时间:2023-05-09 13:18:07 所属栏目:MsSql教程 来源:
导读:#!/bin/bash
# Use the following variables to control your install:
# Password for the SA user (required)
MSsql_SA_PASSWORD='Huawei12#$'
# Must be evaluation, developer, express, web, stand
#!/bin/bash
# Use the following variables to control your install:
# Password for the SA user (required)
MSsql_SA_PASSWORD='Huawei12#$'
# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key
# Defaults to developer
MSsql_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='aguser'
sql_INSTALL_USER_PASSWORD='Huawei12#$'
if [ -z $MSsql_SA_PASSWORD ]
then
  echo Environment variable MSsql_SA_PASSWORD must be set for unattended install
  exit 1
fi
echo Adding Microsoft repositories...
sudo curl -o /etc/yum.repos.d/mssql-server.repo  >/dev/null \
  && curl -o /etc/yum.repos.d/msprod.repo  >/dev/null
echo Installing sql Server and sqlCMD ...
sudo ACCEPT_EULA=Y yum install -y mssql-server mssql-tools unixODBC-devel
echo Running mssql-conf setup...
sudo MSsql_SA_PASSWORD=$MSsql_SA_PASSWORD \
     MSsql_PID=$MSsql_PID \
     /opt/mssql/bin/mssql-conf -n setup accept-eula
# 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_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# Optional sql Server Agent installation:
if [ ! -z $sql_INSTALL_AGENT ]
then
  echo Installing sql Server Agent...
  sudo yum install -y mssql-server-agent
fi
# 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-fts
fi
# 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 --permanent && firewall-cmd --reload && setenforce 0
# 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=1
errstatus=1
while [ $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 $errstatus
fi
# 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]"
fi
echo Done!

(编辑:汽车网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章