Instalacja ODBC MSSQL na dystrybucjach RHEL

Komendy można wykonywać całościowo jako blok tekstu 

 if ! [[ "7 8 9" == *"$(grep VERSION_ID /etc/os-release | cut -d '"' -f 2 | cut -d '.' -f 1)"* ]];

then

 echo "RHEL $(grep VERSION_ID /etc/os-release | cut -d '"' -f 2 | cut -d '.' -f 1) is not currently supported.";

 exit;

fi

# Download the package to configure the Microsoft repo

curl -sSL -O https://packages.microsoft.com/config/rhel/$(grep VERSION_ID /etc/os-release | cut -d '"' -f 2 | cut -d '.' -f 1)/packages-microsoft-prod.rpm

# Install the package

sudo yum install packages-microsoft-prod.rpm

# Delete the file

rm packages-microsoft-prod.rpm

sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts

sudo ACCEPT_EULA=Y yum install -y msodbcsql18

# optional: for bcp and sqlcmd

sudo ACCEPT_EULA=Y yum install -y mssql-tools18

echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc

source ~/.bashrc

# optional: for unixODBC development headers

sudo yum install -y unixODBC-devel 

 Po instalacji oczywiście należy skonfigurować plik połączeń  

 /etc/odbc.ini 

 Przykładowy config dla bazy MSSQL 

 # DSN dla Microsoft SQL Server (MSSQL) z ODBC Driver 18 i self-signed cert

[DSN_MSSQL]

Driver = ODBC Driver 18 for SQL Server

Server = sqlserver.example.local

Port = 1433

Database = your_database

TrustServerCertificate = Yes

# Uwierzytelnianie SQL (UID i PWD podaje Zabbix przez makra)

# Trusted_Connection=Yes # NIE aktywuj, jeśli nie masz Kerberosa 

   

  