Centos中nginx+rsync+inotify實現負載平衡配置

來源:互聯網
上載者:User


實驗環境

前端nginx:ip 192.168.6.242,對後端的wordpress網站做反向 Proxy實現負載平衡
後端nginx:ip 192.168.6.36,192.168.6.205都部署wordpress,並使用相同的資料庫


1、安裝rsync和inotify

在後端的兩個wordpress上配置rsync+inotify,兩伺服器都開啟rsync服務,並且通過inotify分別向對方同步資料
下面配置192.168.6.205這台伺服器


vim /etc/rsyncd.conf
 uid = nginx
 gid = nginx
 port = 873

 <span style="background-color: #(color);"><span style="color: #f00;">host all = 192.168.6.36     #另外一台wordpress使用192.168.6.205</span></span>

 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 = <span style="color: #f00;">/etc/rsync_server.passwd     #指定帳號密碼,用於提供另外一個節點訪問自身的帳號

 </span>

vim /etc/rsync_server.passwd
 rsync:rsync
vim /etc/rsync_client.passwd

rsync                                                     #用於訪問另外一個wordpress使用的密碼檔案


配置inotify同步指令碼

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
讓該指令碼在後台運行

nohup /root/inotify.sh &

2、配置前端nginx實現反向 Proxy

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地址或者網域名稱

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.