主机 | IP | 操作系统 | 角色 |
---|---|---|---|
Lb.example.com | 外网卡:(NAT) 192.168.123.149/24 内网卡:(仅主机模式) 192.168.206.133/24 |
CentOS8.4 | 负载均衡器+yum源 |
web-1.example.com | 仅主机模式192.168.206.129 | CentOS8.4 | Web节点1 |
web-2.example.com | 仅主机模式192.168.64.130 | CentOS8.4 | Web节点2 |
Db.example.com | 仅主机模式192.168.64.134 | CentOS8.4 | DB+NFS |
客户端 | 192.168.123.111 | Win10 | 客户机外网测试 |
安装Centos8.4最小模板机
https://mirrors.aliyun.com
[root@localhost ~]#systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# hostnamectl set-hostname LB.example.com
[root@localhost ~]# bash
[root@LB ~]# yum -y install
[root@LB ~]#vi /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
[root@LB ~]#systemctl enable --now vsftpd
[root@LB ~]# mkdir /var/ftp/dvd
[root@LB ~]#vi /etc/fstab
/dev/cdrom /var/ftp/dvd iso9660 defaults 0 0
[root@LB ~]#mount -a
[root@LB ~]#df -h
/dev/sr0 9.3G 9.3G 0 100% /var/ftp/dvd
内网测试FTP是否可以访问
[root@localhost ~]#hostnamectl set-hostname web-1.example.com
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#setenforce 0
[root@localhost ~]#bash
[root@web-1 ~]#rm -f /etc/yum.repos.d/*
[root@web-1 ~]# cat > /etc/yum.repos.d/base.repo << /
> [base]
> name=base
> baseurl=ftp://192.168.206.133/dvd/BaseOS
> enabled=1
> gpgcheck=0
> /
[root@web-1 ~]# cat > /etc/yum.repos.d/app.repo << /
> [APP]
> name=app
> baseurl=ftp://192.168.206.133/dvd/AppStream
> enabled=1
> gpgcheck=0
> /
[root@web-1 ~]#yum -y install httpd
[root@web-1 ~]# echo 111111111 > /var/www/html/index.html
[root@web-1 ~]#echo web-1 > /var/www/html/test.html
[root@web-1 ~]# systemctl enable --now httpd
[root@localhost ~]#hostnamectl set-hostname web-2.example.com
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#setenforce 0
[root@localhost ~]#bash
[root@web-2 ~]#rm -f /etc/yum.repos.d/*
[root@web-2 ~]# cat > /etc/yum.repos.d/base.repo << /
> [base]
> name=base
> baseurl=ftp://192.168.206.133/dvd/BaseOS
> enabled=1
> gpgcheck=0
> /
[root@web-2 ~]# cat > /etc/yum.repos.d/app.repo << /
> [APP]
> name=app
> baseurl=ftp://192.168.206.133/dvd/AppStream
> enabled=1
> gpgcheck=0
> /
[root@web-2 ~]#yum -y install httpd
[root@web-2 ~]# echo 222222222 > /var/www/html/index.html
[root@web-2 ~]#echo web-2 > /var/www/html/test.html
[root@web-2 ~]# systemctl enable --now httpd
[root@localhost ~]# hostnamectl set-hostname LB.example.com
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]#bash
[root@LB ~]# yum -y install haproxy
[root@LB ~]# vi /etc/haproxy/haproxy.cfg
# 发起http请求道80端口,会被转发到设置的ip及端口
bind *:80
#后端配置
backend app
balance roundrobin
server web-1 192.168.206.129:80 check
server web-2 192.168.206.130:80 check
[root@LB ~]#haproxy -f /etc/haproxy/haproxy.cfg -c
[root@LB ~]#systemctl enable --now haproxy
访问http://192.168.123.149时,不断刷新,会有两个服务器页面来回切换。
[root@localhost ~]# hostnamectl set-hostname Db.example.com
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]#bash
[root@DB ~]# rm -f /etc/yum.repos.d/*
[root@DB ~]# cat > /etc/yum.repos.d/base.repo << /
> [base]
> name=base
> baseurl=ftp://192.168.206.133/dvd/BaseOS
> enabled=1
> gpgcheck=0
> [root@DB ~]# cat > /etc/yum.repos.d/app.repo << /
> [APP]
> name=app
> baseurl=ftp://192.168.206.133/dvd/AppStream
> enabled=1
> gpgcheck=0
> /
[root@DB ~]# yum -y install mariadb-server
[root@DB ~]# systemctl enable --now mariadb
[root@DB ~]# mysql -u root -e 'create database discuz;'
[root@DB ~]# mysql -u root -e "grant all on discuz.* to wxx@'%' identified by '1234';"
[root@DB ~]# yum -y install nfs-utils
[root@DB ~]# mkdir /web
[root@DB ~]# chmod 777 /web
[root@DB ~]# echo /web *(rw) > /etc/exports
[root@DB ~]# systemctl enable --now nfs-server
[root@web-1 ~]# yum -y install php-xmlrpc php php-mysqlnd
[root@web-1 ~]# yum -y install nfs-utils
[root@web-1 ~]# showmount -e 192.168.206.134
Export list for 192.168.206.134:
/web *
[root@web-1 ~]# vim /etc/fstab
192.168.206.134:/web /var/www/html nfs defaults,_netdev 0 0
[root@web-1 ~]# mount -a
[root@web-1 ~]# df -h
192.168.206.134:/web 37G 2.2G 35G 6% /var/www/html
[root@web-2 ~]# yum -y install php-xmlrpc php php-mysqlnd
[root@web-2 ~]# yum -y install nfs-utils
[root@web-2 ~]# showmount -e 192.168.206.134
Export list for 192.168.206.134:
/web *
[root@web-2 ~]# vim /etc/fstab
192.168.206.134:/web /var/www/html nfs defaults,_netdev 0 0
[root@web-2 ~]# mount -a
[root@web-2 ~]# df -h
192.168.206.134:/web 37G 2.2G 35G 6% /var/www/html
[root@DB ~]# yum -y install lrzsz
[root@DB ~]# rz
[root@DB ~]# ll
[root@DB ~]# yum -y install unzip
[root@DB ~]# cd DiscuzX/upload/
[root@DB upload]# mv * /web/
[root@DB upload]# chmod -R 777 /web/
#在两台web服务器检查论坛文件,重启httpd
[root@web-1 ~]# systemctl restart httpd
[root@web-1 ~]# ls /var/www/html/
admin.php connect.php group.php member.php search.php uc_server
api crossdomain.xml home.php misc.php source
api.php data index.php plugin.php static
archiver favicon.ico install portal.php template
config forum.php m robots.txt uc_client
[root@web-2 ~]# systemctl restart httpd
[root@web-2 ~]# ls /var/www/html/
admin.php connect.php group.php member.php search.php uc_server
api crossdomain.xml home.php misc.php source
api.php data index.php plugin.php static
archiver favicon.ico install portal.php template
config forum.php m robots.txt uc_client
#出现这个页面是不正确的
#解决方法
[root@LB ~]# vi /etc/haproxy/haproxy.cfg
frontend main
bind *:80
# acl url_static path_beg -i /static /images /javascript /stylesheets
# acl url_static path_end -i .jpg .gif .png .css .js
# use_backend static if url_static
default_backend app
#再次访问
#一定要全绿,不然会安装不成功
#接下来的步骤均默认下一步
#安装成功页面
#最终成功登录并发帖效果图
#注意:程序安装一次,不能再次安装[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
#若要强制重新安装,需要先删除原安装配置
[root@DB upload]# rm -f /web/data/install.lock
首先配置好防火墙、selinux后,然后将web-1关机,再用web-1克隆出web-n(n=1,2,3······),最后修改haproxy配置文件
[root@LB ~]# vi /etc/haproxy/haproxy.cfg
backend app
balance roundrobin
server web-1 192.168.206.129:80 check
server web-2 192.168.206.130:80 check
server web-3 192.168.206.131:80 check
首先将web-1关机,再用web-1克隆出web-n(n=1,2,3······),最后修改haproxy配置文件
[root@LB ~]# vi /etc/haproxy/haproxy.cfg
backend app
balance roundrobin
server web-1 192.168.206.129:80 check
server web-2 192.168.206.130:80 check
server web-3 192.168.206.131:80 check