RedHat7.4上安装SQL Server 2017

版权声明:本文为Buddy Yuan原创文章,未经允许不得转载。原文地址: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) <gpgsecurity@microsoft.com>"
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) <security@centos.org>"
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

关注dbDao.com的新浪微博

扫码加入微信Oracle小密圈,了解Oracle最新技术下载分享资源