Centos SQL Server保姆级安装教程

0、安装环境

系统版本:CentOS Linux release 7.9.2009

SQL Server版本:mssql-server2019

一、安装mssql-server2019

1.1 下载微软官方的SQL Server2019源到本地

curl https://packages.microsoft.com/config/rhel/7/mssql-server-2019.repo > /etc/yum.repos.d/mssql-server.repo

image-20230403134027636

1.2 镜像下载完成后,执行以下命令安装mssql-server2019(SQL Server软件包)

yum install -y mssql-server

1.3 程序包安装完成后,请运行 mssql-conf setup 命令选择安装版本并按提示进行安装,具体操作如下:

/opt/mssql/bin/mssql-conf setup

1)选择所要安装的版本,输入数字2(本教程安装开发版),各个版本详细介绍见官网介绍

image-20230403134240367

2)然后在出现询问是否接受许可条款时,输入Yes,回车继续下一步。

image-20230403134339529

3)系统会要求用户要求输入sa用户密码(密码长度八位以上,且密码必须包含数字、字母和特殊字符),注意在输入密码的时候,窗口上是不显示任何字符的,所以输入完之后,直接回车,然后再输入一遍,回车确认。

image-20230403134418485

4)配置完成后,请验证服务是否正在运行

systemctl status mssql-server

image-20230403134501555

二、安装mssql工具包和UnixODBC开发人员软件包

2.1 下载官方软件包源

curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo

2.2 安装

yum install -y mssql-tools unixODBC-devel

2.3 添加PATH环境

echo 'export PATH=$PATH:/opt/mssql-tools/bin' >> /etc/profile

2.4 重新加载环境变量

source /etc/profile

三、连接SQL Server进行测试

3.1 利用sqlcmd命令进行本地连接

sqlcmd -S localhost -U sa -p

输入之前设置的sa密码,登录成功后,如下图所示

  • -S:名称
  • -U:用户名
  • -p:密码

image-20230403134749687

3.2 利用DBeaver配置远程连接(在本地机器上)

要允许远程连接,请在 Centos 上打开防火墙上的 SQL Server 端口。 默认的 SQL Server 端口为 TCP 1433。 如果对防火墙使用 FirewallD,可以使用以下命令:

firewall-cmd --zone=public --add-port=1433/tcp --permanent
firewall-cmd --reload
# firewall-cmd未启用不需要做此设置

或者直接关闭防火墙

systemctl stop firewalld

其他防火墙常用命令如下:

命令说明
systemctl status firewalld查看防火墙状态
systemctl stop firewalld暂时关闭防火墙
systemctl disable firewalld永久关闭防火墙
systemctl start firewalld开启防火墙
firewall-cmd --zone=public --add-port=8080/tcp --permanent开放指定端口
firewall-cmd --zone=public --remove-port=8080/tcp --permanent关闭指定端口
firewall-cmd --reload立即生效
firewall-cmd --zone=public --list-ports查看所有开放的端口

1)新建连接

image-20230331103847805

2)选择 SQL Server

image-20230331103619884

3)设置Host、用户名和密码并测试连接

image-20230331103715647

连接成功,如下图所示

image-20230331103743663

四、测试环境快速安装

安装前提条件:需提前安装virtualbox和vagrant,具体步骤参考:https://blog.youkuaiyun.com/yiluohan0307/article/details/129459487

4.1 创建Centos集群安装的VagrantFile文件

创建vagrantfile所在文件夹sql_server,并创建文件 Vagrantfile 和 setup.sh ,其中VagrantFile是vagrant的启动配置文件,setup.sh是SQL Server安装文件。

mkdir /vagrant_centos_cluster
touch VagrantFile
touch setup.sh

编辑VagrantFile文件, 内容如下:

# -*- mode: ruby -*-
# vi: set ft=ruby :

$init_script = <<-SCRIPT
#!/bin/bash

echo "install init"
# Set SSH to allow password login
sed -i 's@^PasswordAuthentication no@PasswordAuthentication yes@g' /etc/ssh/sshd_config
sed -i 's@^#PubkeyAuthentication yes@PubkeyAuthentication yes@g' /etc/ssh/sshd_config
systemctl restart sshd.service

# Install CentOS basic software
yum install -y -q net-tools vim-enhanced sshpass expect wget

# Configure the vagrant user to have root privileges
sed -i "/## Same thing without a password/ivagrant   ALL=(ALL)     NOPASSWD:ALL" /etc/sudoers

# Add ip address to hosts file
sed -i '/^127.0.1.1/'d /etc/hosts
echo "192.168.10.101  sqlserver" >> /etc/hosts

# Modify DNS
sed -i "s@^nameserver.*@nameserver 114.114.114.114@" /etc/resolv.conf
SCRIPT

# Configure SQL Server password, default:123456yY
sql_server_password = "123456yY"

# Configure vm settings
boxes = [
    {
      :name => "sqlserver", :eth1 => "192.168.10.101", :mem => "4096", :cpu => "3"
    }
]

Vagrant.configure(2) do |config|
  config.vm.box = "centos/7"
  config.vm.box_version = "1804.02"
  boxes.each do |opts|
    config.vm.define opts[:name] do |config|
      config.vm.hostname = opts[:name]
      config.ssh.insert_key = false
      config.vm.provider "virtualbox" do |v|
        v.customize ["modifyvm", :id, "--name", opts[:name]]
        v.customize ["modifyvm", :id, "--memory", opts[:mem]]
        v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
      end
      config.vm.network "private_network", ip: opts[:eth1]
    end
  end

  config.vm.provision "shell", inline: $init_script
  config.vm.provision "shell", path: "setup.sh", args: sql_server_password

end

编辑setup.sh文件, 内容如下:

#!/bin/bash
#set -x

SQL_SERVER_PASSWORD=$1

# 默认密码:123456yY
DEFAULT_SQL_SERVER_PASSWORD=123456yY

SQL_SERVER_PASSWORD=${SQL_SERVER_PASSWORD:-$DEFAULT_SQL_SERVER_PASSWORD}

install_sql_server() {

    # 下载微软官方的SQL Server2019源到本地
    if [ ! -f /etc/yum.repos.d/mssql-server.repo ];then
        curl https://packages.microsoft.com/config/rhel/7/mssql-server-2019.repo > /etc/yum.repos.d/mssql-server.repo
    fi
    # 安装 SQL Server 软件包
    yum install -y mssql-server

    # 安装指定版本(2.Developer)并设置密码
    expect -c "
        spawn /opt/mssql/bin/mssql-conf setup
        expect {
            \"Enter your edition*\" { send \"2\r\"; exp_continue}
            \"Do you accept the license terms*\" { send \"yes\r\" ; exp_continue}
            \"Enter the SQL Server*\" { send \"${SQL_SERVER_PASSWORD}\r\"; exp_continue}
            \"Confirm the SQL Server*\" { send \"${SQL_SERVER_PASSWORD}\r\" ; exp_continue}
        }";

    # 启动并设置开机自启
    systemctl start mssql-server
    systemctl enable mssql-server

    # 安装SQL Server命令行工具
    if [ ! -f /etc/yum.repos.d/msprod.repo ];then
        curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo
    fi
    expect -c "
        spawn yum install -y mssql-tools unixODBC-devel
        expect {
            \"Do you accept the license terms*\" { send \"YES\r\"; exp_continue}
            \"Do you accept the license terms*\" { send \"YES\r\"; exp_continue}
        }";

    # 添加并更新环境变量
    echo 'export PATH=$PATH:/opt/mssql-tools/bin' >> /etc/profile
    source /etc/profile

}

install_sql_server

4.2 启动虚拟机

vagrant会自动下载 box 并安装 shell 脚本内容进行安装配置。

vagrant up

image-20230403141637823

4.3 登录,验证配置是否正确

正常启动后,我们就可以使用以下命令直接登录到虚拟机或者使用SecureCRT、 Tabby 等终端工具登录查看。

vagrant ssh sqlserver

参考资料

https://zhuanlan.zhihu.com/p/570024665?utm_id=0

https://blog.youkuaiyun.com/leonnew/article/details/126662980

https://www.cnblogs.com/YZFHKMS-X/p/15060850.html

https://blog.youkuaiyun.com/weixin_44146294/article/details/127360167

https://www.cnblogs.com/ajunyu/p/13297449.html

https://www.ngui.cc/el/2235085.html?action=onClick

### CentOS 7 上部署 Nextcloud 的详细教程 #### 准备工作 为了成功部署 Nextcloud,在开始之前需确认服务器环境满足基本条件。服务器应运行 Linux 操作系统,推荐使用稳定版本的 CentOS 7。对于初次尝试者来说,建议先在一个本地虚拟机环境中完成测试后再迁移到生产环境。 #### 安装 LNMP 环境 由于本指南专注于基于 LNMP (Linux, Nginx, MariaDB/MySQL, PHP) 架构下的 Nextcloud 部署方法[^1],因此首先需要搭建好相应的 Web 服务组件: - **Nginx**: 可通过 yum 或 epel-release 来安装最新稳定版; - **MariaDB/MySQL**: 同样可以从官方源获取并配置数据库引擎; - **PHP**: 至少要包含 php-fpm 和其他必要的扩展模块如 gd、mbstring 等。 ```bash sudo yum install nginx mariadb-server php php-fpm php-gd php-mbstring... ``` #### 下载与验证 Nextcloud 文件包 前往官方网站下载适合当前系统的 Nextcloud 压缩文件,并对其进行完整性校验以确保文件未被篡改或损坏[^2]: ```bash cd ~/ wget https://download.nextcloud.com/server/releases/latest.zip wget https://download.nextcloud.com/server/releases/latest.zip.sha256 sha256sum -c latest.zip.sha256 < latest.zip ``` 如果校验结果显示 OK,则说明文件完好无损,可继续下一步骤;反之则应当重新下载直至获得正确的压缩包为止。 #### 数据库准备 启动 MySQL/MariaDB 并创建一个新的数据库用于存储 Nextcloud 应用数据以及相应权限账户[^3]: ```sql CREATE DATABASE nextclouddb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; GRANT ALL PRIVILEGES ON nextclouddb.* TO 'nextclouduser'@'localhost' IDENTIFIED BY 'yourpassword'; FLUSH PRIVILEGES; EXIT; ``` 请注意替换 `nextclouddb`、`nextclouduser` 和 `'yourpassword'` 为实际使用的名称和密码组合。 #### 解压上传至 webroot 目录 将解压后的 Nextcloud 文件夹放置于 Nginx 所指向的根目录下,默认路径通常位于 `/var/www/html/` 中: ```bash unzip ~/latest.zip -d /var/www/html/ chown -R apache:apache /var/www/html/nextcloud chmod -R 755 /var/www/html/nextcloud ``` 这里假设 Apache 是作为默认用户身份运行着 FPM 进程,如果不是的话请调整 chown 参数中的用户名部分。 #### 修改 Nginx 配置文件 编辑站点对应的 .conf 文件加入如下内容以便正确解析请求转发给 FastCGI 处理程序: ```nginx server { listen 80; server_name yourdomain.com; root /var/www/html/nextcloud/; index index.php; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } ``` 记得重启 Nginx 让更改生效。 #### 浏览器访问初始化设置页面 打开浏览器输入 IP 地址或者域名进入图形化向导界面按照提示填写管理员账号信息以及其他必要参数即可完成整个过程。 ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yiluohan0307

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值