centos6下基於session綁定nat模型的lvs叢集教程

來源:互聯網
上載者:User

實驗環境:四台虛擬機器,安裝的作業系統是CentOS6.5,各自的功能及IP地址如下:

Director:

    eth0 192.168.2.1(作為VIP使用),eth1:10.0.0.1(作為DIP使用)

RS1:

    eth0:10.0.0.2

RS2:

    eth0:10.0.0.3

資料庫伺服器:安裝的mariadb

    eth0:10.0.0.4

拓撲圖:


 
實驗步驟:

一、準備資料庫伺服器,安裝mariadb,建立一個用於遠端連線資料庫的使用者,建立一個資料庫,用於兩台RS伺服器串連時使用,授權給該使用者對應的資料庫所有許可權。

MariaDB [(none)]> CREATE USER cluster@'10.%.%.%' IDENTIFIED BY 'cluster';
MariaDB [(none)]> CREATE DATABASE cluster;
MariaDB [(none)]> GRANT ALL ON cluster.* TO 'cluster'@'10.%.%.%';
MariaDB [(none)]> FLUSH PRIVILEGES;

二、準備兩台RS伺服器,這兩台RS伺服器都要提供httpd服務。將Discuz論壇安裝程式解壓後的目錄檔案upload複製到/var/www/html/bbs目錄下,複製到其中一台就可以,以RS1為例。使用系統內建的httpd

[root@node1 ~]# yum install -y php
[root@node1 ~]# yum install -y php-mysql
[root@node1 ~]# service httpd start
[root@node1 Discuz]# unzip Discuz_X2.5_SC_GBK.zip  #將解壓出來的upload目錄複寫到/var/www/html目錄下
[root@node1 Discuz]# cp upload/ /var/www/html/bbs
[root@node1 Discuz]# cp upload/ /var/www/html/bbs^C
[root@node1 Discuz]# cd /var/www/html/bbs
[root@node1 bbs]# chmod -R 777 config/ data/ uc_client/ uc_server/

在RS1和RS2上都安裝xinetd並將rsync啟動為服務,以便將/var/www/html目錄的內容做到同時同步的效果,以達到兩台伺服器上內容一致。編輯/etc/rsyncd.conf檔案,內容為:

# Global Settings
uid = nobody
gid = nobody
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
# Directory to be synced
[backup]
path = /var/www/html
ignore errors = yes
read only = no
write only = no
hosts allow = 10.0.0.0/8
hosts deny = *
list = true
uid = root
gid = root
auth users = backup_transfer
secrets file = /etc/rsyncd.passwd

[root@node2 ~]# echo "backup_transfer:redhat" > /etc/rsyncd.passwd  #這個檔案用於認證另外一個節點推送資料時的使用者身份。
backup_transfer:redhat
[root@node2 ~]# echo "redhat" > /etc/rsyncd.passwd2 #這個檔案用於向對方節點推送時在指令碼中指定密碼檔案,免去互動的過程。
[root@node2 ~]# chmod 600 /etc/rsyncd.passwd
[root@node2 ~]# chmod 600 /etc/rsyncd.passwd2
[root@node2 ~]# chkconfig rsync on
[root@node2 ~]# service xinetd start

提供指令檔,以便在兩台伺服器中網站資料目錄內的檔案發生變化時,可以自動推送檔案。指令碼的內容為:

#!/bin/bash
#
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w %w%f %e' -e modify,delete,create,attrib /var/www/html | while read file;
do
/usr/bin/rsync -vzrtopg --delete --progress /var/www/html/ backup_transfer@10.0.0.3::backup --password-file=/etc/rsyncd.passwd2
echo "${files} was rsynced" >> /var/log/rsync.log 2>&1
done

指令碼中定義的傳送IP為對方伺服器的IP地址,只需要修改這一點就可以,其他的配置可以完全一樣,就不再重複。

另外可以在網站根目錄下各添加index.html檔案,簡單的在檔案中寫入對應的主機名稱,之後方便在測試的時候查看director在調度的時候調度請求到不同的主機的效果。

由於是在虛擬機器中類比實驗,所以兩台RS與Director之間的通訊需要RS指向Director的DIP作為網關。

[root@node1 ~]# route add default gw 10.0.0.1 #兩台RS上都要設定。

三、設定Director

Director上配置了兩塊網卡一個作為串連外網的網卡使用,即VIP:192.168.2.1,另外一塊網卡作為內網的網關使用,IP地址為10.0.0.1,另外要開啟IP地址轉寄功能,這樣在類比的實驗環境中RS1和RS2才可以和192.168.2.1正常通訊:

[root@director ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@director ~]# ipvsadm -A -t 192.168.2.1:80 -s rr   #定義叢集服務
[root@director ~]# ipvsadm -a -t 192.168.2.1:80 -r 10.0.0.2 -m   #添加RS1
[root@director ~]# ipvsadm -a -t 192.168.2.1:80 -r 10.0.0.3 -m   #添加RS2

先在瀏覽器內測試預設首頁的效果:


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.