CentOS7下安装SQL Server 2017(详细版)

由于学习的需要,笔者需要在自己的虚拟机上搭建一个sql server数据库,最终在windows电脑进行连接,方便进行学习和练习,以下内容详细的介绍了安装过程,跟着一步步的做下去,保证可以安装成功,下边将笔者安装的步骤进行详细的介绍!(安装资源包笔者上传至资源中,可以根据需要自行下载

(一)安装环境:

  1. VMware15
  2. CentOS系统
  3. SQL Server的rpm安装包
  4. 安装包下载地址:https://packages.microsoft.com/

(二)安装步骤:

2. 安装mssql-server

2.1 下载rpm包

2.1 yum安装

[root@localhost ms_sql]# yum localinstall mssql-server-14.0.900.75-1.x86_64.rpm

Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Examining mssql-server-14.0.900.75-1.x86_64.rpm: mssql-server-14.0.900.75-1.x86_64
Marking mssql-server-14.0.900.75-1.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mssql-server.x86_64 0:14.0.900.75-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================
 Package                             Arch                          Version                                 Repository                                                 Size
===========================================================================================================================================================================
Installing:
 mssql-server                        x86_64                        14.0.900.75-1                           /mssql-server-14.0.900.75-1.x86_64                        870 M

Transaction Summary
===========================================================================================================================================================================
Install  1 Package

Total size: 870 M
Installed size: 870 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mssql-server-14.0.900.75-1.x86_64                                                                                                                       1/1

+--------------------------------------------------------------+
Please run 'sudo /opt/mssql/bin/mssql-conf setup'
to complete the setup of Microsoft SQL Server
+--------------------------------------------------------------+

  Verifying  : mssql-server-14.0.900.75-1.x86_64                                                                                                                       1/1

Installed:
  mssql-server.x86_64 0:14.0.900.75-1                                                                                                                                      

Complete!

2.2 配置

[root@localhost ms_sql]# /opt/mssql/bin/mssql-conf setup

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 [40] days left in the evaluation period.
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.

 

注意评估版本有使用期限。

2.3 验证服务

[root@localhost ms_sql]# 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 Thu 2017-12-14 18:25:03 CST; 1min 23s ago
     Docs: https://docs.microsoft.com/en-us/sql/linux
 Main PID: 56504 (sqlservr)
   CGroup: /system.slice/mssql-server.service
           ├─56504 /opt/mssql/bin/sqlservr
           └─56525 /opt/mssql/bin/sqlservr

Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.36 Server      Server is listening on [ ::1 <ipv6> 1434].
Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.37 Server      Server is listening on [ 127.0.0.1 <ipv4> 1434].
Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.37 Server      Dedicated admin connection support was established for listening locally on port 1434.
Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.38 spid19s     SQL Server is now ready for client connections. This is an informational message; ... required.
Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.42 spid9s      Starting up database 'tempdb'.
Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.61 spid9s      The tempdb database has 1 data file(s).
Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.61 spid20s     The Service Broker endpoint is in disabled or stopped state.
Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.62 spid20s     The Database Mirroring endpoint is in disabled or stopped state.
Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.62 spid20s     Service Broker manager has started.
Dec 14 18:25:10 134test sqlservr[56504]: 2017-12-14 18:25:10.63 spid6s      Recovery is complete. This is an informational message only. No user action is required.
Hint: Some lines were ellipsized, use -l to show in full.


2.4 停止、启动或重启 SQL Server 服务

systemctl stop mssql-server
systemctl start mssql-server
systemctl restart mssql-server


2.5 查看日志文件

[root@localhost ms_sql]# cd /var/opt/mssql/log/errorlog
[root@localhost ms_sql]# ls
[root@localhost ms_sql]# cat XXX.log

 

3. 安装 sqlcmd 和 bcp SQL Server 命令行工具

3.1 下载

[root@localhost ms_sql]# wget https://packages.microsoft.com/rhel/7.3/prod/msodbcsql-13.1.6.0-1.x86_64.rpm
[root@localhost ms_sql]# wget https://packages.microsoft.com/rhel/7.3/prod/mssql-tools-14.0.5.0-1.x86_64.rpm

3.2 安装

[root@localhost ms_sql]# yum localinstall msodbcsql-13.1.6.0-1.x86_64.rpm
[root@localhost ms_sql]# yum localinstall mssql-tools-14.0.5.0-1.x86_64.rpm

 

3.3 添加到环境变量

[root@localhost ms_sql]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
[root@localhost ms_sql]# source ~/.bash_profile
[root@localhost ms_sql]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
[root@localhost ms_sql]# source ~/.bashrc

 

3.4 本地连接

[root@localhost ms_sql]# sqlcmd -S localhost -U sa
Password:
1> select name from sys.databases;
2> go
name                                                                                                                            
--------------------------------------------------------------------------------------------------------------------------------
master                                                                                                                          
tempdb                                                                                                                          
model                                                                                                                           
msdb                                                                                                                                                                                                                                           

(5 rows affected)
1>
1>create database TestDB;
2>go
1>

1> use TestDB;
2> go
Changed database context to 'TestDB'.
1> create table t1 (id int, cname nvarchar(50))
2> go
1>
1> insert into t1 (id, cname) values (1,'abc');
2> go

(1 rows affected)
1> select * from t1;
2> go
id          cname                                             
----------- --------------------------------------------------
          1 abc                                               

(1 rows affected)
1>

3.5 退出

1> quit

 

4. 安装SQL Server Agent

4.1 下载

[root@localhost ms_sql]# wget https://packages.microsoft.com/rhel/7/mssql-server/mssql-server-agent-14.0.900.75-1.x86_64.rpm

 

4.2 安装

[root@localhost ms_sql]# yum localinstall mssql-server-agent-14.0.900.75-1.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Examining mssql-server-agent-14.0.900.75-1.x86_64.rpm: mssql-server-agent-14.0.900.75-1.x86_64
Marking mssql-server-agent-14.0.900.75-1.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mssql-server-agent.x86_64 0:14.0.900.75-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================
 Package                                Arch                       Version                              Repository                                                    Size
===========================================================================================================================================================================
Installing:
 mssql-server-agent                     x86_64                     14.0.900.75-1                        /mssql-server-agent-14.0.900.75-1.x86_64                     8.9 M

Transaction Summary
===========================================================================================================================================================================
Install  1 Package

Total size: 8.9 M
Installed size: 8.9 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mssql-server-agent-14.0.900.75-1.x86_64                                                                                                                 1/1

+--------------------------------------------------------------------------------+
Please restart mssql-server to enable Microsoft SQL Server Agent.
+--------------------------------------------------------------------------------+

  Verifying  : mssql-server-agent-14.0.900.75-1.x86_64                                                                                                                 1/1

Installed:
  mssql-server-agent.x86_64 0:14.0.900.75-1                                                                                                                                

Complete!

 

  • 开启防火墙上的 SQL Server 端口,默认为TCP 1433
sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
sudo firewall-cmd --reload
# firewall-cmd未启用不需要做此设置

到此,SQL Server已在CentOS7上正常运行

 

5. 在Windows上使用SSMS连接数据库

 

 

(三)注意事项:

  • SQL Server 2017需要至少3.2GB的内存才能启动服务,网上有修改内存限制的方法,但是笔者只是简单粗暴的将虚拟机内存调整到了4GB,笔记电脑的内存为16GB,如果内存小的同学可以去网上寻找其他的修改配置的资料,但是步骤比较繁琐,还不如直接给大一点的内存即可!!
  • 在centOS上边安装完成后,如果没有开放端口和关闭防火墙,用本地的工具进行连接时,会报如下的错误

如果大家有疑问或者不明白的地方,欢迎在下方进行留言,笔者看到一定会及时进行回复!!

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zhang_Fei_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值