接了点装库的私活

640?wx_fmt=jpeg

业务需求,要求在 Linux 下安装 sqlserver 数据库。几年前用的时候一直都是在 win 上跑的。其实这次我也是头次安装,但是基本上问题不大。下面我把安装实验笔记做一下总结,后续有需要的朋友可以直接按照这样安即可。

配置源:

[root@k8s-node-01 ~]# 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    196      0  0:00:01  0:00:01 --:--:--   196

直接上手安装:

[root@k8s-node-01 ~]# yum install -y mssql-server
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-server.x86_64 0:14.0.3223.3-15 will be installed
--> Processing Dependency: libsss_nss_idmap for package: mssql-server-14.0.3223.3-15.x86_64
--> Processing Dependency: cyrus-sasl-gssapi for package: mssql-server-14.0.3223.3-15.x86_64
--> Processing Dependency: gdb for package: mssql-server-14.0.3223.3-15.x86_64
--> Processing Dependency: bzip2 for package: mssql-server-14.0.3223.3-15.x86_64
--> Running transaction check
---> Package bzip2.x86_64 0:1.0.6-13.el7 will be installed
---> Package cyrus-sasl-gssapi.x86_64 0:2.1.26-23.el7 will be installed
---> Package gdb.x86_64 0:7.6.1-114.el7 will be installed
---> Package libsss_nss_idmap.x86_64 0:1.16.2-13.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================================
 Package                               Arch                       Version                             Repository                                                    Size
=========================================================================================================================================================================
Installing:
 mssql-server                          x86_64                     14.0.3223.3-15                      packages-microsoft-com-mssql-server-2017                     178 M
Installing for dependencies:
 bzip2                                 x86_64                     1.0.6-13.el7                        mirrors.163.com                                               52 k
 cyrus-sasl-gssapi                     x86_64                     2.1.26-23.el7                       mirrors.163.com                                               41 k
 gdb                                   x86_64                     7.6.1-114.el7                       mirrors.163.com                                              2.4 M
 libsss_nss_idmap                      x86_64                     1.16.2-13.el7                       mirrors.163.com                                              154 k

Transaction Summary
=========================================================================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 181 M
Installed size: 186 M
Downloading packages:
(1/5): bzip2-1.0.6-13.el7.x86_64.rpm                                                                                                              |  52 kB  00:00:00
cyrus-sasl-gssapi-2.1.26-23.el FAILED
http://mirrors.163.com/centos/7/os/x86_64/Packages/cyrus-sasl-gssapi-2.1.26-23.el7.x86_64.rpm: [Errno 12] Timeout on http://mirrors.163.com/centos/7/os/x86_64/Packages/cyrus-sasl-gssapi-2.1.26-23.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
gdb-7.6.1-114.el7.x86_64.rpm   FAILED
http://mirrors.163.com/centos/7/os/x86_64/Packages/gdb-7.6.1-114.el7.x86_64.rpm: [Errno 12] Timeout on http://mirrors.163.com/centos/7/os/x86_64/Packages/gdb-7.6.1-114.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
libsss_nss_idmap-1.16.2-13.el7 FAILED                                                                                                  ]  90 kB/s | 3.1 MB  00:33:41 ETA
http://mirrors.163.com/centos/7/os/x86_64/Packages/libsss_nss_idmap-1.16.2-13.el7.x86_64.rpm: [Errno 12] Timeout on http://mirrors.163.com/centos/7/os/x86_64/Packages/libsss_nss_idmap-1.16.2-13.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(2/5): cyrus-sasl-gssapi-2.1.26-23.el7.x86_64.rpm                                                                                                 |  41 kB  00:00:10
(3/5): gdb-7.6.1-114.el7.x86_64.rpm                                                                                                               | 2.4 MB  00:00:02
(4/5): libsss_nss_idmap-1.16.2-13.el7.x86_64.rpm                                                                                                  | 154 kB  00:00:00
warning: /var/cache/yum/x86_64/$releasever/packages-microsoft-com-mssql-server-2017/packages/mssql-server-14.0.3223.3-15.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY
Public key for mssql-server-14.0.3223.3-15.x86_64.rpm is not installed
(5/5): mssql-server-14.0.3223.3-15.x86_64.rpm                                                                                                     | 178 MB  00:34:19
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                     89 kB/s | 181 MB  00:34:49
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 : cyrus-sasl-gssapi-2.1.26-23.el7.x86_64                                                                                                                1/5
  Installing : bzip2-1.0.6-13.el7.x86_64                                                                                                                             2/5
  Installing : gdb-7.6.1-114.el7.x86_64                                                                                                                              3/5
  Installing : libsss_nss_idmap-1.16.2-13.el7.x86_64                                                                                                                 4/5
  Installing : mssql-server-14.0.3223.3-15.x86_64                                                                                                                    5/5

+--------------------------------------------------------------+
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  : libsss_nss_idmap-1.16.2-13.el7.x86_64                                                                                                                 1/5
  Verifying  : gdb-7.6.1-114.el7.x86_64                                                                                                                              2/5
  Verifying  : mssql-server-14.0.3223.3-15.x86_64                                                                                                                    3/5
  Verifying  : bzip2-1.0.6-13.el7.x86_64                                                                                                                             4/5
  Verifying  : cyrus-sasl-gssapi-2.1.26-23.el7.x86_64                                                                                                                5/5

Installed:
  mssql-server.x86_64 0:14.0.3223.3-15

Dependency Installed:
  bzip2.x86_64 0:1.0.6-13.el7         cyrus-sasl-gssapi.x86_64 0:2.1.26-23.el7         gdb.x86_64 0:7.6.1-114.el7         libsss_nss_idmap.x86_64 0:1.16.2-13.el7

Complete!

yum 安装后其实路径是比较凌乱的,不好找,可以直接用 rpm 或者 yum list installed 去查找。以下命令可以直观的看到是在 opt 下。

[root@k8s-node-01 ~]# rpm -qa |grep mssql
mssql-server-14.0.3223.3-15.x86_64
[root@k8s-node-01 ~]# rpm -ql mssql-server-14.0.3223.3-15.x86_64
/opt/mssql/bin
/opt/mssql/bin/compress-dump.sh
/opt/mssql/bin/crash-support-functions.sh
/opt/mssql/bin/generate-sql-dump.sh
/opt/mssql/bin/handle-crash.sh
/opt/mssql/bin/mssql-conf
/opt/mssql/bin/paldumper
/opt/mssql/bin/sqlservr
/opt/mssql/lib
/opt/mssql/lib/libc++.so.1
/opt/mssql/lib/libc++abi.so.1
/opt/mssql/lib/libprotobuf.so
/opt/mssql/lib/libprotobuf.so.15
/opt/mssql/lib/libprotobuf.so.15.0.1
/opt/mssql/lib/libsqlvdi.so
/opt/mssql/lib/libunwind.so.8
/opt/mssql/lib/loc
/opt/mssql/lib/loc/de_DE
/opt/mssql/lib/loc/de_DE/LC_MESSAGES
/opt/mssql/lib/loc/de_DE/LC_MESSAGES/sqlservr.mo
/opt/mssql/lib/loc/en_US
/opt/mssql/lib/loc/en_US/LC_MESSAGES
/opt/mssql/lib/loc/en_US/LC_MESSAGES/sqlservr.mo
/opt/mssql/lib/loc/es_ES
/opt/mssql/lib/loc/es_ES/LC_MESSAGES
/opt/mssql/lib/loc/es_ES/LC_MESSAGES/sqlservr.mo
/opt/mssql/lib/loc/fr_FR
/opt/mssql/lib/loc/fr_FR/LC_MESSAGES
/opt/mssql/lib/loc/fr_FR/LC_MESSAGES/sqlservr.mo
/opt/mssql/lib/loc/it_IT
/opt/mssql/lib/loc/it_IT/LC_MESSAGES
/opt/mssql/lib/loc/it_IT/LC_MESSAGES/sqlservr.mo
/opt/mssql/lib/loc/ja_JP
/opt/mssql/lib/loc/ja_JP/LC_MESSAGES
/opt/mssql/lib/loc/ja_JP/LC_MESSAGES/sqlservr.mo
/opt/mssql/lib/loc/ko_KR
/opt/mssql/lib/loc/ko_KR/LC_MESSAGES
/opt/mssql/lib/loc/ko_KR/LC_MESSAGES/sqlservr.mo
/opt/mssql/lib/loc/pt_BR
/opt/mssql/lib/loc/pt_BR/LC_MESSAGES
/opt/mssql/lib/loc/pt_BR/LC_MESSAGES/sqlservr.mo
/opt/mssql/lib/loc/ru_RU
/opt/mssql/lib/loc/ru_RU/LC_MESSAGES
/opt/mssql/lib/loc/ru_RU/LC_MESSAGES/sqlservr.mo
/opt/mssql/lib/loc/zh_CN
/opt/mssql/lib/loc/zh_CN/LC_MESSAGES
/opt/mssql/lib/loc/zh_CN/LC_MESSAGES/sqlservr.mo
/opt/mssql/lib/loc/zh_TW
/opt/mssql/lib/loc/zh_TW/LC_MESSAGES
/opt/mssql/lib/loc/zh_TW/LC_MESSAGES/sqlservr.mo
/opt/mssql/lib/mssql-conf
/opt/mssql/lib/mssql-conf/checkinstall.sh
/opt/mssql/lib/mssql-conf/checkrunninginstance.sh
/opt/mssql/lib/mssql-conf/collations.txt
/opt/mssql/lib/mssql-conf/invokesqlservr.sh
/opt/mssql/lib/mssql-conf/loc
/opt/mssql/lib/mssql-conf/loc/mo
/opt/mssql/lib/mssql-conf/loc/mo/mssql-conf-de_DE.mo
/opt/mssql/lib/mssql-conf/loc/mo/mssql-conf-en_US.mo
/opt/mssql/lib/mssql-conf/loc/mo/mssql-conf-es_ES.mo
/opt/mssql/lib/mssql-conf/loc/mo/mssql-conf-fr_FR.mo
/opt/mssql/lib/mssql-conf/loc/mo/mssql-conf-it_IT.mo
/opt/mssql/lib/mssql-conf/loc/mo/mssql-conf-ja_JP.mo
/opt/mssql/lib/mssql-conf/loc/mo/mssql-conf-ko_KR.mo
/opt/mssql/lib/mssql-conf/loc/mo/mssql-conf-pt_BR.mo
/opt/mssql/lib/mssql-conf/loc/mo/mssql-conf-ru_RU.mo
/opt/mssql/lib/mssql-conf/loc/mo/mssql-conf-zh_CN.mo
/opt/mssql/lib/mssql-conf/loc/mo/mssql-conf-zh_TW.mo
/opt/mssql/lib/mssql-conf/mssql-conf.py
/opt/mssql/lib/mssql-conf/mssqlconfhelper.py
/opt/mssql/lib/mssql-conf/mssqlsettings.py
/opt/mssql/lib/mssql-conf/mssqlsettingsmanager.py
/opt/mssql/lib/mssql-conf/set-collation.sh
/opt/mssql/lib/secforwarderxplat.sfp
/opt/mssql/lib/sqlagent.sfp
/opt/mssql/lib/sqlservr.sfp
/opt/mssql/lib/system.certificates.sfp
/opt/mssql/lib/system.common.sfp
/opt/mssql/lib/system.netfx.sfp
/opt/mssql/lib/system.security.sfp
/opt/mssql/lib/system.sfp
/usr/lib/systemd/system/mssql-server.service
/usr/share/doc/mssql-server/THIRDPARTYNOTICES.TXT
/usr/share/doc/mssql-server/license_Eval_Linux.txt
/usr/share/doc/mssql-server/license_Eval_Linux_Chinese (Simplified).txt
/usr/share/doc/mssql-server/license_Eval_Linux_Chinese (Traditional).txt
/usr/share/doc/mssql-server/license_Eval_Linux_French.txt
/usr/share/doc/mssql-server/license_Eval_Linux_German.txt
/usr/share/doc/mssql-server/license_Eval_Linux_Italian.txt
/usr/share/doc/mssql-server/license_Eval_Linux_Japanese.txt
/usr/share/doc/mssql-server/license_Eval_Linux_Korean.txt
/usr/share/doc/mssql-server/license_Eval_Linux_Portuguese (Brazil).txt
/usr/share/doc/mssql-server/license_Eval_Linux_Russian.txt
/usr/share/doc/mssql-server/license_Eval_Linux_Spanish.txt
/usr/share/doc/mssql-server/license_Std_Linux.txt
/usr/share/doc/mssql-server/license_Std_Linux_Chinese (Simplified).txt
/usr/share/doc/mssql-server/license_Std_Linux_Chinese (Traditional).txt
/usr/share/doc/mssql-server/license_Std_Linux_French.txt
/usr/share/doc/mssql-server/license_Std_Linux_German.txt
/usr/share/doc/mssql-server/license_Std_Linux_Italian.txt
/usr/share/doc/mssql-server/license_Std_Linux_Japanese.txt
/usr/share/doc/mssql-server/license_Std_Linux_Korean.txt
/usr/share/doc/mssql-server/license_Std_Linux_Portuguese (Brazil).txt
/usr/share/doc/mssql-server/license_Std_Linux_Russian.txt
/usr/share/doc/mssql-server/license_Std_Linux_Spanish.txt
/usr/share/man/man1/mssql-conf.1.gz
/usr/share/man/man1/sqlservr.1.gz
[root@k8s-node-01 ~]# cd /opt/mssql/
[root@k8s-node-01 mssql]# ll
total 4
drwxrwxr-x 2 root root  166 Sep  4 17:30 bin
drwxrwxr-x 4 root root 4096 Sep  4 17:31 lib
[root@k8s-node-01 mssql]# cd bin/
[root@k8s-node-01 bin]# ll
total 4916
-rwxr-xr-x 1 root root     434 Aug  1 13:15 compress-dump.sh
-rwxr-xr-x 1 root root   19886 Aug  1 13:15 crash-support-functions.sh
-rwxr-xr-x 1 root root    1615 Aug  1 13:15 generate-sql-dump.sh
-rwxr-xr-x 1 root root    2520 Aug  1 13:15 handle-crash.sh
-rwxrwxr-x 1 root root    1294 Aug  1 13:14 mssql-conf
-rwxr-xr-x 1 root root 2562592 Aug  1 13:15 paldumper
-rwxr-xr-x 1 root root 2429048 Aug  1 13:15 sqlservr

接下来进行安装并加入开机自启项。

[root@k8s-node-01 bin]# sudo /opt/mssql/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 does not meet SQL Server password policy requirements because it is not complex enough. The password must be at least 8 characters long and contain characters from three of the following four sets: uppercase letters, lowercase letters, numbers, and symbols.
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.

加入启动项:

[root@k8s-node-01 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 Wed 2019-09-04 17:37:22 CST; 36s ago
     Docs: https://docs.microsoft.com/en-us/sql/linux
 Main PID: 15012 (sqlservr)
   CGroup: /system.slice/mssql-server.service
           ├─15012 /opt/mssql/bin/sqlservr
           └─15033 /opt/mssql/bin/sqlservr

Sep 04 17:37:27 k8s-node-01 sqlservr[15012]: 2019-09-04 17:37:27.76 spid9s      Polybase feature disabled.
Sep 04 17:37:27 k8s-node-01 sqlservr[15012]: 2019-09-04 17:37:27.76 spid9s      Clearing tempdb database.
Sep 04 17:37:27 k8s-node-01 sqlservr[15012]: 2019-09-04 17:37:27.85 Server      Failed to verify the Authenticode signature of 'C:\binn\secforwarder.dll'. Signature v...
Sep 04 17:37:28 k8s-node-01 sqlservr[15012]: 2019-09-04 17:37:28.12 spid9s      Starting up database 'tempdb'.
Sep 04 17:37:28 k8s-node-01 sqlservr[15012]: 2019-09-04 17:37:28.32 spid9s      The tempdb database has 1 data file(s).
Sep 04 17:37:28 k8s-node-01 sqlservr[15012]: 2019-09-04 17:37:28.33 spid24s     The Service Broker endpoint is in disabled or stopped state.
Sep 04 17:37:28 k8s-node-01 sqlservr[15012]: 2019-09-04 17:37:28.33 spid24s     The Database Mirroring endpoint is in disabled or stopped state.
Sep 04 17:37:28 k8s-node-01 sqlservr[15012]: 2019-09-04 17:37:28.34 spid24s     Service Broker manager has started.
Sep 04 17:37:28 k8s-node-01 sqlservr[15012]: 2019-09-04 17:37:28.35 spid5s      Recovery is complete. This is an informational message only. No user action is required.
Sep 04 17:37:32 k8s-node-01 sqlservr[15012]: 2019-09-04 17:37:32.04 spid11s     The activated proc '[dbo].[sp_syspolicy_events_reader]' running on queue 'msdb.dbo.sys...
Hint: Some lines were ellipsized, use -l to show in full.
[root@k8s-node-01 bin]# systemctl enable mssql-server
[root@k8s-node-01 bin]# ps -ef | grep mssql
mssql     15012      1  1 17:37 ?        00:00:00 /opt/mssql/bin/sqlservr
mssql     15033  15012 15 17:37 ?        00:00:08 /opt/mssql/bin/sqlservr
root      15269  11154  0 17:38 pts/1    00:00:00 grep --color=auto mssql

接下来需要安装sqlcmd 连接工具并加入环境变量。

[root@k8s-node-01 bin]# yum install -y mssql-tools unixODBC-devel
[root@k8s-node-01 bin]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
[root@k8s-node-01 bin]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
[root@k8s-node-01 bin]# source ~/.bashrc

基本上大功告成了,可以连接实验一下:

[root@k8s-node-01 bin]# sqlcmd -S localhost -U SA -P 'tigergao@123'
1> CREATE DATABASE tigergao
2> go
1> use tigergao
2> go
Changed database context to 'tigergao'.
1> CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
2> INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
3> go

(1 rows affected)

(1 rows affected)
1> select * from  Inventory;
2> go
id          name                                               quantity
----------- -------------------------------------------------- -----------
          1 banana                                                     150
          2 orange                                                     154

(2 rows affected)
1>

当然也可以下载个客户端,用 win 直接去连服务端即可。

其实一点都不复杂,近期以学习养生为主。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值