一.实验环境
 二.实验目的
实验目的 通过www.magedu.org访问个人站点 本机的hosts(windows环境)添加解析到vip 通过haproxy实现反向代理 要求 两台nginx+php的web环境 实现站点高可用 任何一台宕机不影响访问 nginx要相同版本 普通用户启动 博客要正常上传,并且在两个web读取 共享基于共享存储NFS实现 对nfs实现实时跨主机数据同步备份 部署数据库主从 **言简意赅的说:**就是客户端通过本机设置的vip,通过haproxy实现反向代理 轮询访问web1和2 ,创建一个博客账号,并上传图片,图片要在两台web主机读取,并且实时备份在nfs1和2服务器 ,同时修改的数据要存放在mysql两台主从服务器里
三.部署步骤
1.配置主从  mysql安装可以用编译,也可以用yum 版本一致就可以,我这里用的是yum安装
yum -y install mysql-server ;systemctl enable --now mysqld ; systemctl start mysqld
https://blog.csdn.net/Lcongming/article/details/117090768 (详细配置主从步骤) 由于后面要搭建博客,所以这里我们要在10.0.0.8上先创建一个WordPress的账号并授权; 步骤如下图  在slave验证
mysql -uwordpress -p123456 -h10.0.0.8
 2.实现NFS实时同步  我采用的是基于远程shell 实现 sersync 在47和57两台机器开启了ssh免密登录( https://blog.csdn.net/Lcongming/article/details/117405991 免密登录设置) 我们现在10.0.0.5710.0.0.57NFS2上操作 安装并且启动rsync :
yum -y install rsync ; systemctl enable --now rysncd ; systemctl start rsyncd
修改配置文件;vim /etc/rsyncd.conf 在最后添加
uid = root
gid = root
max connections = 0
ignore errors
exclude = lost+found/
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
reverse lookup = no
[backup]
path = /data/backup/
comment = backup dir
read only = no
再接着建立backup
mkdir /data/backup/
由于用户和组都是root 所以不需要改权限 再重启一下服务;systemctl restart rsyncd
而在NFS1安装了sersync 和nfs-utils 安装的大致步骤如下 将安装包上传 将下载好的软件上传后,解压;tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz 拷贝至相应的目录,设置PATH变量
cp -a GNU-Linux-x86 /usr/local/sersync
echo 'PATH=/usr/local/sersync:$PATH' > /etc/profile.d/sersync.sh
source /etc/profile.d/sersync.sh
#sersync目录只有两个文件:一个是二进制程序文件,一个是xml格式的配置文件  #备份sersync配置文件
cp /usr/local/sersync/confxml.xml{,.bak}
#修改sersync配置文件
vim /usr/local/sersync/confxml.xml
(说明图中1234是常规设置,由于使用了基于shell远程实现sersync,开启了ssh所以④设置false 就是不需要账号密码,而⑤开启了ssh)  然后执行
sersync2 -dro /usr/local/sersync/confxml.xml
(以后台方式运行同步,这步不执行,备用服务器上数据无法同步)
3.搭建Keepalive高可用并配置haproxy 
10.0.0.7 kp1 10.0.0.17 kp2 安装的软件 keepalived和haproxy 安装后 分别要 设置开机启动
systemctl enable --now keepalived.service
systemctl enable --now haproxy.service
搭建keepalived**实现单主 (步骤可以参考:https://blog.csdn.net/Lcongming/article/details/118103893) 以下作参考; kp1 /etc/keepalived/keepalived.conf 
/etc/haproxy/haproxy.conf
(说明有简化配置 和frontend+backend 两种方式,这里用的 是简化配置)  kp2 /etc/keepalived/keepalived.conf  /etc/haproxy/haproxy.conf  在两个ka1和ka2两个节点启用内核参数
vim /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
再执行sysctl -p 抓包观察
tcpdump -i eth0 -nn host 224.0.100.100  (说明,这里看需求,目前实验环境、单主、双主都是可以的)
5.搭建WordPress并挂载
安装的软件 nginx php-fpm nfs-utils  说明一下,除了nginx和php-fpm要安装之外,nfs-untils也要安装,因为涉及挂载 https://blog.csdn.net/Lcongming/article/details/118046181 安装php-fpm参考  接着执行挂载 分别将图中1机器2机器 和3进行挂载  在web1和2上
mkdir -p /data/nginx/wordpress
这个时候 nfs服务一定要启动,执行 systemctl start nfs
mount 10.0.0.47:/data/vmdata/wordpress /data/nginx/wordpress
chown -r nginx.nginx wordpress
查看挂载结果  这个时候,已经实现了web1 web2 nfs1 nfs2上数据同步 目的是后续使1机器和2机器上的网页,php等文件实时同步到NFS服务器中,而数据则存放在主从数据库 补充 如果要机器重启后挂载还在,设置永久挂载就好了 vim /etc/fstab  
6.设置hosts并设置博客 在本地windows下设置  访问域名www.magedu.org  设置完成后,登录微博发表图片;  当web2故障的时候  查看网页访问依旧正常 
7.查看数据是否同步存储 这是在nfs1里的对应数据  下载后就是这个图片  这是在nfs2里查看到的  这是在web1中查看到的  这是在web2中查看到的 
8.报错的处理 上传图片过程中提示报错无法建立目录wp-content/uploads/2021/07。有没有上级目录的写权限? 在master下mysql里操作 update wp_options set option_value = “wp-content/uploads” where option_name = “upload_path”; 将WordPress下将wp-content文件夹的读写权限更改为777即可
|