How To Install Microsoft SQL Server on Fedora 42
Microsoft SQL Server has evolved significantly over the years, expanding beyond its Windows-only origins to embrace the Linux ecosystem. For system administrators and database professionals working with Fedora Linux, the ability to deploy SQL Server directly on their preferred platform represents a significant advantage. This comprehensive guide walks you through the complete process of installing and configuring Microsoft SQL Server on Fedora 42, providing you with the knowledge to successfully deploy this powerful database engine on Red Hat’s community-driven distribution.
Understanding SQL Server on Linux
Microsoft’s decision to bring SQL Server to Linux marked a significant shift in their platform strategy. Since 2017, SQL Server has been available for various Linux distributions, offering nearly all the features found in the Windows version. This cross-platform compatibility provides organizations with greater flexibility in their database infrastructure choices.
SQL Server on Linux maintains compatibility with its Windows counterpart, allowing for seamless data transfer and management across environments. The database engine’s core functionality remains consistent regardless of the operating system. This means Transact-SQL queries, stored procedures, and application connections work identically across platforms.
For Fedora users, SQL Server provides a robust alternative to open-source database solutions like PostgreSQL or MariaDB, particularly for enterprises with existing SQL Server experience or applications optimized for Microsoft’s database platform. While the installation process differs from Windows, the underlying database technology delivers the same reliability, performance, and security features.
Benefits of SQL Server on Fedora
- Cost efficiency compared to Windows server licensing
- Integration with existing Linux infrastructure and tools
- Consistent database experience across heterogeneous environments
- Access to enterprise-grade database features
- Compatibility with existing SQL Server-based applications
System Requirements for SQL Server on Fedora 42
Before beginning the installation process, ensure your Fedora 42 system meets the minimum hardware and software requirements for running Microsoft SQL Server effectively:
- Processor: x64-compatible processor, minimum 2 GHz clock speed, recommended 4 cores or more for production workloads
- Memory: Minimum 2GB RAM, recommended 4GB or more for optimal performance
- Storage: Minimum 6GB available disk space, with additional space needed for databases
- File System: XFS or EXT4 file system (XFS preferred for production workloads)
- System Access: Root or sudo privileges required for installation
For enterprise deployment scenarios, consider scaling these requirements upward, particularly memory and processor cores, to accommodate your expected workload. SQL Server’s performance directly correlates with available system resources, especially RAM and fast storage subsystems.
Preparing Your Fedora 42 Environment
Proper preparation of your Fedora system ensures a smooth SQL Server installation process. The following steps help establish the foundation for a successful deployment:
1. Update your Fedora system:
sudo dnf update -y
2. Install essential development tools and dependencies:
sudo dnf install -y curl unixODBC-devel
3. Configure system limits for SQL Server operation by creating a new file in the /etc/security/limits.d/
directory:
sudo nano /etc/security/limits.d/mssql.conf
4. Add the following lines to the file:
mssql soft nofile 65536
mssql hard nofile 65536
mssql soft nproc 4096
mssql hard nproc 4096
These system preparations ensure your Fedora environment has all necessary prerequisites and optimal configuration for SQL Server’s operation. Taking time with these preparatory steps helps avoid common issues during installation and post-installation operations.
Installing Microsoft SQL Server Repository
SQL Server installation begins with configuring the Microsoft repository on your Fedora system. This repository contains the necessary packages and dependencies for successful deployment.
1. Add Microsoft’s SQL Server repository to your system. Since Fedora 42 is based on the same package management system as RHEL/CentOS, we’ll use the RHEL repository configuration:
sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/9/mssql-server-2022.repo
2. Install the repository key:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
3. Update your package manager’s cache:
sudo dnf makecache
The repository configuration enables your Fedora system to access Microsoft’s package repositories, providing access to SQL Server packages and related tools. If you encounter any issues with repository access, verify your network connectivity and ensure DNS resolution functions correctly.
Installing SQL Server Database Engine
With the repository properly configured, proceed to install the SQL Server database engine on your Fedora 42 system:
1. Install the SQL Server package:
sudo dnf install -y mssql-server
This command downloads and installs the core SQL Server database engine. The installation process may take several minutes depending on your internet connection speed and system performance.
2. Initiate the SQL Server setup process:
sudo /opt/mssql/bin/mssql-conf setup
3. Follow the interactive prompts to:
- Accept the license agreement
- Select your SQL Server edition (Developer, Express, Standard, Enterprise, or Evaluation)
- Set the SA (System Administrator) password
- Confirm your settings
The SA password must comply with SQL Server’s complexity requirements: at least 8 characters long, containing characters from three of the following categories: uppercase letters, lowercase letters, base-10 digits, and symbols.
After completing these steps, the SQL Server service will start automatically. The installation process creates necessary directories, configures initial databases, and sets up the service for automatic startup on system boot.
Post-Installation Configuration
After successful installation, additional configuration steps optimize your SQL Server deployment for your specific requirements:
1. Verify SQL Server service status:
systemctl status mssql-server
2. Configure SQL Server memory limits appropriate for your system:
sudo /opt/mssql/bin/mssql-conf set memory.memorylimitmb 2048
Adjust the value based on your system’s available memory, leaving enough for the operating system and other services.
3. Set default data directory if you want to store database files in a custom location:
sudo /opt/mssql/bin/mssql-conf set filelocation.defaultdatadir /path/to/data/directory
4. Configure default log directory:
sudo /opt/mssql/bin/mssql-conf set filelocation.defaultlogdir /path/to/log/directory
5. Apply configuration changes by restarting the service:
sudo systemctl restart mssql-server
These configuration adjustments help tailor SQL Server to your specific environment and requirements. The mssql-conf tool provides a unified interface for managing most SQL Server configuration parameters on Linux systems.
Installing SQL Server Command-Line Tools
To effectively manage your SQL Server instance, install the command-line tools that enable database administration and querying:
1. Add the tools repository:
sudo curl -o /etc/yum.repos.d/mssql-tools.repo https://packages.microsoft.com/config/rhel/9/prod.repo
2. Install SQL Server tools:
sudo dnf install -y mssql-tools unixODBC-devel
3. Add SQL tools to your PATH for easier access:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
With these tools installed, you can use sqlcmd and bcp utilities to interact with your SQL Server instance from the command line. These tools function identically to their Windows counterparts, making cross-platform administration consistent and familiar.
Starting and Managing SQL Server Services
Understanding how to manage the SQL Server service on Fedora is crucial for day-to-day administration:
1. Start the SQL Server service:
sudo systemctl start mssql-server
2. Stop the service:
sudo systemctl stop mssql-server
3. Restart the service (required after some configuration changes):
sudo systemctl restart mssql-server
4. Enable automatic startup at system boot:
sudo systemctl enable mssql-server
5. Check service status and health:
sudo systemctl status mssql-server
6. View SQL Server logs:
sudo tail -f /var/opt/mssql/log/errorlog
Efficient service management ensures your SQL Server remains available and properly configured. Systemd integration provides standard Linux service control mechanisms that work consistently across modern Linux distributions.
Configuring Firewall for SQL Server
To allow remote connections to your SQL Server instance, configure the firewall to permit traffic on SQL Server’s ports:
1. Open the default SQL Server port (1433) using firewalld:
sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
2. If you’re using SQL Server Browser service, open UDP port 1434:
sudo firewall-cmd --zone=public --add-port=1434/udp --permanent
3. Reload the firewall configuration:
sudo firewall-cmd --reload
4. Verify the firewall configuration:
sudo firewall-cmd --list-all
These firewall configurations permit network traffic to reach your SQL Server instance, enabling remote connections from client applications and management tools. Consider implementing additional network security measures for production environments, such as restricting access to specific IP ranges.
Verifying Your SQL Server Installation
After installation and configuration, verify that your SQL Server instance is functioning correctly:
1. Connect to SQL Server using sqlcmd:
sqlcmd -S localhost -U SA -P 'YourStrongPassword'
2. Create a test database:
CREATE DATABASE TestDB;
GO
3. Switch to the new database:
USE TestDB;
GO
4. Create a test table:
CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT);
GO
5. Insert test data:
INSERT INTO Inventory VALUES (1, 'banana', 150);
INSERT INTO Inventory VALUES (2, 'orange', 154);
GO
6. Query the data:
SELECT * FROM Inventory;
GO
7. Exit sqlcmd:
EXIT
This verification process confirms that your SQL Server instance can create databases, tables, and execute queries correctly. A successful verification indicates your installation is operational and ready for production use.
Installing PHP Extensions for SQL Server
If you need to connect to SQL Server from PHP applications, install the necessary drivers and extensions:
1. Install Microsoft ODBC driver and required PHP packages:
curl https://packages.microsoft.com/config/rhel/9/prod.repo | sudo tee /etc/yum.repos.d/mssql-release.repo
sudo dnf update
sudo dnf install msodbcsql18 unixODBC-devel php-pear php-devel
2. Install PECL packages for SQL Server connectivity:
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
3. Enable the PHP extensions:
sudo bash -c "echo 'extension=sqlsrv.so' > /etc/php.d/20-sqlsrv.ini"
sudo bash -c "echo 'extension=pdo_sqlsrv.so' > /etc/php.d/30-pdo_sqlsrv.ini"
4. Restart web server and PHP services:
sudo systemctl restart httpd
sudo systemctl restart php-fpm
These extensions enable PHP applications to connect to SQL Server using either the SQLSRV or PDO_SQLSRV interfaces. Both connection methods support all SQL Server features and provide optimal performance for PHP applications requiring database connectivity.
Database Administration Basics
Once installed, managing your SQL Server instance involves several routine tasks:
1. Creating databases:
CREATE DATABASE ProductionDB;
GO
2. Creating users and granting permissions:
CREATE LOGIN AppUser WITH PASSWORD = 'StrongPassword123';
GO
USE ProductionDB;
GO
CREATE USER AppUser FOR LOGIN AppUser;
GO
GRANT SELECT, INSERT, UPDATE, DELETE ON SCHEMA::dbo TO AppUser;
GO
3. Performing backups:
BACKUP DATABASE ProductionDB TO DISK = '/var/opt/mssql/backup/ProductionDB.bak' WITH FORMAT;
GO
4. Restoring databases:
RESTORE DATABASE ProductionDB FROM DISK = '/var/opt/mssql/backup/ProductionDB.bak' WITH REPLACE;
GO
5. Setting up scheduled maintenance tasks using cron jobs to execute SQL Server Agent jobs or direct T-SQL commands.
These basic administration tasks help maintain your database environment, ensuring data integrity, security, and availability. As with Windows-based SQL Server, all standard T-SQL commands function identically on Linux.
Performance Optimization for Fedora
Optimize SQL Server performance on Fedora 42 with these system-level adjustments:
1. Configure swap space appropriate for your memory configuration:
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1G count=8
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
2. Tune the I/O scheduler for SSD or high-performance storage:
echo 'none' | sudo tee /sys/block/sda/queue/scheduler
3. Adjust transparent huge pages behavior:
echo 'never' | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
4. Optimize SQL Server memory settings:
sudo /opt/mssql/bin/mssql-conf set memory.memorylimitmb 4096
5. Consider enabling trace flags for specific performance optimizations:
sudo /opt/mssql/bin/mssql-conf set traceflag 1117 on
sudo /opt/mssql/bin/mssql-conf set traceflag 1118 on
These performance adjustments help SQL Server operate optimally on Fedora Linux, addressing platform-specific considerations not present in Windows environments. Monitor your system’s performance after making these changes to validate their effectiveness for your specific workload.
Handling Fedora Version Upgrades
When upgrading to a new Fedora version, take precautions to ensure SQL Server continues to function correctly:
1. Back up all databases before beginning the upgrade process:
BACKUP DATABASE [master] TO DISK = '/var/opt/mssql/backup/master_before_upgrade.bak' WITH FORMAT;
BACKUP DATABASE [msdb] TO DISK = '/var/opt/mssql/backup/msdb_before_upgrade.bak' WITH FORMAT;
-- Repeat for all user databases
2. Document your SQL Server configuration:
sudo /opt/mssql/bin/mssql-conf list
3. After Fedora system upgrade, reinstall SQL Server extensions if necessary:
sudo pecl uninstall sqlsrv
sudo pecl uninstall pdo_sqlsrv
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
4. Restart services:
sudo systemctl restart httpd
sudo systemctl restart php-fpm
sudo systemctl restart mssql-server
5. Verify SQL Server functionality by connecting and performing basic operations.
These precautions minimize disruption during Fedora version upgrades, ensuring your database environment remains functional throughout the process.
Security Best Practices
Implement these security measures to protect your SQL Server installation:
1. Use a strong SA password and consider renaming the SA account in production environments.
2. Implement firewall rules to restrict access to SQL Server ports:
sudo firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="1433" accept' --permanent
sudo firewall-cmd --reload
3. Enable Transport Layer Security (TLS) encryption:
sudo /opt/mssql/bin/mssql-conf set network.tlscert /path/to/certificate.pem
sudo /opt/mssql/bin/mssql-conf set network.tlskey /path/to/private.key
sudo /opt/mssql/bin/mssql-conf set network.tlsprotocols 1.2
sudo systemctl restart mssql-server
4. Apply the principle of least privilege for database users and applications.
5. Keep SQL Server updated with the latest security patches:
sudo dnf check-update mssql-server
sudo dnf update mssql-server
These security practices help protect your SQL Server installation from unauthorized access and potential vulnerabilities, establishing a secure foundation for your database environment.
Troubleshooting Common Issues
When encountering problems with SQL Server on Fedora, these troubleshooting approaches can help identify and resolve issues:
1. Check system logs for errors:
sudo journalctl -u mssql-server --since today
2. Review SQL Server error logs:
sudo cat /var/opt/mssql/log/errorlog
3. Verify service status:
systemctl status mssql-server
4. Check for port conflicts:
sudo ss -tulpn | grep 1433
5. Test network connectivity for remote connection issues:
telnet remote_server 1433
6. Verify permissions on SQL Server directories:
ls -la /var/opt/mssql/
7. Monitor resource usage for performance bottlenecks:
top -u mssql
When troubleshooting, approach methodically by checking logs, service status, connectivity, and resource availability. Most issues can be resolved through careful examination of these diagnostic sources.
Advanced Configuration Options
For more specialized deployments, consider these advanced configuration options:
1. Configure Always On Availability Groups for high availability:
sudo /opt/mssql/bin/mssql-conf set hadr.hadrenabled 1
sudo systemctl restart mssql-server
2. Set up SQL Server Agent for job scheduling:
sudo /opt/mssql/bin/mssql-conf set sqlagent.enabled true
sudo systemctl restart mssql-server
3. Configure Database Mail for automated notifications:
sudo /opt/mssql/bin/mssql-conf set dbmail.defaultprofile "Admin Profile"
sudo systemctl restart mssql-server
4. Enable Full-Text Search capabilities:
sudo dnf install -y mssql-server-fts
sudo systemctl restart mssql-server
These advanced configurations extend SQL Server’s capabilities on Fedora, enabling enterprise-level features comparable to those available on Windows platforms.
Congratulations! You have successfully installed Microsoft SQL. Thanks for using this tutorial for installing the Microsoft SQL Server on your Fedora 42 Linux system. For additional or useful information, we recommend you check the official Microsoft website.