實驗環境
前端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 . .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/press ##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 –## $rsync -vzrtopg –delete –## $rsync -vzrtopg –delete –##名詞 – progress –password-file=/etc/rsync_client.passwd $src $user@$host::$dst
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
done
vim /usr/local/nginx/conf/nginx.conf
#在http段加入
include vhost/wordpress. conf;
vim /usr/local/nginx/confi/vhost/wordpress.conf
upstream wordpress {
server 192.168.6.205wordpress {
server 192.168.6.2055word weight=1;
server 192.168.6.36 weight=1;
}
server {
location / {
proxy_pass http://wordpresspress;# ## proxy_set_header host proxy_set_header host proxy_set_header host $host;
proxy_set_header x-real-ip $# 前端nginx的ip位址或網域名稱
#
以上是nginx+rsync+inotify怎麼設定實現負載平衡的詳細內容。更多資訊請關注PHP中文網其他相關文章!