RedHat7.4上安裝SQL Server 2017
版權宣告:本文為Buddy Yuan原創文章,未經允許不得轉載。原文地址: ofollow,noindex" target="_blank">REDHAT7.4上安裝SQL SERVER 2017
今天測試了一下在RedHat7.4上安裝SQL Server 2017,整個安裝過程並不複雜。以下是安裝過程的詳細步驟。
1.檢查CPU和記憶體,CPU至少2個核心,記憶體2GB以上,磁碟空間大於6GB,如圖所示:

[root@10 ~]# grep -i --color "model name" /proc/cpuinfo model name : Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz model name : Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz [root@10 ~]# grep -i --color "MemTotal" /proc/meminfo MemTotal: 4046612 kB [root@10 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 42G 4.0G 38G 10% / devtmpfs 2.0G 0 2.0G 0% /dev tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 2.0G 9.5M 2.0G 1% /run tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/sda1 497M 153M 344M 31% /boot tmpfs 396M 4.0K 396M 1% /run/user/992 tmpfs 396M 48K 396M 1% /run/user/1000 tmpfs 396M 0 396M 0% /run/user/0
2.下載Microsoft SQL Server 2017 Red Hat儲存庫配置檔案:
[root@10 ~]# sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 232 100 232 0 0 778 0 --:--:-- --:--:-- --:--:-- 781
3.執行yum安裝sql server
[root@10 ~]# yum install -y mssql-server Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. packages-microsoft-com-mssql-server-2017 | 2.9 kB 00:00:00 packages-microsoft-com-mssql-server-2017/primary_db | 16 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package mssql-server.x86_64 0:14.0.3038.14-2 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================================================================================================ Package Arch Version Repository Size ================================================================================================================================================================================================================================================================ Installing: mssql-server x86_64 14.0.3038.14-2 packages-microsoft-com-mssql-server-2017 169 M Transaction Summary ================================================================================================================================================================================================================================================================ Install 1 Package Total download size: 169 M Installed size: 169 M Downloading packages: warning: /var/cache/yum/x86_64/7Server/packages-microsoft-com-mssql-server-2017/packages/mssql-server-14.0.3038.14-2.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY====================================== ] 5.7 MB/s | 168 MB 00:00:00 ETA Public key for mssql-server-14.0.3038.14-2.x86_64.rpm is not installed mssql-server-14.0.3038.14-2.x86_64.rpm | 169 MB 00:00:30 Retrieving key from https://packages.microsoft.com/keys/microsoft.asc Importing GPG key 0xBE1229CF: Userid : "Microsoft (Release signing) <[email protected]>" Fingerprint: bc52 8686 b50d 79e3 39d3 721c eb3e 94ad be12 29cf From : https://packages.microsoft.com/keys/microsoft.asc Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mssql-server-14.0.3038.14-2.x86_64 1/1 +--------------------------------------------------------------+ Please run 'sudo /opt/mssql/bin/mssql-conf setup' to complete the setup of Microsoft SQL Server +--------------------------------------------------------------+ SQL Server needs to be restarted in order to apply this setting. Please run 'systemctl restart mssql-server.service'. Verifying : mssql-server-14.0.3038.14-2.x86_64 1/1 Installed: mssql-server.x86_64 0:14.0.3038.14-2
4.執行SQL Server配置指令碼(/opt/mssql/bin/mssql-conf),這裡選擇安裝的版本,因為我們是測試,就選擇了Developer版。同時還需要設定SA的密碼,密碼規則是強密碼,需要最少8個字元,包括大寫和小寫字母、數字和/或非字母數字符號。
[root@10 bin]# pwd /opt/mssql/bin [root@10 bin]# ./mssql-conf setup 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) Enterprise Core (PAID) 8) 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-8): 2 The license terms for this product can be found in /usr/share/doc/mssql-server or downloaded from: https://go.microsoft.com/fwlink/?LinkId=855862&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 Enter the SQL Server system administrator password: The specified password contains an invalid character. Valid characters include uppercase letters, lowercase letters, numbers, symbols, punctuation marks, and unicode characters that are categorized as alphabetic but are not uppercase or lowercase. Enter the SQL Server system administrator password: Confirm the SQL Server system administrator password: Configuring SQL Server... ForceFlush is enabled for this instance. ForceFlush feature is enabled for log durability. Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /usr/lib/systemd/system/mssql-server.service. Setup has completed successfully. SQL Server is now starting.
5.檢視mssql服務的狀態,目前是running的。
systemctl status mssql-server [root@10 bin]# 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 Mon 2018-10-15 23:02:15 CST; 3min 27s ago Docs: https://docs.microsoft.com/en-us/sql/linux Main PID: 4375 (sqlservr) CGroup: /system.slice/mssql-server.service ├─4375 /opt/mssql/bin/sqlservr └─4414 /opt/mssql/bin/sqlservr Oct 15 23:02:18 10.0.2.15 sqlservr[4375]: 2018-10-15 23:02:18.81 spid11s Polybase feature disabled. Oct 15 23:02:18 10.0.2.15 sqlservr[4375]: 2018-10-15 23:02:18.82 spid11s Clearing tempdb database. Oct 15 23:02:18 10.0.2.15 sqlservr[4375]: 2018-10-15 23:02:18.84 spid6s 8 transactions rolled forward in database 'msdb' (4:0). This is an informational message only. No user action is required. Oct 15 23:02:18 10.0.2.15 sqlservr[4375]: 2018-10-15 23:02:18.90 spid6s 0 transactions rolled back in database 'msdb' (4:0). This is an informational message only. No user action is required. Oct 15 23:02:19 10.0.2.15 sqlservr[4375]: 2018-10-15 23:02:19.13 spid11s Starting up database 'tempdb'. Oct 15 23:02:19 10.0.2.15 sqlservr[4375]: 2018-10-15 23:02:19.34 spid11s The tempdb database has 1 data file(s). Oct 15 23:02:19 10.0.2.15 sqlservr[4375]: 2018-10-15 23:02:19.36 spid22s The Service Broker endpoint is in disabled or stopped state. Oct 15 23:02:19 10.0.2.15 sqlservr[4375]: 2018-10-15 23:02:19.36 spid22s The Database Mirroring endpoint is in disabled or stopped state. Oct 15 23:02:19 10.0.2.15 sqlservr[4375]: 2018-10-15 23:02:19.40 spid22s Service Broker manager has started. Oct 15 23:02:19 10.0.2.15 sqlservr[4375]: 2018-10-15 23:02:19.41 spid6s Recovery is complete. This is an informational message only. No user action is required.
6.預設SQL Server通過1433埠連線,此時要檢查防火牆狀態,如果是開啟的,需要把1433埠在防火牆上做放開設定,允許連線。或者直接關閉Linux防火牆。我在這裡直接關閉了防火牆。
[root@10 bin]# firewall-cmd --state running [root@10 bin]# systemctl stop firewalld.service [root@10 bin]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
7.接下來需要安裝sqlcmd和bcp等客戶端工具。和安裝伺服器一樣,首先也要下載配置檔案。
[root@10 bin]# sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 193 100 193 0 0 682 0 --:--:-- --:--:-- --:--:-- 681
接下來如果有舊版的mssql工具,需要刪除。
[root@10 bin]# yum remove unixODBC-utf16 unixODBC-utf16-devel Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. No Match for argument: unixODBC-utf16 No Match for argument: unixODBC-utf16-devel No Packages marked for removal
刪除完成之後安裝新的工具,在安裝過程中出現下列的問題:
[root@10 bin]# yum install -y mssql-tools unixODBC-devel Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. packages-microsoft-com-prod | 2.9 kB 00:00:00 packages-microsoft-com-prod/primary_db | 144 kB 00:00:00 No package unixODBC-devel available. Resolving Dependencies --> Running transaction check ---> Package mssql-tools.x86_64 0:17.2.0.2-1 will be installed --> Processing Dependency: msodbcsql17 < 17.3.0.0 for package: mssql-tools-17.2.0.2-1.x86_64 --> Processing Dependency: msodbcsql17 >= 17.2.0.0 for package: mssql-tools-17.2.0.2-1.x86_64 --> Running transaction check ---> Package msodbcsql17.x86_64 0:17.2.0.1-1 will be installed --> Processing Dependency: unixODBC >= 2.3.1 for package: msodbcsql17-17.2.0.1-1.x86_64 --> Processing Dependency: libodbcinst.so.2()(64bit) for package: msodbcsql17-17.2.0.1-1.x86_64 --> Running transaction check ---> Package msodbcsql17.x86_64 0:17.2.0.1-1 will be installed --> Processing Dependency: unixODBC >= 2.3.1 for package: msodbcsql17-17.2.0.1-1.x86_64 ---> Package unixODBC-utf16.x86_64 0:2.3.1-1 will be installed --> Processing Conflict: msodbcsql17-17.2.0.1-1.x86_64 conflicts unixODBC-utf16 --> Finished Dependency Resolution Error: msodbcsql17 conflicts with unixODBC-utf16-2.3.1-1.x86_64 Error: Package: msodbcsql17-17.2.0.1-1.x86_64 (packages-microsoft-com-prod) Requires: unixODBC >= 2.3.1 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
下列問題主要是因為軟體的yum倉庫不可用, 百度了辦法 修改成了163的centos的yum倉庫就可以了。
[root@10 run]# yum install -y mssql-tools unixODBC-devel Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package mssql-tools.x86_64 0:17.2.0.2-1 will be installed --> Processing Dependency: msodbcsql17 < 17.3.0.0 for package: mssql-tools-17.2.0.2-1.x86_64 --> Processing Dependency: msodbcsql17 >= 17.2.0.0 for package: mssql-tools-17.2.0.2-1.x86_64 ---> Package unixODBC-devel.x86_64 0:2.3.1-11.el7 will be installed --> Processing Dependency: unixODBC(x86-64) = 2.3.1-11.el7 for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libtemplate.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libtdsS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libsapdbS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: liboraodbcS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: liboplodbcS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbctxtS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbcnnS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbcminiS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbcdrvcfg2S.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbcdrvcfg1S.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libodbccr.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libnn.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libmimerS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Processing Dependency: libesoobS.so.2()(64bit) for package: unixODBC-devel-2.3.1-11.el7.x86_64 --> Running transaction check ---> Package msodbcsql17.x86_64 0:17.2.0.1-1 will be installed ---> Package unixODBC.x86_64 0:2.3.1-11.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================================================================================================ Package Arch Version Repository Size ================================================================================================================================================================================================================================================================ Installing: mssql-tools x86_64 17.2.0.2-1 packages-microsoft-com-prod 254 k unixODBC-devel x86_64 2.3.1-11.el7 base 55 k Installing for dependencies: msodbcsql17 x86_64 17.2.0.1-1 packages-microsoft-com-prod 4.3 M unixODBC x86_64 2.3.1-11.el7 base 413 k Transaction Summary ================================================================================================================================================================================================================================================================ Install 2 Packages (+2 Dependent packages) Total download size: 5.1 M Installed size: 6.0 M Downloading packages: warning: /var/cache/yum/x86_64/$releasever/base/packages/unixODBC-devel-2.3.1-11.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Public key for unixODBC-devel-2.3.1-11.el7.x86_64.rpm is not installed (1/4): unixODBC-devel-2.3.1-11.el7.x86_64.rpm | 55 kB 00:00:00 (2/4): unixODBC-2.3.1-11.el7.x86_64.rpm | 413 kB 00:00:00 (3/4): mssql-tools-17.2.0.2-1.x86_64.rpm | 254 kB 00:00:00 (4/4): msodbcsql17-17.2.0.1-1.x86_64.rpm | 4.3 MB 00:00:01 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 3.4 MB/s | 5.1 MB 00:00:01 Retrieving key from http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 From : http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. ** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows: rhn-check-2.0.2-17.el7.noarch has missing requires of yum-rhn-plugin >= ('0', '1.6.4', '1') Installing : unixODBC-2.3.1-11.el7.x86_64 1/4 The license terms for this product can be downloaded from https://aka.ms/odbc172eula and found in /usr/share/doc/msodbcsql17/LICENSE.txt . By entering 'YES', you indicate that you accept the license terms. Do you accept the license terms? (Enter YES or NO) YES Installing : msodbcsql17-17.2.0.1-1.x86_64 2/4 The license terms for this product can be downloaded from http://go.microsoft.com/fwlink/?LinkId=746949 and found in /usr/share/doc/mssql-tools/LICENSE.txt . By entering 'YES', you indicate that you accept the license terms. Do you accept the license terms? (Enter YES or NO) YES Installing : mssql-tools-17.2.0.2-1.x86_64 3/4 Installing : unixODBC-devel-2.3.1-11.el7.x86_64 4/4 Verifying : unixODBC-devel-2.3.1-11.el7.x86_64 1/4 Verifying : unixODBC-2.3.1-11.el7.x86_64 2/4 Verifying : msodbcsql17-17.2.0.1-1.x86_64 3/4 Verifying : mssql-tools-17.2.0.2-1.x86_64 4/4 Installed: mssql-tools.x86_64 0:17.2.0.2-1 unixODBC-devel.x86_64 0:2.3.1-11.el7 Dependency Installed: msodbcsql17.x86_64 0:17.2.0.1-1 unixODBC.x86_64 0:2.3.1-11.el7
8.接下來做一些測試連線,先檢視用的是否是1434埠
[root@10 run]# netstat -tulpn | grep sqlservr tcp 0 0 0.0.0.0:1433 0.0.0.0:* LISTEN 4414/sqlservr tcp 0 0 127.0.0.1:1434 0.0.0.0:* LISTEN 4414/sqlservr tcp6 0 0 :::1433 :::* LISTEN 4414/sqlservr tcp6 0 0 ::1:1434 :::* LISTEN 4414/sqlservr [root@10 run]# sqlcmd -S 127.0.0.1 -U SA -P 'Passwd!123*' bash: sqlcmd: command not found...
這裡沒配置好環境變數。先設定一下。
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc
再一次連線,如果成功,就會顯示sqlcmd命令提示符:1>
[root@10 run]# sqlcmd -S 127.0.0.1 -U SA Password: 1> SELECT Name from sys.Databases 2> GO Name -------------------------------------------------------------------------------------------------------------------------------- master tempdb model msdb TestDB (5 rows affected) 1> USE TestDB 2> CREATE TABLE test (id INT, name VARCHAR(50)) 3> INSERT INTO test VALUES (1, 'test install'); 4> GO Changed database context to 'TestDB'. (1 rows affected) 1> select * from test 2> GO id name ----------- -------------------------------------------------- 1 test install (1 rows affected)
至此整個安裝過程結束,參考微軟官方文件: https://docs.microsoft.com/zh-cn/sql/linux/quickstart-install-connect-red-hat?view=sql-server-2017