- A+
所属分类:Nginx
实验环境
前端nginx:ip 192.168.6.242,对后端的wordpress网站做反向代理实现负载均衡
后端nginx:ip 192.168.6.36,192.168.6.205都部署wordpress,并使用相同的数据库
安装rsync和inotify
在后端的两个wordpress上配置rsync+inotify,两服务器都开启rsync服务,并且通过inotify分别向对方同步数据, 下面配置192.168.6.205这台服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
vim /etc/rsyncd.conf uid = nginx gid = nginx port = 873 host all = 192.168.6.36 #另外一台wordpress使用192.168.6.205 use chroot = on max connections = 4 timeout = yes [wordpress] path = /usr/local/nginx/html/wordpress comment = rsync files ignore errors read only = no list = yes auth users = rsync secrets file = etc/rsync_server.passwd #指定帐号密码,用于提供另外一个节点访问自身的帐号 |
账号密码
1 2 3 4 5 6 7 8 |
服务端 vim /etc/rsync_server.passwd rsync:rsync 客户端 vim /etc/rsync_client.passwd rsync #用于访问另外一个wordpress使用的密码文件 |
配置inotify同步脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 |
vim /root/inotify.sh #!/bin/bash host=192.168.6.36 #另外一个wordpress src=/usr/local/nginx/html/wordpress/ dst=wordpress user=rsync inotifywait=/usr/local/inotify/bin/inotifywait rsync=/usr/bin/rsync $inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib $src | while read files do $rsync -vzrtopg --delete --progress --password-file=/etc/rsync_client.passwd $src $user@$host::$dst echo "${files} was rsynced" >>/tmp/rsync.log 2>&1 done |
让该脚本在后台运行
1 |
nohup /root/inotify.sh & |
配置前端nginx实现反向代理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
vim /usr/local/nginx/conf/nginx.conf #在http段中加入 include vhost/wordpress.conf; mkdir /usr/local/nginx/confi/vhost vim /usr/local/nginx/confi/vhost/wordpress.conf upstream wordpress { server 192.168.6.205 weight=1; server 192.168.6.36 weight=1; } server { location / { proxy_pass http://wordpress; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } |
修改wordpress中的设置
必须将这个了的站点地址改为前端nginx的ip地址或者域名

微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
15/03/2016 上午 9:47 沙发
你好,我尝试了一下,但是发现在一台机器上编辑一个文件,保存退出之后,,会产生一个swo和swp文件,虽然可以同步,但是两台机器上都会产生这两个文件,请问这是我哪里没有配置好吗?
02/05/2016 下午 12:53 1层
@djl 这是vim 编辑器产生的临时文件,好像是 多个vim 编辑器的进程同时打开一个文件就会产生这种文件
02/12/2015 下午 3:42 板凳
这是主从吧…
11/09/2015 下午 11:22 地板
rsync+inotify的组合建议使用 lsyncd,Ubuntu源直接有,CentOS添加EPEL源之后也有,Github:https://github.com/axkibe/lsyncd
01/09/2015 下午 5:43 4楼
这样的作用是什么?如果A上有sessionA,B上有sessionB,A同步过去会删掉B的内容的。相反B也会删除A的内容。
26/08/2015 下午 1:06 5楼
secrets file = etc/rsync_server.passwd #指定帐号密码,用于提供另外一个节点访问自身的帐号
—–
这样配置是真可以?
26/08/2015 下午 1:06 6楼
secrets file = etc/rsync_server.passwd #指定帐号密码,用于提供另外一个节点访问自身的帐号
—–
这样配置是真可以?
27/08/2015 下午 8:37 1层
@匿名 可以自定义账号密码,关于rsync,请看本站的rsync相关文章