Linux集群服务知识点总结及通过案例介绍如何实现高性能web服务(三)
三:通過corosync+pacemaker實(shí)現(xiàn)web服務(wù)高可用,主要實(shí)現(xiàn)步驟:
既然給web應(yīng)用服務(wù)器做高可用,那么httpd進(jìn)程就不能開機(jī)自動(dòng)運(yùn)行,而且當(dāng)前httpd服務(wù)屬于停止?fàn)顟B(tài),有corosync來自動(dòng)啟動(dòng)某臺的httpd進(jìn)程
| 12 | [root@Real1 ~]# service httpd stop ?&& ?chkconfig httpd off[root@Real2 ~]# service httpd stop ?&& ?chkconfig httpd off |
注:在安裝corosync+pacemaker軟件包之前,使用yum來安裝它們所依賴的軟件包:
| 1 | [root@Real1 ~]# yum install libibverbs librdmacm lm_sensors libtool-ltdl openhpi-libs openhpi perl-TimeDate -y |
第一步:在兩臺Realserver應(yīng)用服務(wù)器上安裝corosync+pacemaker軟件包,相應(yīng)軟件包列表:
| 123456789101112131415 | cluster-gluecluster-glue-libsheartbeatopenaislibresource-agentscorosyncheartbeat-libspacemakercorosyncliblibesmtppacemaker-libs注:軟件包下載地址:http://clusterlabs.org/rpm/。請根據(jù)硬件平臺及操作系統(tǒng)類型選擇對應(yīng)的軟件包;這里建議每個(gè)軟件包都使用目前最新的版本。使用如下命令安裝:# yum -y --nogpgcheck localinstall *.rpm ? 略過驗(yàn)證碼檢測,使用本地安裝 |
第二步:配置corosync和authkeys文件
| 123456789101112131415 | [root@Real1 ~]# cp /etc/corosync/corosync.conf.example /etc/corosync/corosync.conf[root@Real1 ~]# vim /etc/corosync/corosync.conf ? ##編輯corosync主配置文件,并添加如下內(nèi)容aisexec {user: rootgroup: root}service {name: pacemakerver: 0use_mgmtd: yes}并設(shè)定此配置文件中 bindnetaddr后面的IP地址為你的網(wǎng)卡所在網(wǎng)絡(luò)的網(wǎng)絡(luò)地址bindnetaddr 172.16.0.0生成節(jié)點(diǎn)間通信時(shí)用到的認(rèn)證密鑰文件:[root@Real1 ~]# corosync-keygen |
注:Real2上也做同樣的操作,例如安裝包依賴關(guān)系及安裝corosync+pacemaker軟件包。
第三步:將Realserver1上的corosync和authkey復(fù)制至Realserver2上即可:
| 1 | [root@Real1 ~]# scp -p corosync authkey ?Real2:/etc/corosync/ ? ? ##使用-p選項(xiàng)可以保留原來的屬性信息 |
第四步:分別為兩個(gè)節(jié)點(diǎn)創(chuàng)建corosync,生成的日志所在的目錄:
| 12 | [root@Real1 ~]# mkdir /var/log/cluster[root@Real1 ~]# ssh Real2 ?'mkdir /var/log/cluster' |
第五步:分別在每個(gè)節(jié)點(diǎn)上啟動(dòng)corosync進(jìn)程服務(wù)
| 123 | [root@Real1 ~]# service corosync restart[root@Real1 ~]# ssh Real2 'service corosync restart'[root@Real1 ~]# crm status |
◆ 查看corosync啟動(dòng)的相關(guān)進(jìn)程
| 1 | [root@Real1 ~]# ps auxf |
第六步:檢查corosync相關(guān)日志信息:
1:查看corosync引擎是否正常啟動(dòng):
| 1234567 | # grep -e "Corosync Cluster Engine"-e "configuration file"/var/log/cluster/corosync.logMay 1915:46:30corosync [MAIN ?] Corosync Cluster Engine ('1.2.7'): started and ready to provide service.May 1915:46:30corosync [MAIN ?] Successfully read main configuration file'/etc/corosync/corosync.conf'.May 1915:46:51corosync [MAIN ?] Corosync Cluster Engine exiting withstatus 0at main.c:170.May 1915:46:54corosync [MAIN ?] Corosync Cluster Engine ('1.2.7'): started and ready to provide service.May 1915:46:54corosync [MAIN ?] Successfully read main configuration file'/etc/corosync/corosync.conf'.May 1915:48:00corosync [MAIN ?] Corosync Cluster Engine exiting withstatus 0at main.c:170. |
2、查看初始化成員節(jié)點(diǎn)通知是否正常發(fā)出:
| 12345 | # grep ?TOTEM ?/var/log/cluster/corosync.logMay 1915:46:54corosync [TOTEM ] Initializing transport (UDP/IP).May 1915:46:54corosync [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).May 1915:46:56corosync [TOTEM ] The network interface[172.16.88.10] isnow up.May 1915:46:57corosync [TOTEM ] A processor joined or left the membership and a newmembership was formed. |
3、查看pacemaker是否正常啟動(dòng):
| 123456 | # grep pcmk_startup /var/log/cluster/corosync.logMay 1915:46:33corosync [pcmk ?] info: pcmk_startup: CRM: InitializedMay 1915:46:33corosync [pcmk ?] Logging: Initialized pcmk_startupMay 1915:46:33corosync [pcmk ?] info: pcmk_startup: Maximum core file size is: 4294967295May 1915:46:33corosync [pcmk ?] info: pcmk_startup: Service: 9May 1915:46:33corosync [pcmk ?] info: pcmk_startup: Local hostname: Real1.example.com |
第七步:使用如下命令查看集群節(jié)點(diǎn)的啟動(dòng)狀態(tài):
第八步:配置集群工作屬性及集群資源:
◆ 禁用stonith設(shè)備和關(guān)閉法定票數(shù)的默認(rèn)策略為ingore
◆ 添加集群資源(vip、httpd):
第九步:查看資源的啟用狀態(tài)(crm stauts)
◆ 如果想讓兩個(gè)資源運(yùn)行在一個(gè)Realserver中的話,需要定義組資源,然后將vip和webservice加入到組中即可。
◆ 用windows客戶端測試:
第十步:如果其中一個(gè)節(jié)點(diǎn)發(fā)生故障,另一個(gè)節(jié)點(diǎn)就會(huì)取代發(fā)生故障的節(jié)點(diǎn),然后對外提供服務(wù)。
| 12 | [root@Real1 ~]# crm node standby[root@Real1 ~]# crm status |
再次使用windows客戶端測試:
◆ 我們知道限制資源運(yùn)行在同一個(gè)節(jié)點(diǎn)上,有兩種方法(定義資源組和設(shè)置排列約束),下面來如何使用排列約束來限制兩個(gè)資源在同一個(gè)節(jié)點(diǎn)上,在設(shè)置前,我們將資源組web收到刪除。
| 12345678 | [root@Real1 ~]# crm resourcecrm(live)resource# stop webcrm(live)resource# cleanup webcrm(live)resource# cdcrm(live)# configurecrm(live)configure# deletewebcrm(live)configure# verifycrm(live)configure# commit |
◆ 下面就可以使用排列約束來限制兩個(gè)資源運(yùn)行在同一個(gè)節(jié)點(diǎn)上:
◆ 使用crm status命令查看資源運(yùn)行節(jié)點(diǎn)狀態(tài)并使用netstat
◆ 設(shè)置資源啟動(dòng)順序
◆ 手動(dòng)遷移資源到另一個(gè)節(jié)點(diǎn):
◆ 用windows客戶端測試
◆ 定義資源的黏貼性(傾向性),vip資源更傾向運(yùn)行在Real1主機(jī)上:
◆ 使用crm status命令查看當(dāng)前資源運(yùn)行在那個(gè)節(jié)點(diǎn)上,并手動(dòng)遷移資源,然后手動(dòng)在上線,看是否vip資源更傾向于節(jié)點(diǎn)一上。
| 123456789101112131415161718192021222324252627282930313233343536373839 | [root@Real1 ~]# crm status ? ? ##查看當(dāng)前資源運(yùn)行在那個(gè)節(jié)點(diǎn)上============Last updated: Sun May 2622:17:022013Stack: openaisCurrent DC: Real1.example.com - partition withquorumVersion: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f2Nodes configured, 2expected votes2Resources configured.============Online: [ Real1.example.com Real2.example.com ]httpd ?(lsb:httpd): ? ?Started Real1.example.comvip ? ?(ocf::heartbeat:IPaddr): ? ?Started Real1.example.com[root@Real1 ~]# crm node standby ?##手動(dòng)遷移資源,并成為被動(dòng)節(jié)點(diǎn)[root@Real1 ~]# crm status============Last updated: Sun May 2622:17:262013Stack: openaisCurrent DC: Real1.example.com - partition withquorumVersion: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f2Nodes configured, 2expected votes2Resources configured.============Node Real1.example.com: standbyOnline: [ Real2.example.com ]httpd ?(lsb:httpd): ? ?Started Real2.example.comvip ? ?(ocf::heartbeat:IPaddr): ? ?Started Real2.example.com[root@Real1 ~]# crm node online ? ?##將節(jié)點(diǎn)變?yōu)橹鞴?jié)點(diǎn)[root@Real1 ~]# crm status ? ##再次查看資源,因?yàn)槟J(rèn)黏貼值為0,所以發(fā)現(xiàn)vip更傾向運(yùn)行在節(jié)點(diǎn)Real1節(jié)點(diǎn)上============Last updated: Sun May 2622:17:482013Stack: openaisCurrent DC: Real1.example.com - partition withquorumVersion: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f2Nodes configured, 2expected votes2Resources configured.============Online: [ Real1.example.com Real2.example.com ]httpd ?(lsb:httpd): ? ?Started Real1.example.comvip ? ?(ocf::heartbeat:IPaddr): ? ?Started Real1.example.com |
◆ 設(shè)定默認(rèn)黏貼值為200,然后再手動(dòng)遷移資源,看vip資源是否更傾向于運(yùn)行在哪個(gè)節(jié)點(diǎn)上。
| 123456789101112131415161718192021222324252627282930313233343536373839 | [root@Real1 ~]# crm status============Last updated: Sun May 2622:29:502013Stack: openaisCurrent DC: Real1.example.com - partition withquorumVersion: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f2Nodes configured, 2expected votes2Resources configured.============Online: [ Real1.example.com Real2.example.com ]httpd ?(lsb:httpd): ? ?Started Real1.example.comvip ? ?(ocf::heartbeat:IPaddr): ? ?Started Real1.example.com[root@Real1 ~]# crm node standby[root@Real1 ~]# crm status============Last updated: Sun May 2622:30:052013Stack: openaisCurrent DC: Real1.example.com - partition withquorumVersion: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f2Nodes configured, 2expected votes2Resources configured.============Node Real1.example.com: standbyOnline: [ Real2.example.com ]httpd ?(lsb:httpd): ? ?Started Real2.example.comvip ? ?(ocf::heartbeat:IPaddr): ? ?Started Real2.example.com[root@Real1 ~]# crm node online[root@Real1 ~]# crm status ? ?##因?yàn)橘Y源的默認(rèn)粘性為200,大于Real1節(jié)點(diǎn)上的粘性值,所以vip資源更傾向運(yùn)行在節(jié)點(diǎn)2上。============Last updated: Sun May 2622:30:362013Stack: openaisCurrent DC: Real1.example.com - partition withquorumVersion: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f2Nodes configured, 2expected votes2Resources configured.============Online: [ Real1.example.com Real2.example.com ]httpd ?(lsb:httpd): ? ?Started Real2.example.comvip ? ?(ocf::heartbeat:IPaddr): ? ?Started Real2.example.com |
轉(zhuǎn)載于:https://blog.51cto.com/smileyouth/1269169
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的Linux集群服务知识点总结及通过案例介绍如何实现高性能web服务(三)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 透过表象看本质!?之二数据拟合
- 下一篇: Linux命令——chmod