在Debian上配置SQL Server涉及多个步骤,包括安装必要的软件包、配置数据库、设置高可用性等。以下是一个基本的指南,帮助你在Debian上配置SQL Server:
sudo apt update && sudo apt upgrade
sudo apt install -y curl gnupg apt-transport-https
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /usr/share/keyrings/microsoft-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/debian/12/prod/ stable main" | sudo tee /etc/apt/sources.list.d/mssql-server.list
sudo apt update
sudo apt install -y mssql-server
在安装过程中,系统会提示你接受最终用户许可协议(EULA),请阅读并接受协议以继续。
sudo /opt/mssql/bin/mssql-conf setup
在配置过程中,你需要设置SA(系统管理员)用户的密码。请记住这个密码,因为将在连接到SQL Server时使用它。
sudo apt install -y mssql-tools
使用 sqlcmd
工具连接到SQL Server:
sqlcmd -S localhost -U SA -P YourPassword
请将 YourPassword
替换为在配置时为SA用户设置的密码。
SQL Server在Linux上的高可用性通常通过SQL Server Always On可用性组来实现。以下是一个基本的步骤:
/etc/sqlserver/sqlservr.exe.config
),并配置共享存储和日志传输。sqlcmd -S YourServerIP -E -Q "CREATE AVAILABILITY GROUP [YourAGName] WITH (ENCRYPTION ON, LOG_ROTATION_ON_TIMEOUT OFF, MAX_LOG_FILES 2, MAX_LOG_MEMBERS 2, MAX_DATA_FILES 1024)"
sqlcmd -S YourServerIP -E -Q "ALTER AVAILABILITY GROUP [YourAGName] ADD DATABASE [YourDatabaseName]"
sqlcmd -S YourServerIP -E -Q "ALTER AVAILABILITY GROUP [YourAGName] SET FAILURE_POLICY AUTO"
sqlcmd -S SecondaryServerIP -E -Q "ALTER AVAILABILITY GROUP [YourAGName] FAILOVER"
根据你的具体需求,你可能需要配置网络接口。Debian 10及更高版本可以使用 netplan
进行网络配置。
sudo nano /etc/netplan/01-netcfg.yaml
例如,配置有线连接:
network:
version: 2
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
sudo netplan apply
sudo apt install firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld
sudo firewall-cmd --zone public --add-port 1433/tcp --permanent
sudo firewall-cmd --reload
sudo apt install iptables
sudo iptables -A INPUT -p tcp --dport 1433 -j ACCEPT
sudo iptables-save /etc/iptables/rules.v4
sudo iptables-restore < /etc/iptables/rules.v4
以上步骤提供了一个基本的框架,但在实际配置过程中,可能需要根据具体需求进行调整。建议参考Microsoft的官方文档以获取更详细的指导。