blog-details

Hướng dẫn này sẽ hướng dẫn bạn cách cài đặt Microsoft SQL Server (MS SQL) trên RHEL / CentOS 8. MS SQL là một hệ thống cơ sở dữ liệu quan hệ của Microsoft, có nguồn mở vào năm 2016. Bắt đầu với SQL Server 2017, nó đã có sẵn để sản xuất khối lượng công việc trên RHEL và các bản phân phối Linux khác.

Bản phát hành MS SQL Server có sẵn cho khối lượng công việc sản xuất là MS SQL 2017 và MS SQL 2019. Thực hiện theo các bước trong phần tiếp theo để cài đặt và chạy Microsoft SQL Server (MS SQL) 2019 trên máy chủ RHEL / CentOS 8 Linux.

Dưới đây là các yêu cầu hệ thống tối thiểu để chạy MS SQL Server 2019 trên CentOS 8 / RHEL 8 Linux:

    Bộ nhớ tối thiểu 3 GB
    Bộ xử lý CPU tốc độ tối thiểu 1,4 GHz. Nhưng khuyến nghị là> = 2 GHz
    SQL Server yêu cầu tối thiểu 10 GB dung lượng đĩa cứng khả dụng

Step 1: Thêm repository SQL -  Add the Microsoft SQL Server 2019 repository

The Microsoft SQL database server packages are available on Red Hat repository which needs to be added manually.

sudo curl https://packages.microsoft.com/config/rhel/8/mssql-server-2019.repo -o /etc/yum.repos.d/mssql-server-2019.repo 
sudo  curl https://packages.microsoft.com/config/rhel/8/prod.repo -o /etc/yum.repos.d/msprod.repo

Step 2: Tiến hành cài - Install MS SQL server on RHEL 8 / CentOS 8

All the packages required for Microsoft SQL Server 2019 are available on the repositories added. Just execute the commands below to install MS SQL server on CentOS 8 / RHEL 8 Linux.

sudo dnf -y install mssql-server

 

Dependency tree:

Dependencies resolved.
========================================================================================================================================================
 Package                          Arch           Version                                         Repository                                        Size
========================================================================================================================================================
Installing:
 mssql-tools                      x86_64         17.5.2.1-1                                      packages-microsoft-com-prod                      223 k
 unixODBC-devel                   x86_64         2.3.7-1.rh                                      packages-microsoft-com-prod                       42 k
 mssql-server                     x86_64         15.0.4033.1-2                                   packages-microsoft-com-mssql-server-2019         209 M
Installing dependencies:
 gc                               x86_64         7.6.4-3.el8                                     AppStream                                        109 k
 gdb                              x86_64         8.2-6.el8                                       AppStream                                        296 k
 gdb-headless                     x86_64         8.2-6.el8                                       AppStream                                        3.7 M
 guile                            x86_64         5:2.0.14-7.el8                                  AppStream                                        3.5 M
 libatomic_ops                    x86_64         7.6.2-3.el8                                     AppStream                                         38 k
 libbabeltrace                    x86_64         1.5.4-2.el8                                     AppStream                                        201 k
 libipt                           x86_64         1.6.1-8.el8                                     AppStream                                         50 k
 python2                          x86_64         2.7.16-12.module_el8.1.0+219+cf9e6ac9           AppStream                                        109 k
 python2-libs                     x86_64         2.7.16-12.module_el8.1.0+219+cf9e6ac9           AppStream                                        6.0 M
 python2-pip-wheel                noarch         9.0.3-14.module_el8.1.0+219+cf9e6ac9            AppStream                                        1.2 M
 python2-setuptools-wheel         noarch         39.0.1-11.module_el8.1.0+219+cf9e6ac9           AppStream                                        289 k
 msodbcsql17                      x86_64         17.5.2.1-1                                      packages-microsoft-com-prod                      802 k
 unixODBC                         x86_64         2.3.7-1.rh                                      packages-microsoft-com-prod                      213 k
Installing weak dependencies:
 python2-pip                      noarch         9.0.3-14.module_el8.1.0+219+cf9e6ac9            AppStream                                        2.0 M
 python2-setuptools               noarch         39.0.1-11.module_el8.1.0+219+cf9e6ac9           AppStream                                        643 k
Enabling module streams:
 python27                                        2.7                                                                                                   

Transaction Summary
========================================================================================================================================================
Install  18 Packages

Accept License Agreement when you see a prompt:

The license terms for this product can be downloaded from
https://aka.ms/odbc17eula 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

Step 3: Install SQL Server command-line tools

Then install mssql-tools with the unixODBC developer package.

sudo yum -y install mssql-tools unixODBC-devel 

Accept License:

Do you accept the license terms? (Enter YES or NO)
YES
  Installing       : msodbcsql17-17.5.2.1-1.x86_64                                                                                                 2/4 
  Running scriptlet: msodbcsql17-17.5.2.1-1.x86_64                                                                                                 2/4 
  Running scriptlet: mssql-tools-17.5.2.1-1.x86_64                                                                                                 3/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

See below.

Confirm installation.

$ rpm -qi mssql-server
Name        : mssql-server
Version     : 15.0.4033.1
Release     : 2
Architecture: x86_64
Install Date: Sun 19 Apr 2020 08:44:02 PM EAT
Group       : Unspecified
Size        : 1095014063
License     : Commercial
Signature   : RSA/SHA256, Mon 30 Mar 2020 08:05:33 PM EAT, Key ID eb3e94adbe1229cf
Source RPM  : mssql-server-15.0.4033.1-2.src.rpm
Build Date  : Fri 27 Mar 2020 02:16:54 AM EAT
Build Host  : hls-rhel8-1-prod-build-rhel8-01
Relocations : (not relocatable)
Summary     : Microsoft SQL Server Relational Database Engine
....

$ rpm -qi mssql-tools 
Name        : mssql-tools
Version     : 17.5.2.1
Release     : 1
Architecture: x86_64
Install Date: Sun 19 Apr 2020 08:45:46 PM EAT
Group       : Applications/Driver
Size        : 726935
License     : http://go.microsoft.com/fwlink/?LinkId=746949
Signature   : RSA/SHA256, Tue 03 Mar 2020 10:25:59 PM EAT, Key ID eb3e94adbe1229cf
Source RPM  : mssql-tools-17.5.2.1-1.src.rpm
Build Date  : Tue 03 Mar 2020 09:10:21 PM EAT
Build Host  : ODBC-029-CentOS68-1.galaxy.ad
Relocations : (not relocatable)
Packager    : Microsoft SQL Tools Team <[email protected]>
Summary     : Tools for Microsoft(R) SQL Server (R)
....

Step 4: Initialize MS SQL Database Engine

After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

sudo /opt/mssql/bin/mssql-conf setup

1. Select an edition you’d like to use

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

For me. I’ll go with 2 – Developer (free, no production use rights).

2. Accept the license terms

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

3. Set SQL Server system administrator password:

Enter the SQL Server system administrator password: <Password>
Confirm the SQL Server system administrator password: <Confirm Password> Configuring SQL Server... 

ForceFlush is enabled for this instance. 
ForceFlush feature is enabled for log durability.
Created symlink /etc/systemd/system/multi-user.target.wants/mssql-server.service → /usr/lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.

The service should be started and set to start at boot.

$ systemctl status mssql-server.service 
● 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 Sun 2020-04-19 21:05:26 EAT; 1h 52min ago
Docs: https://docs.microsoft.com/en-us/sql/linux
Main PID: 8699 (sqlservr)
Tasks: 157
Memory: 727.2M
CGroup: /system.slice/mssql-server.service
├─8699 /opt/mssql/bin/sqlservr
└─8727 /opt/mssql/bin/sqlservr
Apr 19 21:05:30 cent8.novalocal sqlservr[8699]: [61B blob data]
Apr 19 21:05:30 cent8.novalocal sqlservr[8699]: [96B blob data]
Apr 19 21:05:30 cent8.novalocal sqlservr[8699]: [66B blob data]

$ systemctl is-enabled mssql-server.service 
enabled

Add /opt/mssql/bin/ to your $PATH variable:

echo 'export PATH=$PATH:/opt/mssql/bin:/opt/mssql-tools/bin' | sudo tee /etc/profile.d/mssql.sh

Source the file to start using MS SQL executable binaries in your current shell session:

source /etc/profile.d/mssql.sh

If you have an active Firewalld service, allow SQL Server ports for remote hosts to connect:

sudo  firewall-cmd --add-port=1433/tcp --permanent
sudo firewall-cmd --reload

Step 5: Test SQL Server

Connect to the SQL Server and verify it is working.

$ sqlcmd -S localhost -U SA

Authenticate with the password set in Step 4.

Show Database users:

1> select name from sysusers;
2> go
name
MS_AgentSigningCertificate##
MS_PolicyEventProcessingLogin##
db_accessadmin
db_backupoperator
db_datareader
db_datawriter
db_ddladmin
db_denydatareader
db_denydatawriter
db_owner
db_securityadmin
dbo
guest
INFORMATION_SCHEMA
public
sys
(16 rows affected)
1>

Create a test database:

CREATE DATABASE mytestDB
SELECT Name from sys.Databases
GO
USE mytestDB
CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
GO
SELECT * FROM Inventory LIMIT 1;

Show databases on the SQL Server.

1> select name,database_id from sys.databases; 
2> go
name          database_id
------------- -----------
master                  1
tempdb                  2
model                   3
msdb                    4
testDB                  5
(5 rows affected)

Drop a database:

1> DROP DATABASE testDB;
2> GO

Installation of SQL Server on other Linux systems:

Đánh giá bài viết