Hướng dẫn cài bionic v3.0 wordpress

MS SQL liên quan tới hệ thống CSDL của Microsoft và bắt đầu được Open sourced từ năm 2016. Dưới đây là bài viết hướng dẫn cách cài và cấu hình MS SQL 2017 trên Ubuntu Linux x64 (Ubuntu 18.04 Bionic Beaver Linux).

Hướng dẫn cài bionic v3.0 wordpress

Dưới đây là cấu hình hệ thống cơ bản để cài và chạy MS SQL trên Ubuntu 18.04 / 16.04 server:

  • Cấu hình bộ nhớ thấp nhất: 1 GRAM.
  • CPU tốc độ tối thiểu: 1.4 GHz. Nên có tốc độ cao hơn >= 2 GHz.
  • SQL Server yêu cầu tối thiếu dung lượng: 10 GB ổ cứng SSD trống.

Phần 1. Cài đặt MS SQL Server trên Ubuntu 18.04 hoặc Ubuntu 16.04 LTS

Bước 1: Cập nhật hệ thống Ubuntu

Trên màn lệnh terminal của Ubuntu nhập 2 lệnh sau:

sudo apt-get update

sudo apt-get -y upgrade

Nếu phần lỗi “kernel” đã được cập nhật xong, chúng ta sẽ nhập tiếp lệnh để khởi động lại Ubuntu:

sudo reboot

Bước 2: Nhập key GPG lưu trữ bộ cài MS SQL “repository GPG keys”:

Nhập lệnh để thêm key:

sudo wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –

Bước 3: Thêm địa chỉ để download bộ cài Microsoft SQL Server Ubuntu repository:

Nhập lệnh sau:

sudo add-apt-repository “$(wget -qO- https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list)”

Bước 4: Nhập lệnh cài MS SQL Server 2017 trên Ubuntu 18.04/ Ubuntu 16.04 LTS

Gõ 3 lệnh sau:

sudo apt-get update

sudo apt install libcurl3

sudo apt-get install -y mssql-server

Màn hình các thao tác thực hiện sau:

Reading package lists… 0%

Reading package lists… Done

Building dependency tree

Reading state information… Done

The following packages were automatically installed and are no longer required:

grub-pc-bin libpython-all-dev python-all python-all-dev python-asn1crypto python-cffi-backend python-crypto python-cryptography python-dbus

python-enum34 python-gi python-idna python-ipaddress python-keyring python-keyrings.alt python-pkg-resources python-secretstorage

python-setuptools python-six python-wheel python-xdg

Use ‘apt autoremove’ to remove them.

The following NEW packages will be installed:

mssql-server

0 upgraded, 1 newly installed, 0 to remove and 15 not upgraded.

Need to get 176 MB of archives.

After this operation, 928 MB of additional disk space will be used.

Get:1 https://packages.microsoft.com/ubuntu/16.04/mssql-server-2017 xenial/main amd64 mssql-server amd64 14.0.3030.27-1 [176 MB]

Fetched 176 MB in 5s (36.3 MB/s)

Preconfiguring packages …

Selecting previously unselected package mssql-server.

(Reading database … 117280 files and directories currently installed.)

Preparing to unpack …/mssql-server_14.0.3030.27-1_amd64.deb …

Unpacking mssql-server (14.0.3030.27-1) …

Processing triggers for libc-bin (2.27-3ubuntu1) …

Setting up mssql-server (14.0.3030.27-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’.

Processing triggers for man-db (2.8.3-2) …

Processing triggers for libc-bin (2.27-3ubuntu1) …

Nếu đến đây xuất hiện lỗi: “mssql-server : Depends: openssl (<= 1.1.0) but 1.1.0g-2ubuntu4.1 is to be installed“.

Đây là lỗi SSL, Chúng ta sẽ hạ version SSL bằng cách cài openssl và hạ version để cài lại cùng mssql server, nhập 3 lệnh sau:

$ wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/openssl_1.0.2g-1ubuntu4_amd64.deb

$ sudo dpkg -i openssl_1.0.2g-1ubuntu4_amd64.deb

$ apt-get -y install mssql-server

Khi việc cài đặt xong, chúng ta sẽ xử lý cấu hình của MSSQL thiết lập mật khẩu cho root user thông qua file /opt/mssql/bin/mssql-conf:

Gõ lệnh sau:

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

Choose an edition of SQL Server:

  1. Evaluation (free, no production use rights, 180-day limit)
  1. Developer (free, no production use rights)
  1. Express (free)
  1. Web (PAID)
  1. Standard (PAID)
  1. Enterprise (PAID)
  1. Enterprise Core (PAID)
  1. 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: ### đây chính là mật khẩu sa của MS SQL 2017

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 /etc/systemd/system/multi-user.target.wants/mssql-server.service → /lib/systemd/system/mssql-server.service.

Setup has completed successfully. SQL Server is now starting.

Bây giờ chúng ta cần kiểm tra tình trạng đã khởi động của dịch vụ MS SQL, gõ lệnh:

$ systemctl status mssql-server.service

● mssql-server.service – Microsoft SQL Server Database Engine

Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor preset: enabled)

Active: active (running) since Wed 2019-09-18 14:39:34 UTC; 21s ago

Docs: https://docs.microsoft.com/en-us/sql/linux

Main PID: 3501 (sqlservr)

Tasks: 108

CGroup: /system.slice/mssql-server.service

├─3501 /opt/mssql/bin/sqlservr

└─3541 /opt/mssql/bin/sqlservr

Sep 18 14:39:37 ubuntu18 sqlservr[3501]: [155B blob data]

Sep 18 14:39:37 ubuntu18 sqlservr[3501]: [62B blob data]

Sep 18 14:39:37 ubuntu18 sqlservr[3501]: [61B blob data]

Sep 18 14:39:38 ubuntu18 sqlservr[3501]: [389B blob data]

Sep 18 14:39:38 ubuntu18 sqlservr[3501]: [66B blob data]

Sep 18 14:39:38 ubuntu18 sqlservr[3501]: [75B blob data]

Sep 18 14:39:38 ubuntu18 sqlservr[3501]: [96B blob data]

Sep 18 14:39:38 ubuntu18 sqlservr[3501]: [100B blob data]

Sep 18 14:39:38 ubuntu18 sqlservr[3501]: [71B blob data]

Sep 18 14:39:38 ubuntu18 sqlservr[3501]: [124B blob data]

Bước 5: Cài công cụ MS SQL client và gói hỗ trợ kết nối unixODBC plugin

Gõ lệnh sau:

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

Hướng dẫn cài bionic v3.0 wordpress
Tiếp theo nhập 3 lệnh sau:

2

Nếu gặp phải lỗi: Command ‘curl’ not found, but can be installed with: apt install curl

Chúng ta sẽ cài thêm bộ lệnh curl bằng cách gõ lệnh: apt install curl

Hướng dẫn cài bionic v3.0 wordpress

Sau khi cài bổ sung curl xong, ta tiếp tục nhập lại lệnh:

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
Tiếp theo nhập 3 lệnh sau:
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get -y install mssql-tools
sudo apt-get install unixodbc-dev
Tiếp theo, chúng ta phải thêm tham số "/opt/mssql-tools/bin/ " đưa đường dẫn "PATH" làm biến môi trường "environment variable",  để dùng các bộ lệnh bash shell.
Chúng ta nhập lệnh sau:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
Để có thể tương tác với các lệnh ở trạng thái không cần "login sessions", chúng ta sẽ sửa đường dẫn "PATH" trong ~/.bashrc file, nhập lệnh sau:
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

0

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

1

Bước 6. Kết nối với MS-SQL console:

# sqlcmd -S 127.0.0.1 -U SA

Password:

Nếu bạn gặp lỗi sau:

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2746.

Hướng dẫn cài bionic v3.0 wordpress

Đây là lỗi do phiên bản SSL version 1 cần phải được cập nhật, chúng ta sẽ phải cài lại OpenSSL thư viện version 1.0 để kết nối với SQL Server. Thực hiện các lệnh sau:

  1. Dừng SQL Server: sudo systemctl stop mssql-server
  2. Mở file mssql-server để sửa cấu hình dịch vụ: sudo systemctl edit mssql-server
  3. Nội dung của file mssql-server thêm 2 dòng sau và lưu lại nội dung này: [Service] Environment=”LD_LIBRARY_PATH=/opt/mssql/lib”
  4. Tạo đường link tới 2 thư viện của OpenSSL 1.0 để kết nối SQL Server: sudo ln -s /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 /opt/mssql/lib/libssl.so sudo ln -s /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 /opt/mssql/lib/libcrypto.so
  5. Khởi động lại SQL Server: sudo systemctl start mssql-server

Tiếp theo chúng ta có thể kiểm tra tình hình vận hành của MS-SQL Server bằng 3 lệnh sau:

1> create database testDB;

Get a list database:

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

2

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

3

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

4

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

5

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

6

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

7

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

8

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

9

Tiếp theo nhập 3 lệnh sau:

0

Tiếp theo nhập 3 lệnh sau:

1

Phần 2. Lập trình, thiết kế CSDL và Administrator DBA:

Các bạn có thể dùng tool Microsoft SQL Server Management Studio:

Nhập thông tin địa chỉ tên/IPv4 của máy chủ MS-SQL server bạn vừa cài trên Ubuntu linux 18.04/16.04 LTS

Hướng dẫn cài bionic v3.0 wordpress

Phần mềm chuyên cho thiết kế, quản trị CSDL của MS-SQL Server 2017:

Hướng dẫn cài bionic v3.0 wordpress

Nếu cần thông tin hoặc học nâng cao về các công nghệ và phần mềm xử lý dữ liệu MS-SQL Database, Data-ware house, BI cho chuyên ngành của minh

Hay tìm hiểu các môn đó trên trang web: https://robusta.vn/

Chúc các bạn thành công!