Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
SQL Server on Linux
This article explains how to configure SMB storage for a failover cluster instance (FCI) on Linux.
Outside Windows, SMB is also called a Common Internet File System (CIFS) share, which Samba implements. On Windows, you access an SMB share with the format \\SERVERNAME\SHARENAME. For Linux-based SQL Server installations, you must mount the SMB share as a folder.
Important source and server information
Follow these tips to use SMB successfully:
- The SMB share can be on Windows, Linux, or an appliance as long as it uses SMB 3.0 or later. For more information about Samba and SMB 3.0, see SMB 3.0 to check whether your Samba implementation complies with SMB 3.0.
- The SMB share should be highly available.
- Set security properly on the SMB share. The following example is from
/etc/samba/smb.conf, whereSQLDatais the name of the share.
[SQLData]
path=/var/smb/SQLData
read only = no
browseable = yes
guest ok = no
writeable = yes
valid users = SQLSambaUser
Instructions
Choose one of the servers to participate in the FCI configuration. It doesn't matter which one.
Get information about the
mssqluser.sudo id mssqlNote the
uid,gid, and groups.Execute
sudo smbclient -L //NameOrIP/ShareName -U User.<NameOrIP>is the DNS name or IP address of the server hosting the SMB share.<ShareName>is the name of the SMB share.
For system databases, or anything stored in the default data location, follow these steps. Otherwise skip to step 5.
Ensure that SQL Server is stopped on the server you're working on.
sudo systemctl stop mssql-server sudo systemctl status mssql-serverSwitch fully to the superuser.
sudo -iSwitch to the
mssqluser.su mssqlCreate a temporary directory to store the SQL Server data and log files.
mkdir <TempDir><TempDir>is the name of the folder. The following example creates a folder named/var/opt/mssql/tmp.
mkdir /var/opt/mssql/tmpCopy the SQL Server data and log files to the temporary directory.
cp /var/opt/mssql/data/* <TempDir><TempDir>is the name of the folder from the previous step.
Verify that the files are in the directory.
ls <TempDir><TempDir> is the name of the folder from Step d.
Delete the files from the existing SQL Server data directory.
rm -f /var/opt/mssql/data/*Verify that the files no longer exist.
ls /var/opt/mssql/dataEnter
exitto switch back to therootuser.Mount the SMB share in the SQL Server data folder. This example shows the syntax for connecting to a Windows Server-based SMB 3.0 share.
mount -t cifs //<ServerName>/<ShareName> /var/opt/mssql/data -o vers=3.0,username=<UserName>,password=<Password>,domain=<domain>,uid=<mssqlUID>,gid=<mssqlGID>,file_mode=0777,dir_mode=0777<ServerName>is the name of the server with the SMB share<ShareName>is the name of the share<UserName>is the name of the user to access the share<Password>is the password for the user<domain>is the name of Active Directory<mssqlUID>is the UID of themssqluser<mssqlGID>is the GID of themssqluser
Verify the mount by running
mountwith no switches.mountSwitch to the
mssqluser.su mssqlCopy the files from the temporary directory
/var/opt/mssql/data.cp /var/opt/mssql/tmp/* /var/opt/mssql/dataVerify the files are there.
ls /var/opt/mssql/dataEnter
exitto leave themssqluser.Enter
exitto leave therootuser.Start SQL Server. If you copied everything and applied security correctly, SQL Server starts.
sudo systemctl start mssql-server sudo systemctl status mssql-serverTo test further, create a database to ensure the permissions are fine. The following example uses Transact-SQL; you can use SQL Server Management Studio (SSMS).
Stop SQL Server and verify it's shut down. If you plan to add or test other disks, don't shut down SQL Server until you add and test them.
sudo systemctl stop mssql-server sudo systemctl status mssql-serverIf you're finished, unmount the share. Otherwise, unmount after you finish testing or adding disks.
sudo umount //<IPAddressorServerName>/<ShareName>/<FolderMountedIn><IPAddressOrServerName>is the IP address or name of the SMB host<ShareName>is the name of the share<FolderMountedIn>is the name of the folder where SMB is mounted
For things other than system databases, such as user databases or backups, follow these steps. If you use only the default location, skip to Step 14.
Switch to the superuser.
sudo -iCreate a folder for SQL Server to use.
mkdir <FolderName><FolderName> is the name of the folder. Specify the folder's full path if it isn't in the right location. The following example creates a folder named
/var/opt/mssql/userdata.mkdir /var/opt/mssql/userdataMount the SMB share in the SQL Server data folder. This example shows the syntax for connecting to a Samba-based SMB 3.0 share.
mount -t cifs //<ServerName>/<ShareName> <FolderName> -o vers=3.0,username=<UserName>,password=<Password>,uid=<mssqlUID>,gid=<mssqlGID>,file_mode=0777,dir_mode=0777<ServerName>is the name of the server with the SMB share<ShareName>is the name of the share<FolderName>is the name of the folder created in the last step<UserName>is the name of the user to access the share<Password>is the password for the user<mssqlUID>is the UID of themssqluser<mssqlGID>is the GID of themssqluser.
Verify the mount by running
mountwith no switches.Enter
exitto leave the superuser.To test, create a database in that folder. The following example uses
sqlcmdto create a database, switch context to it, verify the files exist at the OS level, and then delete the temporary location. You can use SSMS.Unmount the share.
sudo umount //<IPAddressorServerName>/<ShareName> /<FolderMountedIn><IPAddressOrServerName>is the IP address or name of the SMB host<ShareName>is the name of the share<FolderMountedIn>is the name of the folder where SMB is mounted.
Repeat the steps on the other nodes.
You're now ready to configure the FCI.