搭建discuz论坛(lvs+nginx+http+mysql+nfs)
一、IP规划
服务名 | IP地址 | 服务 |
---|---|---|
LVS1 | 192.168.100.110 | keepalived+ipvsadm |
LVS2 | 192.168.100.111 | keepalived+ipvsadm |
nginx1 | 192.168.100.113 | nginx |
nginx2 | 192.168.100.114 | nginx |
nfs | 192.168.100.116 | nfs-util |
web1 | 192.168.100.118 | httpd+php+nfs-util |
web2 | 192.168.100.119 | httpd+php+nfs-util |
mysql | 192.168.100.121 | mysql |
虚拟IP
服务名 | IP地址 | 服务 |
---|---|---|
虚拟ip | 192.168.100.100 | nginx+keepalived |
二、配置
1.LVS1
关闭防护墙,selinux
# 关闭防火墙
systemctl stop firewalld
# 关闭selinux
setenforce 0
设置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
下载keepalived和ipvsadm
yum -y install keepalived ipvsadm
备份默认配置文件
cp -p /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
删除原有文件,创建新内容
# 删除原有文件
rm -rf /etc/keepalived/keepalived.conf
# 创建新文件
vi /etc/keepalived/keepalived.conf
添加以下内容
! 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
}
}
}
启动keepalived
systemctl start keepalived
服务模块
# 加载系统内核的服务模块
modprobe ip_vs
# 查看运行状态
lsmod | grep ip_vs
下载net网络工具
yum -y install net-tools
查看网卡信息
# 停用物理网卡
ifconfig ens33 down
# 启动物理网卡(如在连接工具上,需到虚拟机上启动)
ifconfig ens33 up
# 查看网卡信息(在ens33网卡下是否有ip:192.168.100.100)
ip a
# 查看LVS-DR群集策略规则
ipvsadm -ln
LVS-DR群集策略
# 查看策略
ipvsadm -ln
2.LVS2
关闭防护墙,selinux
# 关闭防火墙
systemctl stop firewalld
# 关闭selinux
setenforce 0
设置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
下载keepalived和ipvsadm
yum -y install keepalived ipvsadm
备份默认配置文件
cp -p /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
删除原有文件,创建新内容
# 删除原有文件
rm -rf /etc/keepalived/keepalived.conf
# 创建新文件
vi /etc/keepalived/keepalived.conf
添加以下内容
! 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
}
}
}
启动keepalived
systemctl start keepalived
服务模块
# 加载系统内核的服务模块
modprobe ip_vs
# 查看运行状态
lsmod | grep ip_vs
下载net网络工具
yum -y install net-tools
查看网卡信息
# 停用物理网卡
ifconfig ens33 down
# 启动物理网卡(如在连接工具上,需到虚拟机上启动)
ifconfig ens33 up
# 查看网卡信息(在ens33网卡下是否有ip:192.168.100.100)
ip a
# 查看LVS-DR群集策略规则
ipvsadm -ln
LVS-DR群集策略
# 查看策略
ipvsadm -ln
3.nginx1
关闭防火墙,selinux
# 关闭防火墙
systemctl stop firewalld
# 关闭selinux
setenforce 0
设置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
下载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
配置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
启动nginx
systemctl start nginx
虚拟网卡
# 添加虚拟网卡(回环地址)
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
写入路由指向
# 下载网络工具
yum -y install net-tools
# 添加路由信息
route add -host 192.168.100.100 dev lo:0
调整/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
4.nginx2
关闭防火墙,selinux
# 关闭防火墙
systemctl stop firewalld
# 关闭selinux
setenforce 0
设置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
下载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
配置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
启动nginx
systemctl start nginx
写入路由指向
# 下载网络工具
yum -y install net-tools
# 添加路由信息
route add -host 192.168.100.100 dev lo:0
调整/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
5.nfs
关闭防火墙,selinux
# 关闭防火墙
systemctl stop firewalld
# 关闭selinux
setenforce 0
设置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
创建nfs目录
# 创建共享目录
mkdir /luntan
下载nfs环境
yum -y install nfs-utils*
上传论坛包到/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/
配置进程
# 启动nfs进程守护
systemctl start rpcbind
systemctl start nfs
共享
# 编辑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
6.web1
关闭防火墙,selinux
# 关闭防火墙
systemctl stop firewalld
# 关闭selinux
setenforce 0
设置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
安装环境
# 安装httpd,php,nfs环境
yum -y install httpd php php-mysql nfs-utils*
挂载并启动
# 将nfs共享目录挂载到apache下
mount 192.168.100.116:/luntan /var/www/html
# 启动服务
systemctl start httpd
7.web2
关闭防火墙,selinux
# 关闭防火墙
systemctl stop firewalld
# 关闭selinux
setenforce 0
设置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
安装环境
# 安装httpd,php,nfs环境
yum -y install httpd php php-mysql nfs-utils*
挂载并启动
# 将nfs共享目录挂载到apache下
mount 192.168.100.116:/luntan /var/www/html
# 启动服务
systemctl start httpd
8.mysql
关闭防护墙,selinux
# 关闭防火墙
systemctl stop firewalld
# 关闭selinux
setenforce 0
设置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
下载mariadb
yum -y install mariadb mariadb-server
修改完成重启服务
# 重启服务
systemctl restart mariadb
# 配置mysql密码,123456
mysql_secure_installation
授权
# 进入mysql
mysql -uroot -p123456
# 授权
grant all privileges on *.* to 'root'@'%' identified by '123456';
# 刷新权限
flush privileges;
三、安装
进入浏览器,输入http://192.168.100.100/upload,开始安装
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » 搭建discuz论坛(lvs+nginx+http+mysql+nfs)8台服务器
发表评论 取消回复