wordpress网站集群搭建
wordpress1 (192.168.2.11)
wordpress2 (192.168.2.12)
wordpress3 (192.168.2.13)
把wordpress1的nginx打包拷贝到2和web3上
[root@wordpress1 ~]# scp nginx.tar.gz 192.168.2.12:/root/
[root@wordpress1 ~]# scp nginx.tar.gz 192.168.2.13:/root/
[root@wordpress1 ~]# scp /usr/lib/systemd/system/nginx.service 192.168.2.13:/usr/lib/systemd/system/
[root@wordpress1 ~]# scp /usr/lib/systemd/system/nginx.service 192.168.2.12:/usr/lib/systemd/system/
在wordpress2和wordpress3上启服务
[root@workpress-3-13 ~]# systemctl daemon-reload
[root@workpress-3-13 ~]# systemctl enable nginx.service --now
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@workpress-3-13 ~]# ss -tlnp | grep :80
LISTEN 0 128 *:80 *:* users:(("nginx",pid=1550,fd=6),("nginx",pid=1549,fd=6))
[root@workpross-2 ~]# systemctl daemon-reload
[root@workpross-2 ~]# systemctl enable nginx.service --now
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@workpross-2 ~]# ss -tlnp | grep :80
LISTEN 0 128 *:80 *:* users:(("nginx",pid=1542,fd=6),("nginx",pid=1541,fd=6))
配置wordpress2和wordpress3支持php
[root@workpross-22 ~]# yum install -y php php-fpm php-mysql
[root@workpross-2 ~]# systemctl enable php-fpm --now
[root@workpross-3~]# yum install -y php php-fpm php-mysql
[root@workpross-3 ~]# systemctl enable php-fpm --now
在任意的一个主机上页面上新建文章,另外的两台主机,也可以看到更新。因为3台web服务器新建文章时,都是把数据存入到数据库服务器了。
配置NFS服务器
nfs (192.168.2.23)
安装nfs
[root@nfs ~]# yum install -y nfs-utils.x86_64
配置共享
[root@nfs ~]# mkdir /web_share
[root@nfs ~]# vim /etc/exports
/web_share 192.168.2.0/24(rw,no_root_squash)
rw表示读写权限
no_root_squash,表示远程主机root创建的文件,属主属组就是root。默认会变成nfsnobody
启动服务。注意,NFS服务依赖rpcbind服务
[root@nfs ~]# systemctl enable rpcbind --now
[root@nfs ~]# ss -tlnp | grep :111
LISTEN 0 128 *:111
[root@nfs ~]# systemctl enable nfs --now
[root@nfs ~]# ss -tlnp | grep :2049
LISTEN 0 64 *:2049
验证
[root@nfs ~]# showmount -e
Export list for nfs:
/web_share 192.168.2.0/24
迁移文件至nfs共享
[root@wordpress1 ~]# cd /usr/local/nginx/
[root@wordpress1 nginx]# tar cpzf /root/html.tar.gz html
[root@wordpress1 nginx]# cd
[root@wordpress1 ~]# scp html.tar.gz 192.168.2.23:/root/
[root@nfs-2-23 ~]# tar xf html.tar.gz -C /web_share/
删除wordpress服务器html目录中的内容
rm -rf /usr/local/nginx/html/*
在各wordpress服务器上挂载共享目录
以word press1为例
[root@wordpress1 ~]# yum install -y nfs-utils
[root@wordpress1 ~]# echo '192.168.2.23:/web_share/html /usr/local/nginx/html nfs defaults 0 0' >> /etc/fstab
[root@wordpress1 ~]# mount -a
[root@wordpress1 ~]# df -h /usr/local/nginx/html/
文件系统 容量 已用 可用 已用% 挂载点
192.168.2.31:/web_share/html 30G 1.4G 29G 5% /usr/local/nginx/html
配置代理服务器
proxy01(192.168.2.5/192.168.1.5)
[root@proxy ~]# yum install -y haproxy
[root@proxy ~]# vim /etc/haproxy/haproxy.cfg
把63行到最后一行删除,然后追加以下内容
listen wordpress *:80
balance roundrobin
server web1 192.168.2.11:80 check inter 2000 rise 2 fall 3
server web2 192.168.2.12:80 check inter 2000 rise 2 fall 3
server web3 192.168.2.13:80 check inter 2000 rise 2 fall 3
[root@proxy ~]# systemctl enable haproxy.service --now
[root@proxy ~]# ss -tlnp | grep :80
LISTEN 0 128 *:80
• 客户端访问http://192.168.4.5或http://192.168.2.5仍然可以正常访问
• 为HAProxy配置监控页面
shell
[root@proxy ~]# vim /etc/haproxy/haproxy.cfg
在结尾追加以下内容
listen mon *:1080
stats refresh 30s
stats uri /mon
stats auth admin:admin
[root@proxy ~]# systemctl restart haproxy