nginx+rsync+inotify实现负载均衡配置方法
linux  /  管理员 发布于 7年前   126
实验环境
前端nginx:ip 192.168.6.242,对后端的wordpress网站做反向代理实现复杂均衡
后端nginx:ip 192.168.6.36,192.168.6.205都部署wordpress,并使用相同的数据库
1、在后端的两个wordpress上配置rsync+inotify,两服务器都开启rsync服务,并且通过inotify分别向对方同步数据
下面配置192.168.6.205这台服务器
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 #指定帐号密码,用于提供另外一个节点访问自身的帐号
vim /etc/rsync_server.passwd
rsync:rsync
vim /etc/rsync_client.passwd
rsync #用于访问另外一个wordpress使用的密码文件
配置inotify同步脚本
#!/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 Ctimefmt '%d/%m/%y %H:%M' Cformat '%T %w%f' -e modify,delete,create,attrib $src | while read files
do
$rsync -vzrtopg Cdelete Cprogress Cpassword-file=/etc/rsync_client.passwd $src $user@$host::$dst
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
done
2、配置前端nginx实现反向代理
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;
}
}
3、修改wordpress中的设置,必须将这个了的站点地址改为前端nginx的ip地址或者域名
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号