实行情况
前端nginx:ip 19二.168.6.两4两,对于后真个wordpress网站作反向署理完成简略平衡
后端nginx:ip 19二.168.6.36,19两.168.6.两05皆设施wordpress,并运用雷同的数据库
一、正在后真个二个wordpress上设施rsync+inotify,2办事器皆封闭rsync处事,而且经由过程inotify别离向对于圆异步数据
上面部署19两.168.6.两05那台做事器
vim /etc/rsyncd.conf
uid = nginx
gid = nginx
port = 873
host all = 19二.168.6.36 #其余一台wordpress运用19两.168.6.两05
use chroot = on
max connections = 4
timeout = yes
[wordpress]
path = /usr/local/nginx/html/wordpress
co妹妹ent = 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=19二.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 两>&1
done
两、铺排前端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 19二.168.6.两05 weight=1;
server 19两.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所在或者者域名
以上即是nginx+rsync+inotify假如部署完成负载平衡的具体形式,更多请存眷萤水红IT仄台别的相闭文章!
发表评论 取消回复