Computer >> Máy Tính >  >> Lập trình >> MySQL

Cách cài đặt và cấu hình MS SQL (Beta) trên CentOS 7

Trong bài viết này, chúng ta sẽ tìm hiểu về - Cách cài đặt và cấu hình MS SQL trên CentOS 7. Gần đây Microsoft đã thông báo rằng họ đang có kế hoạch phát hành MS SQL cho Linux. Đặc biệt là các phiên bản beta dành cho RedHat doanh nghiệp Linux, Centos &Ubuntu nhưng chỉ với các phiên bản 64-bit.

Điều kiện tiên quyết

  • Máy có RAM tối thiểu 4 GB và dung lượng đĩa cứng 30 GB.
  • Máy được cài đặt CentOS 7.
  • Người dùng có đặc quyền root hoặc người dùng root.

Cài đặt MS SQL Server trên CentOS

Vì MS SQL không có sẵn với kho lưu trữ CentOS mặc định, chúng tôi cần thêm thông tin chi tiết về kho lưu trữ MS SSQL vào kho lưu trữ yum cục bộ.

Để cài đặt MS SQL Server bằng dòng lệnh, chúng tôi cần thêm kho lưu trữ vào kho lưu trữ yum cục bộ.

# curl https://packages.microsoft.com/config/rhel/7/mssql-server.repo > /etc/yum.repos.d/mssql-server.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 220 100 220 0 0 257 0 --:--:-- --:--:-- --:--:-- 257

Sau khi cập nhật kho lưu trữ, chúng tôi sẽ chạy lệnh dưới đây để cài đặt máy chủ MS-SQL

# yum update
# yum install -y mssql-server
…
…
Resolving Dependencies
--> Running transaction check
---> Package mssql-server.x86_64 0:14.0.1.246-6 will be installed
--> Processing Dependency: bzip2 for package: mssql-server-14.0.1.246-6.x86_64
--> Processing Dependency: gdb for package: mssql-server-14.0.1.246-6.x86_64
--> Running transaction check
---> Package bzip2.x86_64 0:1.0.6-13.el7 will be installed
---> Package gdb.x86_64 0:7.6.1-80.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mssql-server x86_64 14.0.1.246-6 packages-microsoft-com-mssql-server 138 M
Installing for dependencies:
bzip2 x86_64 1.0.6-13.el7 base 52 k
gdb x86_64 7.6.1-80.el7 base 2.4 M
Transaction Summary
================================================================================
Install 1 Package (+2 Dependent packages)
…
…
+-------------------------------------------------------------------+
| Please run /opt/mssql/bin/sqlservr-setup to complete the setup of |
| Microsoft(R) SQL Server(R). |
+-------------------------------------------------------------------+
Verifying : mssql-server-14.0.1.246-6.x86_64 1/3
Verifying : gdb-7.6.1-80.el7.x86_64 2/3
Verifying : bzip2-1.0.6-13.el7.x86_64 3/3
Installed:
mssql-server.x86_64 0:14.0.1.246-6
Dependency Installed:
bzip2.x86_64 0:1.0.6-13.el7 gdb.x86_64 0:7.6.1-80.el7
Complete!

Định cấu hình tài khoản MS SQL SA

Sau khi cài đặt xong, chúng tôi sẽ chạy tập lệnh sqlservr-setup để thiết lập mật khẩu của SA; chúng tôi cần cung cấp một mật khẩu mạnh cho tài khoản SA (với tối thiểu 8 ký tự, chữ thường và chữ hoa với các số từ 1 đến 10 hoặc bất kỳ ký tự số không phải chữ cái nào)

# sudo /opt/mssql/bin/sqlservr-setup
Microsoft(R) SQL Server(R) Setup
You can abort setup at any time by pressing Ctrl-C. Start this program
with the --help option for information about running it in unattended
mode.
Please enter a password for the system administrator (SA) account:
Please confirm the password for the system administrator (SA) account:
Setting a password for the system administrator (SA) account
Do you wish to start the SQL Server service now? [y/n]: Y
Do you wish to enable SQL Server to start on boot? [y/n]: y
Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /usr/lib/systemd/system/mssql-server.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server-telemetry.service to /usr/lib/systemd/system/mssql-server-telemetry.service.
Setup completed successfully.

Sau khi cấu hình xong, chúng tôi sẽ khởi động lại các dịch vụ MS SQL và sẽ thấy trạng thái của các dịch vụ bằng lệnh dưới đây -

Để khởi động lại các dịch vụ

# systemctl start mssql-server

Xem trạng thái của các dịch vụ

# systemctl status mssql-server
mssql-server.service - Microsoft(R) SQL Server(R) Database EngineLoaded: loaded (/usr/lib/systemd/system/mssql-server.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2016-12-02 15:52:33 IST; 5min ago
Main PID: 2299 (sqlservr)
CGroup: /system.slice/mssql-server.service
├─2299 /opt/mssql/bin/sqlservr
└─2307 /opt/mssql/bin/sqlservr
Dec 02 15:52:37 localhost.localdomain sqlservr[2299]: 2016-12-02 10:22:37.31 spid17s....
Dec 02 15:52:37 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/mssql-ser...'
Dec 02 15:52:37 localhost.localdomain sqlservr[2299]: 2016-12-02 10:22:37.53 spid6s ....
..
..
Dec 02 15:57:40 localhost.localdomain sqlservr[2299]: 2016-12-02 10:27:40.21 spid51 ...'
Dec 02 15:57:43 localhost.localdomain systemd[1]: Started Microsoft(R) SQL Server(R)....Hint: Some lines were eclipsed, use -l to show in full.

Mở tường lửa cho MS SQL

Chúng tôi cần mở cài đặt tường lửa để có thể truy cập MS SQL, dưới đây là lệnh để mở tường lửa

# sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
# sudo firewall-cmd –reload

Cài đặt công cụ MS SQL

Chúng tôi cần tải xuống kho lưu trữ của Microsoft.

# curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 193 100 193 0 0 213 0 --:--:-- --:--:-- --:--:-- 213

Sau khi kho lưu trữ được cài đặt trên máy cục bộ, chúng ta có thể sử dụng lệnh dưới đây để cài đặt các công cụ MS SQL bằng lệnh dưới đây -

# yum install mssql-tools
Loaded plugins: fastestmirror
packages-microsoft-com-prod | 2.9 kB 00:00:00
packages-microsoft-com-prod/primary_db | 4.6 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.digipower.vn
* extras: mirror.digistar.vn
* updates: mirror.digistar.vn
Resolving Dependencies
========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
mssql-tools x86_64 14.0.1.246-1 packages-microsoft-com-prod 249 k
Installing for dependencies:
libtool-ltdl x86_64 2.4.2-21.el7_2 updates 49 k
msodbcsql x86_64 13.0.1.0-1 packages-microsoft-com-prod 3.8 M
unixODBC-utf16 x86_64 2.3.1-1 packages-microsoft-com-prod 329 k
Transaction Summary
========================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 4.5 M
Installed size: 4.5 M
Is this ok [y/d/N]: ^CN
Exiting on user command
Your transaction was saved, rerun it with:
yum load-transaction /tmp/yum_save_tx.2016-12-02.17-18.RpEVqg.yumtx
Do you accept the license terms? (Enter YES or NO)YES
Installing : msodbcsql-13.0.1.0-1.x86_64 3/4
The license terms for this product can be downloaded from
https://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
Dependency Installed:
libtool-ltdl.x86_64 0:2.4.2-21.el7_2 msodbcsql.x86_64 0:13.0.1.0-1
unixODBC-utf16.x86_64 0:2.3.1-1
Complete!

Kết nối với SQL Server trên Linux

Sau khi các công cụ được cài đặt trên máy, chúng tôi sẽ kiểm tra các lệnh dưới đây và cú pháp chung để kết nối với máy chủ MS SQL.

Cú pháp

# sqlcmd –S IP-ADDRESS –U SA –P ‘<YOUR SYSTEM PASSWORD’
# sqlcmd sqlcmd -S localhost -U SA -P Test@1234
1>CREATE DATABASE TEST1;
2>GO;
3>quit

Trong bài viết trên, chúng ta đã cùng nhau tìm hiểu - Cách cài đặt MS SQL Server, công cụ dòng lệnh MS SQL để kết nối với máy chủ. Ngoài ra, chúng ta đã tìm hiểu - Cách thay đổi hoặc thiết lập mật khẩu tài khoản SA cho MS SQL.