Share via


SQL Server installation on CentOS (Linux)

                                                https://msdnshared.blob.core.windows.net/media/2016/08/0841.NinjaAwardTinySilver.pngSilver Award Winner                       

This article explains how to install SQL Server 2017 CTP with an offline setup in Linux.

Minimum requirement for MSSQL installation

  • We need at least 3.25GB of memory to run SQL Server on Linux.
  • SQL Server Engine has been tested up to 1 TB of memory at this time. The file system must be XFS or EXT4. Other file systems, such as BTRFS, are unsupported. 

               

mount | grep "^/dev"       --check file system 

                /dev/mapper/vg1-root_lv on / type ext4 (rw,relatime,data=ordered)
               /dev/sda1 on /boot type ext4 (rw,relatime,data=ordered)
              /dev/mapper/vg1-tmp_lv on /tmp type ext4 (rw,relatime,data=ordered)

  • We need administrative access for installation.

**            sudo -l -U msdba   -->User msdba is not allowed to run sudo on servername**

Fresh install

1. Login with superuser

#Sudo su 
#cat /etc/centos-release  --check version

     CentOS Linux release 7.3.1611 (Core)
     My system is Centos 7 so I am selecting 7. there is 6 also.
[https://packages.microsoft.com/config/rhel/

**    Check ip: Ifconfig**

](https://packages.microsoft.com/config/rhel/)

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.16.1.54 netmask 255.255.255.0  broadcast 172.16.2.255
        inet6 fe80::215:5dff:fe0c:ca05  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:0c:ca:05  txqueuelen 1000  (Ethernet)
        RX packets 35630910  bytes 22082879940 (20.5 GiB)
        RX errors 0  dropped 1826364  overruns 0  frame 0
        TX packets 24340926  bytes 2595346733 (2.4 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 175829697  bytes 237477231652 (221.1 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 175829697  bytes 237477231652 (221.1 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


2. Download Microsoft SQL Server Red Hat repository configuration file

     You can copy repository file using WinSCP to CentOS machine.

3. Copy file in /etc/yum.repos.d/firectory

Yum repository must present in this location only

cp  mssql-server.repo /etc/yum.repos.d/mssql-server.repo

cp prod.repo /etc/yum.repos.d/msprod.repo

4. Install mssql using yum install

sudo yum install -y mssql-server
#sudo yum install -y mssql-server 
 
  Loaded plugins: fastestmirror, langpacks packages-microsoft-com-mssql-server  | 2.9 kB  00:00  
 
  Loading mirror speeds from  cached hostfile
 * base: mirror.fibergrid.in
 * epel: repo.ugm.ac.id
 * extras: mirror.fibergrid.in
 * updates: mirror.fibergrid.in
  Resolving Dependencies
   --> Running transaction check
   ---> Package mssql-server.x86_64 0:14.0.500.272-2 will be installed
   --> Finished Dependency Resolution
  Dependencies Resolved
   ================================================================================
    Package  Arch  Version  Repository  Size
   ================================================================================
  Installing:
  mssql-server x86_64 14.0.500.272-2  packages-microsoft-com-mssql-server 159 M
  Transaction Summary
   ================================================================================
   Install  1 Package
   Total download size: 159 M
   Installed size: 159 M
   Downloading packages:
   mssql-server-14.0.500.272- 0% [  ]  0.0 B/s |  0 B  --:-- ETA
   mssql-server-14.0.500.272- 0% [  ]  0.0 B/s | 576 kB  --:-- ETA
   mssql-server-14.0.500.272- 0% [  ] 1.3 MB/s | 1.4 MB  02:01 ETA
   mssql-server-14.0.500.272- 1% [  ] 1.4 MB/s | 2.4 MB  01:52 ETA
   mssql-server-14.0.500.272- 99% [===============-] 4.2 MB/s | 157 MB  00:00 ETA
   mssql-server-14.0.500.272- 99% [===============-] 4.2 MB/s | 159 MB  00:00 ETA
   mssql-server-14.0.500.272-2.x86_64.rpm  | 159 MB  00:39 
   Running transaction  check
   Running transaction  test
   Transaction test succeeded
   Running transaction
    Installing : mssql-server-14.0.500.272-2. [############################ ] 1/1
    Installing : mssql-server-14.0.500.272-2.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.500.272-2.x86_64  1/1
     Installed:
       mssql-server.x86_64 0:14.0.500.272-2 
    Complete!

5. Configuration and setting SA password with a strong password

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

.

# sudo /opt/mssql/bin/mssql-conf setup
    The license terms for  this product can be downloaded from
     http://go.microsoft.com/fwlink/?LinkId=746388
    and found in  /usr/share/doc/mssql-server/LICENSE.TXT.
    Do you accept the license terms? [Yes/No]:yes 
      Setting up Microsoft SQL Server 
    Enter the new SQL Server system administrator password:  --Enter strong password
    Confirm the new SQL Server system administrator password: --Enter strong password
     starting Microsoft SQL Server... 
     Enabling Microsoft SQL Server to  run at  boot...
    Setup completed successfully.

6. Check mssql services packages are installed

  root #rpm -qa | grep mssql

        mssql-server-14.0.500.272-2.x86_64                                                                                                              

7. Check mssql services is running

  root # 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 Mon 2017-05-01 11:59:13 IST; 3min 17s ago
 Docs:
https://docs.microsoft.com/en-us/sql/linux
  Main PID: 15429 (sqlservr)
 CGroup: /system.slice/mssql-server.service
 15429 /opt/mssql/bin/sqlservr
 15454 /opt/mssql/bin/sqlservr
    May 01 11:59:20 DBAT sqlservr[15429]: 2017-05-01 11:59:20.87 spid19s ....
    May 01 11:59:20 DBAT sqlservr[15429]: 2017-05-01 11:59:20.87 Server  ....
    May 01 11:59:20 DBAT sqlservr[15429]: 2017-05-01 11:59:20.88 Server  ....
    May 01 11:59:20 DBAT sqlservr[15429]: 2017-05-01 11:59:20.88 spid19s ....
    May 01 11:59:21 DBAT sqlservr[15429]: 2017-05-01 11:59:21.53 spid9s  ....
    May 01 11:59:22 DBAT sqlservr[15429]: 2017-05-01 11:59:22.09 spid9s  ....
    May 01 11:59:22 DBAT sqlservr[15429]: 2017-05-01 11:59:22.13 spid21s ....
    May 01 11:59:22 DBAT sqlservr[15429]: 2017-05-01 11:59:22.13 spid21s ....
    May 01 11:59:22 DBAT sqlservr[15429]: 2017-05-01 11:59:22.24 spid21s ....
    May 01 11:59:22 DBAT sqlservr[15429]: 2017-05-01 11:59:22.44 spid5s  ....
  
    Hint: Some lines were ellipsized, use -l to  show in  full

8. Enable firewall rule
  

   

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

 
**9. Install mssql agent **

#sudo yum install mssql-server-agent
#sudo systemctl restart mssql-server

10. Remove old version


      sudo yum     update  
      sudo yum remove unixODBC-utf16 unixODBC-utf16-devel  

11. Enable it to start on system boot

sudo systemctl enable mssql-server

**11. Install mssql tools with unixODBC developer packages. **

 sudo yum ``update


      sudo yum install mssql-tools unixODBC-devel  

12. Check for last updated version


      sudo yum     check    -    update  
      sudo yum     update  mssql-server-agent
      sudo yum     update  mssql-tools
      sudo systemctl restart mssql-server  

13. Login in mssql using Sqlcmd

[root]# sqlcmd -S 10.16.1.54 -U sa
Password:
1> select @@version
2> go
Microsoft SQL Server vNext (CTP2.0) - 14.0.500.272 (X64)         Apr 13 2017 11:44:40         Copyright (C) 2017 Microsoft Corporation. All rights reserved.  Developer Edition (64-bit) on Linux (CentOS Linux 7 (Core))                                                                                            

 

14. Check mssql process

# ps -ef | grep mssql
    mssql    36817     1  0 Jul28 ?        00:00:00 /opt/mssql/bin/sqlservr
    mssql    36851 36817  1 Jul28 ?        04:46:58 /opt/mssql/bin/sqlservr
   root     55572 55513  0 19:54 pts/0    00:00:00 grep --color=auto mssql

**15. Check package information of mssql
**

# yum info mssql-server

   Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.mirror.net.in
 * epel: kartolo.sby.datautama.net.id
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Installed Packages
Name        : mssql-server
Arch        : x86_64
Version     : 14.0.900.75
Release     : 1
Size        : 870 M
Repo        : installed
From repo   : packages-microsoft-com-mssql-server
Summary     : Microsoft SQL Server Relational Database Engine
License     : Commercial
Description : The mssql-server package contains the Microsoft SQL Server Relational Database Engine.

Errors

sqlcmd: command not found

make  sure that you have create link in  following path.

sudo ls /opt/mssql-tools/bin/sqlcmd*
sudo ln -sfn /opt/mssql-tools/bin/sqlcmd /usr/bin/sqlcmd

**Note: **The ln command is used to create links between files. And parameters of this command s, f, n have different purposes.

Suggested Readings

This article participated in Technet Guru Competition may-2017 and won a Silver Medal.

sudo yum update mssql-server-agent

sudo yum update mssql-tools