ESXi_HA(4張網卡)-DRBD-Heartbeat(以apache實作)

Download Report

Transcript ESXi_HA(4張網卡)-DRBD-Heartbeat(以apache實作)

OracleLinux灌好做完基本設定
匯出HA-node.ova之後
第2台先匯.ova來改設定值: ESXi5-02
• 匯入.ova:
– File > Deploy OVF Template > Deploy from a file or URL
• OVF Template Details:
– ova範本檔細節
• Name: apache02
• Disk Format: 不用改
Network Mapping: 應該會配對成功
若有紅字,表示之前Service 或DRBD-Heartbeat打錯字 
請手動配對正確
Network Mapping: 就配對成功了
Ready to Complete
• 確定都ok了後,勾”Power on after deployment”.
> Finish 開機.
apache02開機後
• 1.) 改hostname: apache02.abc.com
– /etc/sysconfig/network
• hostname=apache02.abc.com
• 2.) bond0 ip: 改為10.10.88.112
– 原為101
bond1 ip: 改為192.168.88.112
– 原為101
重啟網路 service network restart
網路還是不通!!
因為 eth0 1 2 3  4 5 6 7
apache02開機後
• 網卡變為 eth4 5 6 7 > 辛苦一點,改回 eth0 1 2 3 (mac要配對)
• 查網卡名稱變化
– dmesg | grep eth0
– dmesg | grep eth1
– dmesg | grep eth2
– dmesg | grep eth3
– ip a > mac.txt, 然後以 vim (split編修)
– 重點是要改煩人的 70-perXXX
• eth0 1 2 3 換回正確的 mac
• 有時在ping的response顯示有「DUP!」,表明存在loop.
(因為有 host-only關係)
• 改好後reboot
• win7 test ping apache02.abc.com (10.10.88.112)
– test ifdown eth0
• win7 test ping 192.168.88.112
– test ifdown eth2
apache02開機後
• 網卡變為 eth4 5 6 7 > 辛苦一點,改回 eth0 1 2 3 (mac要配對)
• 查網卡名稱變化
– dmesg | grep eth0
– dmesg | grep eth1
– dmesg | grep eth2
– dmesg | grep eth3
– ip a > mac.txt, 然後以 vim (split編修)
– 重點是要改煩人的 70-perXXX
• eth0 1 2 3 換回正確的 mac
• 有時在ping的response顯示有「DUP!」,表明存在loop.
(因為有 host-only關係)
• 改好後reboot
• win7 test ping apache02.abc.com (10.10.88.112)
– test ifdown eth0
• win7 test ping 192.168.88.112
– test ifdown eth2
apache01開機
• 1.) 改hostname: apache01.abc.com
– /etc/sysconfig/network
• hostname=apache01.abc.com
• 2.) bond0 ip: 改為10.10.88.111
– 原為101
bond1 ip: 改為192.168.88.111
– 原為101
重啟網路 service network restart
•  一樣不通,eth4567要改回0123,同
apache02
/etc/hosts on apache01 & 02
• 10.10.88.111 apache01.abc.com apache01
• 10.10.88.112 apache02.abc.com apache02
• ftp://120.125.145.81/ha/hosts_apache.txt
apache01 & 02
以 hostname互ping必須會通
• 01 ping 02 service卡
– apache01# ping apache02.abc.com
• 01 ping 02 DRBD-Heartbeat卡
– apache01# ping 192.168.88.112
• 02 ping 01 service卡
– apache02# ping apache01.abc.com
• 02 ping 01 DRBD-Heartbeat卡
– apache02# ping 192.168.88.112
apache01 & 02安裝 apache
• yum -y install httpd
DRBD 設定檔 /etc/drbd.con
01 & 02都要改
• (Distributed Replicated Block Device)
• Network RAID-1
• 01 & 02: 修改drbd.conf設定檔
(apache01 & 02內容相同)
– ftp://120.125.145.81/ha/drbd.conf.txt
/etc/drbd.conf
• resource ha  DRBD資源名稱:ha
• DRBD同步速率為100Mbps(bits),單.conf中的單位為bytes除以8,取約
略10M
syncer {
rate 10M;
}
• apache01 server資訊
on apache01.abc.com {
device /dev/drbd0; //device名稱,用來代表 /dev/sda5,就是/data
disk /dev/sda5; // “/data”的partition,可用fdisk -l查
address 192.168.88.111:7788; //drbd 同步ip & port
meta-disk internal;
}
• apache02 server資訊,意義同上
修改DRBD相關執行檔權限
• ftp://120.125.145.81/ha/change_per_drbd.txt
– chgrp haclient /sbin/drbdsetup
– chmod o-x /sbin/drbdsetup
– chmod u+x /sbin/drbdsetup
– chgrp haclient /sbin/drbdmeta
– chmod o-x /sbin/drbdmeta
– chmod u+x /sbin/drbdmeta
• 目的是讓後續建DRBD資源時,可以順切執行
相關指令
載入 drbd 模組並建立 resource
01 及 02 都必須做
• modprobe指令載入drbd 模組 (locate drbd.ko確認有此module)
– modprobe drbd
• 確認 drbd 模組是否載入
– lsmod|grep drbd
• 執行drbd之前,必須塞一些資料到/dev/sda5內,否則create-md時會出現錯誤
– dd if=/dev/zero of=/dev/sda5 bs=1M count=100
– sda5就是/data的partition
• 載入drbd module ok後,建立 drbd resource, 指令
– drbdadm create-md 資源名稱,因為在 drbd 設定檔(drbd.conf)中 resource
名稱為 ha 所以上述的資源名稱就是以ha取代,指令如下:
drbdadm create-md ha (執行成功後,可以以 ctrl+c 跳出)
• 啟動 drbd 服務
– service drbd start
• 設定 drbd 開機時自動啟動
– chkconfig drbd on
• 所有指令:
– ftp://120.125.145.81/ha/drbd_load_mo_create_rs.txt
上一頁,指令匯整(01 & 02都要做)
• modprobe drbd //載入 drbd 模組
• lsmod|grep drbd //確認 drbd 模組是否載入
• dd if=/dev/zero of=/dev/sda5 bs=1M count=100
//執行drbd之前,必須塞一些資料到/dev/sda5內
(否則 create-md 時會出現錯誤)
• drbdadm create-md ha //建立 drbd resource
• service drbd start //啟動 drbd 服務
• chkconfig drbd on //設定 drbd 開機時自動啟動
drbd 狀態檢視
• drbd啟動後可用 service drbd status查看目前
drbd 的狀態
– service drbd status
• 當01啟動 drbd 服務而02尚未啟動時, 狀態為
Secondary/Unknown
當02也 啟動 drbd 服務後,狀態為
Secondary/Secondary,而 ds 狀態為
Inconsistent 表示二台主機資料尚未同步
01: 先啟動drbd
• 01: watch service drbd status
– 02: service drbd start  觀察 01 drbd status
– 01: service drbd stop  觀察 01 drbd status
• drbd成功連線後,兩者role都是Secondary
– 目前沒有開始同步,沒有任一server是primary
– Active node的drbd資源角色即為primary
– Standby node的drbd資源角色即為secondary
• ds (data state)狀態為 Inconsistent
– 表示二台主機資料尚未同步
只有apache01要做:
初始化apache01的/dev/sda5(即/data的掛載partition)
• 同時,提昇apache01為primary(即active)並開
始同步 /dev/drbd0就是/dev/sda5
• 確定01及02 都可偵測到對方 (drbd state roll:
Secondary/Secondary),將01設為
Primary(active) Node(與上一句話同義)
• 並使二台主機開始同步/dev/sda5硬碟資料
(也就是/dev/drbd0)
• 此時查看 drbd 狀態可發現同步的百分比及
進度(只有01需要執行)
• 初始化apache01的/dev/sda5,指令:
– drbdadm -- --overwrite-data-of-peer primary ha
– ftp://120.125.145.81/ha/drbd_init_dev_sda5_only_apache01.tx
t
• 馬上在01&02執行:
– watch service drbd status
觀察同步的百分比,可看到 兩邊跑的速度是一樣的
• 當同步完成後,可發現二台主機的 ds 狀態都為 UpToDate (service
drbd status)
– 表示同步完成,二台主機擁有相同且最新的資料
– 如影片: http://youtu.be/tkyVp76w2ck?hd=1
– 也可看出 “左邊是自己角色/右邊是對方角色”
– 01: Primary, 02: Secondary
只有01要執行
格式化(mkfs.ext4) /dev/sda5
• 剛剛在drbd.conf中:
– device /dev/drbd0;
disk /dev/sda5;
已設定 /dev/drbd0指的就是/dev/sda5
• 01 及 02都完成資料同步作業後(即 /dev/drbd0 完成初始
化),將/dev/drbd0(/dev/sda5)格式化(mkfs.ext4),格式化完
成後將/dev/drbd0掛載至 /data,指令如下:
– mkfs.ext4 /dev/drbd0
– mount /dev/drbd0 /data
– df -h
• 可看到 /data 已 mount成功到/dev/drbd0 (即/dev/sda5)
• 在01看drbd status:
– service drbd status
– 可看到掛載點 /data與檔案系統 ext4已出現,如下頁
01 & 02都要修改apache設定檔
• locate httpd.conf
• 兩處:“/var/www/html”改為”/data”
– DocumentRoot "/var/www/html“
– <Directory "/var/www/html">
只在01:啟動apache
• service httpd start
• echo “<h1>hello jj</html>” > /data/index.html
• win7 test: http://apache01.abc.com
(Only 01)確定apache01可正確http連
線後,開始Heartbeat前
• stop apache
– service httpd stop
• 卸載 /dev/drbd0(就是drbd mount point)
– umount /dev/drbd0
• 把apache01的資源角色從Primary降為Secondary node,否則待會
兒Heartbeat會無法順切執
• drbdadm secondary ha
• service drbd status
– apache drbd角色已變為Secondary
Heartbeat
• 2台 HA Server,其中一台會產生一個cluster ip,
擁有cluster ip的 active node會回應client
users的要求,當故障轉移(failover)時,新的
active node會接手該cluster ip,並更新arp
cache中cluster ip所對應的mac(改成自己的
mac,client就可以”無斷線感地”持續要求服
務.
01 & 02都要設定 /etc/ha.d/ha.cf
(Heartbeat通訊檔)
• 其實偵測對方是否死掉,就是用簡單的ping
而已
– 每隔2秒互ping對方一次
– 超過15秒對方沒有回應,就認定對方死了
– 兩台server的Heartbeat通訊設定檔為
• /etc/ha.d/ha.cf (原無此檔)
• ftp://120.125.145.81/ha/ha.cf.txt
01的/etc/ha.d/ha.cf
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
debugfile /var/log/ha-debug //Heartbeat服務除錯記錄檔
logfile /var/log/ha-log
//Heartbeat服務記錄檔
logfacility local0
autojoin none
ucast bond0 10.10.75.112
//指定對方(apache02)的bond0 ip (service)
ucast bond1 192.168.75.112 //指定對方(apache02)的bond1 ip (drbd+heartbeat)
ping 10.10.75.254 // //IP 連線偵測用,設定區網內的 Gateway (當網路或 Heartbeat 失效時測試用
(因為有可能是 heartbeat掉了而已,所以ping一下gw是否還是通的)
respawn hacluster /usr/lib/heartbeat/ipfail
respawn hacluster /usr/lib/heartbeat/dopd
apiauth dopd gid=haclient uid=hacluster
udpport 694 // 使用 udp, port 694來 做通訊
warntime 5 //網路disconnect超過5秒就warn
deadtime 15 // 網路disconnect超過15秒,就判定對方主機失效
initdead 60 //初始化超過60秒沒有連上對方,就判定 heartbeat 一開始就沒有成功
keepalive 2 //每2秒互ping對方是否還活著
node apache01.abc.com // 第一台
node apache02.abc.com // 第二台
auto_failback off // Active node 恢復也不會搶回主控權
02的/etc/ha.d/ha.cf
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
debugfile /var/log/ha-debug //Heartbeat服務除錯記錄檔
logfile /var/log/ha-log
//Heartbeat服務記錄檔
logfacility local0
autojoin none
ucast bond0 10.10.75.111
//指定對方(apache01)的bond0 ip (service)
ucast bond1 192.168.75.111 //指定對方(apache01)的bond1 ip (drbd+heartbeat)
ping 10.10.75.254 // //IP 連線偵測用,設定區網內的 Gateway (當網路或 Heartbeat 失效時測試用
(因為有可能是 heartbeat掉了而已,所以ping一下gw是否還是通的)
respawn hacluster /usr/lib/heartbeat/ipfail
respawn hacluster /usr/lib/heartbeat/dopd
apiauth dopd gid=haclient uid=hacluster
udpport 694 // 使用 udp, port 694來 做通訊
warntime 5 //網路disconnect超過5秒就warn
deadtime 15 // 網路disconnect超過15秒,就判定對方主機失效
initdead 60 //初始化超過60秒沒有連上對方,就判定 heartbeat 一開始就沒有成功
keepalive 2 //每2秒互ping對方是否還活著
node apache01.abc.com // 第一台
node apache02.abc.com // 第二台
auto_failback off // Active node 恢復也不會搶回主控權
01 & 02都要設的Heartbeat資源檔
(兩者同) /etc/ha.d/haresources
• 設定 01 & 02的 haresource 資源設定檔 01 及 02 設定檔內容一模
一樣,
• 表示預設使用 01 主機擔任 Primary Node 角色,此設定檔內容可
分為五段來看。(01 及 02 都必須設定)
• 1.) active Node 的 FQDN >> apache01.abc.com
• 2.) 指定 Cluster IP Address : 10.10.88.110
• 3.) 指定 Cluster Resource Name >> drbddisk::ha
• 4.) 指定 Cluster Device, Mount Point、File System Type
• >> drbddisk::ha Filesystem::/dev/drbd0::/data::ext4
• 5.) 指定 Service>> Apache
• haresources 設定檔內容如下
• apache01.abc.com 10.10.88.110 drbddisk::ha
Filesystem::/dev/drbd0::/data::ext4 Apache
• ftp://120.125.145.81/ha/haresources.txt
Heartbeat 驗證設定檔
01 & 02均同, /etc/ha.d/authkeys
•
•
•
•
auth 1
1 sha1 9bc29cfe2f182c3e3ba556fc520d89c3
ftp://120.125.145.81/ha/authkeys.txt
600 permission:
– chmod 600 /etc/ha.d/authkeys
Heartbeat 監控服務設定檔
01 & 02均同, /etc/ha.d/resource.d/Apache
• ftp://120.125.145.81/ha/Apache.txt
• Active 死掉後,standby根豦此檔決定要啟動
什麼服務
• 755 permission
01 & 02新增heartbeat為系統服務
• chkconfig --add heartbeat
• chkconfig heartbeat on
01 & 02 啟動 heartbeat
• service heartbeat start
• ifconfig bond0:0