在 Linux 上安裝 SQL Server 2017
概述
通過將平臺抽象層 (PAL) 引入 SQL Server,Linux 上的 SQL Server 成為可能。PAL 將所有操作系統(tǒng)特定代碼集中在一處,并允許其余代碼保持獨立于操作系統(tǒng)。PAL 是 Microsoft 研究項目 Drawbridge 的成果。目前,Red Hat Enterprise Server、SUSE Linux Enterprise Server 和 Ubuntu 支持 SQL Server。它還支持在 Docker 容器中運行。
SQL Server for Linux版本,可以在某些Linux發(fā)行版上直接安裝和運行。但是有一些具體系統(tǒng)要求,首先,確保你的Linux發(fā)行版滿足SQL Server的要求。例如,SQL Server 2017要求操作系統(tǒng)為Red Hat Enterprise Linux(RHEL)7.3或Ubuntu 16.04 LTS,而SQL Server 2019要求操作系統(tǒng)為RHEL 8.0、SUSE Linux Enterprise Server(SLES)15或Ubuntu 18.04 LTS。
本文將闡述在 Linux 上安裝 SQL Server 2017的具體過程。
為什么應(yīng)該在 Linux 上運行 SQL Server?
企業(yè)需求:Linux 上的 SQL Server 為企業(yè)關(guān)鍵功能(例如使用針對 Linux 操作系統(tǒng)的開源集群機制的 AlwaysOn 可用性組的高可用性和災(zāi)難恢復(fù))提供了一個可靠的平臺。AlwaysOn 配置還可以將節(jié)點與 Linux 和 Windows 操作系統(tǒng)混合。AlwaysOn 可用性組可以幫助您的應(yīng)用程序滿足強大的業(yè)務(wù)連續(xù)性要求。
降低運營成本:組織在 Linux 上使用 SQL Server 時可以實現(xiàn)運營成本的降低。SQL Server 許可證允許它根據(jù)架構(gòu)的需要在 Windows、Linux 或 Docker 上使用??缙脚_的許可模型,允許在多操作系統(tǒng)環(huán)境中提供 SQL Server 功能。SQL Server 在 Windows 和 Linux 上的許可方式相同,例如,運行在windows上的現(xiàn)有許可證可以轉(zhuǎn)移到 Linux,無需額外費用。
性能:與運行在 Windows 操作系統(tǒng)相比,Linux 上的 SQL Server 性能應(yīng)該相當(dāng)或更好。
簡單性:Linux 上的 SQL Server 允許 SQL Server DBA 和開發(fā)人員使用現(xiàn)有工具和腳本執(zhí)行日常任務(wù),而無需關(guān)注其中的差異。在 Windows 上運行的所有核心數(shù)據(jù)庫功能在 Linux 中也可用。但是,某些依賴于 Windows 功能的 SQL Server 功能將不可用??梢栽诖颂幷业讲皇苤С值墓δ艿牧斜?。
安裝和維護:在Linux上命令行安裝SQL Server、補丁比Windows上相對要快。這使得企業(yè)能夠節(jié)省代價高昂的停機時間。較舊版本的 SQL Server(例如 SQL Server 2008 或 2008 R2)可以輕松升級到 Linux 上較新版本的 SQL Server。
非生產(chǎn)環(huán)境一鍵完成:利用 docker 容器來配置非生產(chǎn)數(shù)據(jù)庫環(huán)境,使開發(fā)人員和 DBA 能夠立即執(zhí)行測試。
安裝過程
步驟 1:下載 Microsoft SQL Server Red Hat 存儲庫配置文件:
- 以 root 用戶身份運行以下命令:
curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo
第 2 步:安裝 SQL Server:
yum -y install mssql-server
步驟 3:設(shè)置 SQL Server :
/opt/mssql/bin/mssql-conf setup
- 安裝程序?qū)⑻崾据斎氚姹绢愋秃?sa 密碼,請在命令提示符上提供相關(guān)的信息。
The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=852741&clcid=0x409
The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409
Do you accept the license terms? [Yes/No]:Yes
Choose an edition of SQL Server:
1) Evaluation (free, no production use rights, 180-day limit)
2) Developer (free, no production use rights)
3) Express (free)
4) Web (PAID)
5) Standard (PAID)
6) Enterprise (PAID)
7) I bought a license through a retail sales channel and have a product key to enter.
Details about editions can be found at
https://go.microsoft.com/fwlink/?LinkId=852748&clcid=0x409
Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.
Enter your edition(1-7): 2
Enter the SQL Server system administrator password:
Confirm the SQL Server system administrator password:
Configuring SQL Server...
This is an evaluation version. There are [132] days left in the evaluation period.
Setup has completed successfully. SQL Server is now starting.
這樣就完成了 Linux 上的 SQL Server 安裝,您可以通過以下命令檢查 SQL Server 服務(wù)和進程:
- 檢查服務(wù)
systemctl status mssql-server
輸出:
● mssql-server.service - Microsoft SQL Server Database Engine
Loaded: loaded (/usr/lib/systemd/system/mssql-server.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2017-09-13 13:40:54 BST; 6min ago
Docs: https://docs.microsoft.com/en-us/sql/linux
Main PID: 6017 (sqlservr)
CGroup: /system.slice/mssql-server.service
├─6017 /opt/mssql/bin/sqlservr
└─6048 /opt/mssql/bin/sqlservr
Sep 13 13:41:08 dbalab1 sqlservr[6017]: 2017-09-13 13:41:08.95 spid6s 8 transactions rolled forward in database 'msdb' (4:0). This is an informat... required.
Sep 13 13:41:09 dbalab1 sqlservr[6017]: 2017-09-13 13:41:09.06 spid9s Polybase feature disabled.
Sep 13 13:41:09 dbalab1 sqlservr[6017]: 2017-09-13 13:41:09.06 spid9s Clearing tempdb database.
Sep 13 13:41:09 dbalab1 sqlservr[6017]: 2017-09-13 13:41:09.10 spid6s 0 transactions rolled back in database 'msdb' (4:0). This is an information... required.
Sep 13 13:41:09 dbalab1 sqlservr[6017]: 2017-09-13 13:41:09.73 spid9s Starting up database 'tempdb'.
Sep 13 13:41:10 dbalab1 sqlservr[6017]: 2017-09-13 13:41:10.19 spid9s The tempdb database has 1 data file(s).
Sep 13 13:41:10 dbalab1 sqlservr[6017]: 2017-09-13 13:41:10.20 spid22s The Service Broker endpoint is in disabled or stopped state.
Sep 13 13:41:10 dbalab1 sqlservr[6017]: 2017-09-13 13:41:10.21 spid22s The Database Mirroring endpoint is in disabled or stopped state.
Sep 13 13:41:10 dbalab1 sqlservr[6017]: 2017-09-13 13:41:10.32 spid22s Service Broker manager has started.
Sep 13 13:41:10 dbalab1 sqlservr[6017]: 2017-09-13 13:41:10.46 spid6s Recovery is complete. This is an informational message only. No user action is required.
- 檢查進程
ps -ef | grep sqlservr | grep -v grep
mssql 6017 1 0 13:40 ? 00:00:01 /opt/mssql/bin/sqlservr
mssql 6048 6017 8 13:40 ? 00:00:31 /opt/mssql/bin/sqlservr
- 檢查端口
netstat -tulpn | grep 1433
tcp 0 0 0.0.0.0:1433 0.0.0.0:* LISTEN 6048/sqlservr
tcp6 0 0 :::1433 :::* LISTEN 6048/sqlservr
步驟 4:連接到 SQL Server 實例:
要進行連接,您首先需要安裝 mssql-tools(sqlcmd 和 bcp),可以通過執(zhí)行以下命令來安裝:
下載:
curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
安裝:
yum install -y mssql-tools unixODBC-devel
Mssq-tools 現(xiàn)已安裝,但要使用它們,請將 mssql-tools 二進制文件添加到您的路徑中:
export PATH="$PATH:/opt/mssql-tools/bin"
如果永久生效,請把mssql-tools 二進制文件加入用戶的bash_profile文件或/etc/profile:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
完成此操作后,您可以通過執(zhí)行以下命令連接到 SQL Server 實例:-
sqlcmd -S localhost -U SA -P ''
第 5 步:現(xiàn)在要允許遠程連接(通過您最喜歡的 SSMS 連接),您需要禁用防火墻,這可以通過以下方式實現(xiàn):
禁用防火墻:
systemctl disable firewalld
或者允許端口 1433:
firewall-cmd --zone=public --add-port=1433/tcp --permanent``firewall-cmd --reload
第6步:安裝SQL Server代理。
yum install mssql-server-agent
systemctl restart mssql-server