当前位置:   article > 正文

搭建discuz论坛(lvs+nginx+http+mysql+nfs)8台服务器

搭建discuz论坛(lvs+nginx+http+mysql+nfs)8台服务器

搭建discuz论坛(lvs+nginx+http+mysql+nfs)

一、IP规划

服务名IP地址服务
LVS1192.168.100.110keepalived+ipvsadm
LVS2192.168.100.111keepalived+ipvsadm
nginx1192.168.100.113nginx
nginx2192.168.100.114nginx
nfs192.168.100.116nfs-util
web1192.168.100.118httpd+php+nfs-util
web2192.168.100.119httpd+php+nfs-util
mysql192.168.100.121mysql

虚拟IP

服务名IP地址服务
虚拟ip192.168.100.100nginx+keepalived

二、配置

1.LVS1

​ 关闭防护墙,selinux

# 关闭防火墙
systemctl stop firewalld

# 关闭selinux
setenforce 0
  • 1
  • 2
  • 3
  • 4
  • 5

​ 设置ip:192.168.100.110

# 编辑网卡信息
vi /etc/sysconfig/network-scripts/ifcfg-ens33

# 修改
BOOTPROTO=static
ONBOOT=yes

# 写入
IPADDR=192.168.100.110
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ 下载keepalived和ipvsadm

yum -y install keepalived ipvsadm
  • 1

​ 备份默认配置文件

cp -p /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
  • 1

​ 删除原有文件,创建新内容

# 删除原有文件
rm -rf /etc/keepalived/keepalived.conf 

# 创建新文件
vi /etc/keepalived/keepalived.conf 
  • 1
  • 2
  • 3
  • 4
  • 5

​ 添加以下内容

! Configuration File for keepalived

# 配置双机热备(主)
lobal_defs {
   router_id 1
}
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 1
    priority 120
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        192.168.100.100
    }
}

# 虚拟服务器ip及mysql地址
virtual_server 192.168.100.100 80 {
        delay_loop 15
        lb_algo rr
        lb_kind DR
        protocol TCP
        real_server 192.168.100.113 80 {
        weight 1
        TCP_CHECK {
                connect_port 80
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 4
                }
        }
        real_server 192.168.100.114 80 {
        weight 1
        TCP_CHECK {
                connect_port 80
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 4
                }
        }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

​ 启动keepalived

systemctl start keepalived
  • 1

​ 服务模块

# 加载系统内核的服务模块
modprobe ip_vs

# 查看运行状态
lsmod | grep ip_vs
  • 1
  • 2
  • 3
  • 4
  • 5

​ 下载net网络工具

yum -y install net-tools
  • 1

​ 查看网卡信息

# 停用物理网卡
ifconfig ens33 down

# 启动物理网卡(如在连接工具上,需到虚拟机上启动)
ifconfig ens33 up

# 查看网卡信息(在ens33网卡下是否有ip:192.168.100.100)
ip a

# 查看LVS-DR群集策略规则
ipvsadm -ln
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ LVS-DR群集策略

# 查看策略
ipvsadm -ln
  • 1
  • 2
2.LVS2

​ 关闭防护墙,selinux

# 关闭防火墙
systemctl stop firewalld

# 关闭selinux
setenforce 0
  • 1
  • 2
  • 3
  • 4
  • 5

​ 设置ip:192.168.100.111

# 编辑网卡信息
vi /etc/sysconfig/network-scripts/ifcfg-ens33

# 修改
BOOTPROTO=static
ONBOOT=yes

# 写入
IPADDR=192.168.100.111
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ 下载keepalived和ipvsadm

yum -y install keepalived ipvsadm
  • 1

​ 备份默认配置文件

cp -p /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
  • 1

​ 删除原有文件,创建新内容

# 删除原有文件
rm -rf /etc/keepalived/keepalived.conf 

# 创建新文件
vi /etc/keepalived/keepalived.conf 
  • 1
  • 2
  • 3
  • 4
  • 5

​ 添加以下内容

! Configuration File for keepalived

# 配置双机热备(备)
lobal_defs {
   router_id 2
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 1
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        192.168.100.100
    }
}

# 虚拟服务器ip及mysql地址
virtual_server 192.168.100.100 80 {
        delay_loop 15
        lb_algo rr
        lb_kind DR
        protocol TCP
        real_server 192.168.100.113 80 {
        weight 1
        TCP_CHECK {
                connect_port 80
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 4
                }
        }
        real_server 192.168.100.114 80 {
        weight 1
        TCP_CHECK {
                connect_port 80
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 4
                }
        }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

​ 启动keepalived

systemctl start keepalived
  • 1

​ 服务模块

# 加载系统内核的服务模块
modprobe ip_vs

# 查看运行状态
lsmod | grep ip_vs
  • 1
  • 2
  • 3
  • 4
  • 5

​ 下载net网络工具

yum -y install net-tools
  • 1

​ 查看网卡信息

# 停用物理网卡
ifconfig ens33 down

# 启动物理网卡(如在连接工具上,需到虚拟机上启动)
ifconfig ens33 up

# 查看网卡信息(在ens33网卡下是否有ip:192.168.100.100)
ip a

# 查看LVS-DR群集策略规则
ipvsadm -ln
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ LVS-DR群集策略

# 查看策略
ipvsadm -ln
  • 1
  • 2
3.nginx1

关闭防火墙,selinux

# 关闭防火墙
systemctl stop firewalld

# 关闭selinux
setenforce 0
  • 1
  • 2
  • 3
  • 4
  • 5

​ 设置ip:192.168.100.113

# 编辑网卡信息
vi /etc/sysconfig/network-scripts/ifcfg-ens33

# 修改
BOOTPROTO=static
ONBOOT=yes

# 写入
IPADDR=192.168.100.113
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ 下载nginx,keepalived环境

# 配置nginx下载源
cat >> /etc/yum.repos.d/nginx.repo << EOF
[nginx-stable]
name="nginx stable repo"
baseurl=http://nginx.org/packages/centos/$releasever/$basearch
enabled=1
gpgcheck=0
EOF

# 下载环境
yum -y install nginx keepalived
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ 配置nginx

[root@localhost ~]# vi /etc/nginx/nginx.conf
# 在http {}内添加
    upstream apache{
        server 192.168.100.118:80;
        server 192.168.100.119:80;
    }

[root@localhost ~]# vi /etc/nginx/conf.d/default.conf
# 在location / {}内添加
        proxy_pass http://apache;
        proxy_redirect default;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;

# 重启
[root@localhost ~]# systemctl restart nginx
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

启动nginx

systemctl start nginx
  • 1

​ 虚拟网卡

# 添加虚拟网卡(回环地址)
cat >> /etc/sysconfig/network-scripts/ifcfg-lo:0  << EOF
DEVICE=lo:0
IPADDR=192.168.100.100
NETMASK=255.255.255.255
ONBOOT=yes
EOF

# 重启网络
systemctl restart network

# 查看是否有虚拟ip
ip a
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

​ 写入路由指向

# 下载网络工具
yum -y install net-tools

# 添加路由信息
route add -host 192.168.100.100 dev lo:0
  • 1
  • 2
  • 3
  • 4
  • 5

​ 调整/proc内核参数,关闭ARP响应

cat >> /etc/sysctl.conf << EOF
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
EOF

sysctl -p
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
4.nginx2

​ 关闭防火墙,selinux

# 关闭防火墙
systemctl stop firewalld

# 关闭selinux
setenforce 0
  • 1
  • 2
  • 3
  • 4
  • 5

​ 设置ip:192.168.100.114

# 编辑网卡信息
vi /etc/sysconfig/network-scripts/ifcfg-ens33

# 修改
BOOTPROTO=static
ONBOOT=yes

# 写入
IPADDR=192.168.100.114
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ 下载nginx,keepalived环境

# 配置nginx下载源
cat >> /etc/yum.repos.d/nginx.repo << EOF
[nginx-stable]
name="nginx stable repo"
baseurl=http://nginx.org/packages/centos/$releasever/$basearch
enabled=1
gpgcheck=0
EOF

# 下载环境
yum -y install nginx keepalived
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ 配置nginx

[root@localhost ~]# vi /etc/nginx/nginx.conf
# 在http {}内添加
    upstream apache{
        server 192.168.100.118:80;
        server 192.168.100.119:80;
    }

[root@localhost ~]# vi /etc/nginx/conf.d/default.conf
# 在location / {}内添加
        proxy_pass http://apache;
        proxy_redirect default;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;

# 重启
[root@localhost ~]# systemctl restart nginx
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

​ 启动nginx

systemctl start nginx
  • 1

​ 写入路由指向

# 下载网络工具
yum -y install net-tools

# 添加路由信息
route add -host 192.168.100.100 dev lo:0
  • 1
  • 2
  • 3
  • 4
  • 5

​ 调整/proc内核参数,关闭ARP响应

cat >> /etc/sysctl.conf << EOF
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
EOF

sysctl -p
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
5.nfs

​ 关闭防火墙,selinux

# 关闭防火墙
systemctl stop firewalld

# 关闭selinux
setenforce 0
  • 1
  • 2
  • 3
  • 4
  • 5

​ 设置ip:192.168.100.116

# 编辑网卡信息
vi /etc/sysconfig/network-scripts/ifcfg-ens33

# 修改
BOOTPROTO=static
ONBOOT=yes

# 写入
IPADDR=192.168.100.116
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ 创建nfs目录

# 创建共享目录
mkdir /luntan
  • 1
  • 2

​ 下载nfs环境

yum -y install nfs-utils*
  • 1

​ 上传论坛包到/opt

# 下载unzip解压软件
yum -y install unzip

# 解压论坛软件
unzip /opt/Discuz_X3.2_SC_UTF8.zip -d /luntan

# 给予论坛文件权限
chmod -R 757 /luntan/upload/{config,data,uc_*}

cp -rf /luntan/upload/* /luntan/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

​ 配置进程

# 启动nfs进程守护
systemctl start rpcbind
systemctl start nfs
  • 1
  • 2
  • 3

​ 共享

# 编辑nfs共享配置文件
vi /etc/exports

# 写入以下内容
/luntan 192.168.100.118(rw,sync,no_root_squash) 192.168.100.119(rw,sync,no_root_squash)

# 刷新nfs文件权限
exportfs -r
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
6.web1

​ 关闭防火墙,selinux

# 关闭防火墙
systemctl stop firewalld

# 关闭selinux
setenforce 0
  • 1
  • 2
  • 3
  • 4
  • 5

​ 设置ip:192.168.100.118

# 编辑网卡信息
vi /etc/sysconfig/network-scripts/ifcfg-ens33

# 修改
BOOTPROTO=static
ONBOOT=yes

# 写入
IPADDR=192.168.100.118
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ 安装环境

# 安装httpd,php,nfs环境
yum -y install httpd php php-mysql nfs-utils*
  • 1
  • 2

​ 挂载并启动

# 将nfs共享目录挂载到apache下
mount 192.168.100.116:/luntan /var/www/html

# 启动服务
systemctl start httpd
  • 1
  • 2
  • 3
  • 4
  • 5
7.web2

​ 关闭防火墙,selinux

# 关闭防火墙
systemctl stop firewalld

# 关闭selinux
setenforce 0
  • 1
  • 2
  • 3
  • 4
  • 5

​ 设置ip:192.168.100.119

# 编辑网卡信息
vi /etc/sysconfig/network-scripts/ifcfg-ens33

# 修改
BOOTPROTO=static
ONBOOT=yes

# 写入
IPADDR=192.168.100.119
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ 安装环境

# 安装httpd,php,nfs环境
yum -y install httpd php php-mysql nfs-utils*
  • 1
  • 2

​ 挂载并启动

# 将nfs共享目录挂载到apache下
mount 192.168.100.116:/luntan /var/www/html

# 启动服务
systemctl start httpd
  • 1
  • 2
  • 3
  • 4
  • 5
8.mysql

​ 关闭防护墙,selinux

# 关闭防火墙
systemctl stop firewalld

# 关闭selinux
setenforce 0
  • 1
  • 2
  • 3
  • 4
  • 5

​ 设置ip:192.168.100.121

# 编辑网卡信息
vi /etc/sysconfig/network-scripts/ifcfg-ens33

# 修改
BOOTPROTO=static
ONBOOT=yes

# 写入
IPADDR=192.168.100.121
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

​ 下载mariadb

yum -y install mariadb mariadb-server
  • 1

​ 修改完成重启服务

# 重启服务
systemctl restart mariadb

# 配置mysql密码,123456
mysql_secure_installation 
  • 1
  • 2
  • 3
  • 4
  • 5

​ 授权

# 进入mysql
mysql -uroot -p123456

# 授权
grant all privileges on *.* to 'root'@'%' identified by '123456';

# 刷新权限
flush privileges;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

三、安装

​ 进入浏览器,输入http://192.168.100.100/upload,开始安装

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号