一 Heartbeat 基本理論php
提供冗餘系統:
HA Cluster:爲提高系統調用性,組合多臺主機構建成爲的集羣;html
split brain, partitioned clusternode
vote system:投票系統
HA中的各節點沒法探測彼此的心跳信息時,必須沒法協調工做;此種狀態即爲partitioned cluster;mysql
少數服從多數的原則:quorum
with quorum > total/2
without quorum <= total/2linux
仲裁設備:
quorum disk = qdisk
ping nodeweb
failover: 失效轉移,故障轉移
failback:失效轉回,故障轉回sql
資源類型:
HA-aware:資源自身可直接調用HA集羣底層的HA功能;
非HA-aware:必須藉助於CRM完成在HA集羣上實現HA功能;shell
資源的約束關係:
location:位置約束,定義資源對節點的傾向性;用數值來表示,-oo, +oo;
colocation:排列約束,定義資源彼此間「在一塊兒」傾向性;-oo, +oo
分組:亦能實現將多個資源綁定在一塊兒;
order:順序約束,定義資源在同一個節點上啓動時的前後順序;apache
資源類型:
primitive:主資源,只能運行於集羣內的某單個節點;(也稱做native);
group:組資源,容器,包含一個或多個資源,這些資源可經過「組」這個資源統一進行調度;
clone:克隆資源,能夠在同一個集羣內的多個節點運行多份克隆;
master/slave:主從資源,在同一個集羣內部於兩個節點運行兩份資源,其中一個主,一個爲從;vim
資源隔離:
級別
節點:STONITH (Shooting The Other Node In The Head)
power switch
資源:fencing
FC SAN switch
解決方案:
Messaging Layer:
heartbeat
v1, v2, v3
corosync
cman (RedHat, RHCS)
keepalived (徹底不一樣上述三種)
CRM:
heartbeat v1 haresources (配置接口:配置文件,文件名爲haresources)
heartbeat v2 crm (在各節點運行一個crmd進程,配置接口:命令行客戶端程序crmsh,GUI客戶端:hb_gui);
heartbeat v3, pacemaker (pacemaker能夠以插件或獨立方式運行;配置接口,CLI接口:crmsh, pcs; GUI: hawk(webgui), LCMC, pacemaker-mgmt);
rgmanager (配置接口,CLI:clustat, cman_tool; GUI: Conga(luci+ricci))
組合方式:
heartbeat v1
heartbeat v2
heartbeat v3 + pacemaker
corosync + pacemaker
cman + rgmanager (RHCS)
cman + pacemaker
LRM: Local Resource Manager, 由CRM經過子程序提供;
RA: Resouce Agent
heartbeat legacy:heartbeat傳統類型的RA,一般位於/etc/ha.d/haresources.d/目錄下;
LSB:Linux Standard Base, /etc/rc.d/init.d目錄下的腳本,至少接受4個參數:{start|stop|restart|status};
OCF:Open Cluster Framework
子類別:provider
STONITH:專用於實現調用STONITH設備功能的資源;一般爲clone類型;
Heartbeat:心跳信息傳遞機制
serail cable:做用範圍有限,不建議使用;
ethernet cable:
UDP Unicast
UDP Multicast
UDP Broadcast
組播地址:用於標識一個IP組播域;IANA(Internet Assigned number authority)把D類地址空間分配給IP組播使用;其範圍是:224.0.0.0-239.255.255.255;
永久組播地址:224.0.0.0-224.0.0.255;
臨時組播地址:224.0.1.0-238.255.255.255;
本地組播地址:239.0.0.0-239.255.255.255, 僅在特定本地範圍內有效;
HA案例:ha web services
資源有三個:
ip, httpd, filesystem
fip: floating ip,172.16.100.17
daemon: httpd
約束關係:使用「組」資源,或經過排列約束讓資源運行於同一節點;
順序約束:有次序地啓動資源;
程序選型:
heartbeat v2 + haresources
heartbeat v2 + crm (hb_gui)
配置HA集羣的前提:
(1) 節點間時間必須同步:使用ntp協議實現;
(2) 節點間須要經過主機名互相通訊,必須解析主機至IP地址;
(a) 建議名稱解析功能使用hosts文件來實現;
(b) 通訊中使用的名字與節點名字必須保持一致:「uname -n」命令,或「hostname」展現出的名字保持一致;
(3) 考慮仲裁設備是否會用到;
(4) 創建各節點之間的root用戶可以基於密鑰認證;
# ssh-keygen -t rsa -P ''
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@HOSTNAME
注意:定義成爲集羣服務中的資源,必定不能開機自動啓動;由於它們將由crm管理;
HA Cluster的工做模型:
A/P:兩節點集羣,active, passive;工做於主備模型;
HA Service一般只有一個:HA resources可能會有多個;
A/A:兩節點集羣,active/active,工做於雙方模型;
N-M: N個節點,M個服務;一般N>M;
N-N:N個節點,N個服務;
資源運行的傾向性:
rgmanager:
failover domain, node priority
pacemaker:
資源黏性:運行於當前節點的傾向性;
資源約束:
位置約束:資源對運行於某節點的傾向性
inf: 正無窮
-inf: 負無窮
n:
-n:
排列約束:資源運行於一處的傾向性
inf
-inf
n
-n
順序約束:啓動的前後順序
A --> B --> C
C --> B --> A
DC: Designated Coordinator
corosync:
AIS: Application Interface Standard,
SA Forum: OpenAIS
OpenAIS: 提供了一種集羣模式,包含集羣框架、集羣成員管理、通訊方式、集羣監測,但沒有集羣資源管理功能;
組件包括:AMF, CLM, CPKT, EVT等;分支不一樣,包含的組件略有區別;
分支:picacho, whitetank, wilson,
corosync (集羣管理引擎)
只是openais的一個子組件;
分裂成爲兩個項目:
corosync, wilson(ais的接口標準)
CentOS 5:
cman + rgmanager
CentOS 6:
cman + rgmanager
corosync + pacemaker
命令行管理工具:
crmsh: suse, CentOS 6.4-
pcs: RedHat, CentOS 6.5+
crm的經常使用子命令:
status
node
configure
ra
resource
configure經常使用的子命令:
primitive
group
clone
ms
location
colocation
order
show
property
primitive <rsc_id> class:provider:ra params param1=value1 param2=value2 op op1 param1=value op op2 parma1=value1
二 測試heartbeat+httpd
基本環境設置
10.10.10.50/24 node1.test.com node1
10.10.10.51/24 node2.test.com node2
10.10.10.5/24 vip
關閉iptables
service iptables stop chkconfig iptables off
關閉selinx
vim /etc/selinux/config SELINUX=disabled
修改主機名
vim /etc/sysconfig/network HOSTNAME=node2.test.com vim /etc/hosts 10.10.10.50 node1.test.com node1 10.10.10.51 node2.test.com node2 reboot
[root@node1 ~]# uname -n node1.test.com [root@node2 ~]# uname -n node2.test.com
安裝httpd
yum install httpd [root@node1 ~]# vim /var/www/html/index.html node1.test.com 10.10.10.50 [root@node2 ~]# vim /var/www/html/index.html node2.test.com 10.10.10.51 service httpd start
測試打開 http://10.10.10.50
service httpd stop
準備ssh 信任(不用輸帳號密碼進入系統)
cd ~ ssh-keygen -t rsa ssh-copy-id localhost ssh node2 cat ~/.ssh/id_rsa.pub >>.ssh/authorized_keys scp .ssh/authorized_keys node2:~/.ssh/
安裝heartbeat
設置epel源 libnet在epel
wget http://mirrors.aliyun.com/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -ivh epel-release-6-8.noarch.rpm yum install net-snmp-libs libnet PyXML libtool-ltdl rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
配置heartbeat
cd /etc/ha.d/ cp -r /usr/share/doc/heartbeat-2.1.4/ /etc/ha.d/ cp ./heartbeat-2.1.4/{ha.cf,authkeys,haresources} ./ chmod 600 authkeys
vim authkeys auth 2 #1 crc 2 sha1 password #3 md5 Hello!
vim ha.cf debugfile /var/log/ha-debug #logfacility local0 keepalive 2 deadtime 30 warntime 10 udpport 694 mcast eth0 225.10.0.1 694 1 0 auto_failback on node node1.test.com node node2.test.com ping 10.10.10.2 compression bz2 compression_threshold 2
vim haresources node1.test.com 10.10.10.5/24/eth0/10.10.10.254 httpd
scp -p ha.cf haresources authkeys node2:/etc/ha.d/ service heartbeat start;ssh node2 service heartbeat start
查看實時生成的日誌
tail -f /var/log/ha-debug
檢測運行狀態,全部資源在node1上 ,node2 上只有heartbeat服務
[root@node1 ha.d]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr:10.10.10.50 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1469 errors:0 dropped:0 overruns:0 frame:0 TX packets:1324 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:178040 (173.8 KiB) TX bytes:235325 (229.8 KiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr:10.10.10.5 Bcast:10.10.10.254 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:61 errors:0 dropped:0 overruns:0 frame:0 TX packets:61 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:12332 (12.0 KiB) TX bytes:12332 (12.0 KiB) [root@node1 ha.d]# netstat -nlptu|grep 80 tcp 0 0 :::80 :::* LISTEN 3056/httpd [root@node1 ha.d]# ps aux |grep http root 3056 0.0 0.3 175276 3736 ? Ss 20:00 0:00 /usr/sbin/httpd apache 3060 0.0 0.2 175276 2460 ? S 20:00 0:00 /usr/sbin/httpd apache 3061 0.0 0.2 175276 2444 ? S 20:00 0:00 /usr/sbin/httpd apache 3062 0.0 0.2 175276 2444 ? S 20:00 0:00 /usr/sbin/httpd apache 3063 0.0 0.2 175276 2444 ? S 20:00 0:00 /usr/sbin/httpd apache 3064 0.0 0.2 175276 2444 ? S 20:00 0:00 /usr/sbin/httpd apache 3065 0.0 0.2 175276 2444 ? S 20:00 0:00 /usr/sbin/httpd apache 3066 0.0 0.2 175276 2444 ? S 20:00 0:00 /usr/sbin/httpd apache 3067 0.0 0.2 175276 2444 ? S 20:00 0:00 /usr/sbin/httpd root 3111 0.0 0.0 103304 896 pts/0 S+ 20:01 0:00 grep http [root@node1 ha.d]# ps aux |grep heartbeat root 2662 0.0 1.4 65496 14348 ? SLs 19:59 0:00 heartbeat: master control process nobody 2666 0.0 0.7 58764 7616 ? SL 19:59 0:00 heartbeat: FIFO reader nobody 2667 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: write: mcast eth0 nobody 2668 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: read: mcast eth0 nobody 2669 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: write: ping 10.10.10.2 nobody 2670 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: read: ping 10.10.10.2 root 3114 0.0 0.0 103304 896 pts/0 S+ 20:01 0:00 grep heartbeat [root@node2 ha.d]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:05:71:E9 inet addr:10.10.10.51 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe05:71e9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:22144 errors:0 dropped:0 overruns:0 frame:0 TX packets:16634 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:24037006 (22.9 MiB) TX bytes:7355584 (7.0 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:61 errors:0 dropped:0 overruns:0 frame:0 TX packets:61 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:26550 (25.9 KiB) TX bytes:26550 (25.9 KiB) [root@node2 ha.d]# netstat -nlptu|grep 80 [root@node2 ha.d]# ps aux |grep http root 2823 0.0 0.0 103308 856 pts/0 S+ 20:02 0:00 grep http [root@node2 ha.d]# ps aux |grep heartbeat root 2733 0.0 1.4 65496 14348 ? SLs 19:59 0:00 heartbeat: master control process nobody 2738 0.0 0.7 58764 7616 ? SL 19:59 0:00 heartbeat: FIFO reader nobody 2739 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: write: mcast eth0 nobody 2740 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: read: mcast eth0 nobody 2741 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: write: ping 10.10.10.2 nobody 2742 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: read: ping 10.10.10.2 root 2825 0.0 0.0 103308 856 pts/0 S+ 20:02 0:00 grep heartbeat
打開網頁 http://10.10.10.5
中止第一個節點
[root@node1 ha.d]# service heartbeat stop Stopping High-Availability services: Done.
node1節點服務器所有中止 ,全部服務轉移到node2
[root@node2 ha.d]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:05:71:E9 inet addr:10.10.10.51 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe05:71e9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:22411 errors:0 dropped:0 overruns:0 frame:0 TX packets:16943 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:24082852 (22.9 MiB) TX bytes:7416808 (7.0 MiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:05:71:E9 inet addr:10.10.10.5 Bcast:10.10.10.254 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:61 errors:0 dropped:0 overruns:0 frame:0 TX packets:61 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:26550 (25.9 KiB) TX bytes:26550 (25.9 KiB) [root@node2 ha.d]# netstat -nlptu|grep 80 tcp 0 0 :::80 :::* LISTEN 3139/httpd [root@node2 ha.d]# ps aux |grep http root 3139 0.0 0.3 175276 3736 ? Ss 20:05 0:00 /usr/sbin/httpd apache 3141 0.0 0.2 175276 2460 ? S 20:05 0:00 /usr/sbin/httpd apache 3143 0.0 0.2 175276 2444 ? S 20:05 0:00 /usr/sbin/httpd apache 3145 0.0 0.2 175276 2444 ? S 20:05 0:00 /usr/sbin/httpd apache 3146 0.0 0.2 175276 2444 ? S 20:05 0:00 /usr/sbin/httpd apache 3149 0.0 0.2 175276 2444 ? S 20:05 0:00 /usr/sbin/httpd apache 3151 0.0 0.2 175276 2444 ? S 20:05 0:00 /usr/sbin/httpd apache 3153 0.0 0.2 175276 2444 ? S 20:05 0:00 /usr/sbin/httpd apache 3157 0.0 0.2 175276 2444 ? S 20:05 0:00 /usr/sbin/httpd root 3168 0.0 0.0 103308 856 pts/0 S+ 20:06 0:00 grep http [root@node2 ha.d]# ps aux |grep heartbeat root 2733 0.0 1.4 65496 14348 ? SLs 19:59 0:00 heartbeat: master control process nobody 2738 0.0 0.7 58764 7616 ? SL 19:59 0:00 heartbeat: FIFO reader nobody 2739 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: write: mcast eth0 nobody 2740 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: read: mcast eth0 nobody 2741 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: write: ping 10.10.10.2 nobody 2742 0.0 0.7 58892 7744 ? SL 19:59 0:00 heartbeat: read: ping 10.10.10.2 root 3170 0.0 0.0 103308 852 pts/0 S+ 20:06 0:00 grep heartbeat
打開網頁 http://10.10.10.5
從新開啓node1
[root@node1 ha.d]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr:10.10.10.50 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2457 errors:0 dropped:0 overruns:0 frame:0 TX packets:2066 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:299678 (292.6 KiB) TX bytes:365721 (357.1 KiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr:10.10.10.5 Bcast:10.10.10.254 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:61 errors:0 dropped:0 overruns:0 frame:0 TX packets:61 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:12332 (12.0 KiB) TX bytes:12332 (12.0 KiB) [root@node1 ha.d]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr:10.10.10.50 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2465 errors:0 dropped:0 overruns:0 frame:0 TX packets:2071 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:300586 (293.5 KiB) TX bytes:367585 (358.9 KiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr:10.10.10.5 Bcast:10.10.10.254 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:61 errors:0 dropped:0 overruns:0 frame:0 TX packets:61 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:12332 (12.0 KiB) TX bytes:12332 (12.0 KiB) [root@node1 ha.d]# netstat -nlptu|grep 80 tcp 0 0 :::80 :::* LISTEN 3693/httpd [root@node1 ha.d]# ps aux |grep http root 3693 0.0 0.3 175276 3728 ? Ss 20:07 0:00 /usr/sbin/httpd apache 3695 0.0 0.2 175276 2460 ? S 20:07 0:00 /usr/sbin/httpd apache 3696 0.0 0.2 175276 2444 ? S 20:07 0:00 /usr/sbin/httpd apache 3698 0.0 0.2 175276 2444 ? S 20:07 0:00 /usr/sbin/httpd apache 3700 0.0 0.2 175276 2444 ? S 20:07 0:00 /usr/sbin/httpd apache 3701 0.0 0.2 175276 2444 ? S 20:07 0:00 /usr/sbin/httpd apache 3702 0.0 0.2 175276 2444 ? S 20:07 0:00 /usr/sbin/httpd apache 3703 0.0 0.2 175276 2444 ? S 20:07 0:00 /usr/sbin/httpd apache 3704 0.0 0.2 175276 2444 ? S 20:07 0:00 /usr/sbin/httpd root 3713 0.0 0.0 103304 896 pts/0 S+ 20:07 0:00 grep http [root@node1 ha.d]# ps aux |grep heartbeat root 3405 0.0 1.4 65496 14348 ? SLs 20:07 0:00 heartbeat: master control process nobody 3410 0.0 0.7 58764 7616 ? SL 20:07 0:00 heartbeat: FIFO reader nobody 3411 0.0 0.7 58892 7744 ? SL 20:07 0:00 heartbeat: write: mcast eth0 nobody 3412 0.0 0.7 58892 7744 ? SL 20:07 0:00 heartbeat: read: mcast eth0 nobody 3413 0.0 0.7 58892 7744 ? SL 20:07 0:00 heartbeat: write: ping 10.10.10.2 nobody 3414 0.0 0.7 58892 7744 ? SL 20:07 0:00 heartbeat: read: ping 10.10.10.2 root 3715 0.0 0.0 103308 896 pts/0 S+ 20:07 0:00 grep heartbeat
全部資源又所有轉移到node1
三 測試heartbeat+httpd+nfs
開啓新的服務器,版本爲cenos 7.1 ip地址爲10.10.10.60
關閉iptables
systemctl stop firewalld systemctl disable firewalld
關閉selinx
vim /etc/selinux/config SELINUX=disabled
安裝nfs
m install nfs*
建立nfs共享文件目錄和文件
mkdir -p /home/data/html vim /home/data/html/index.html html on nfs server 10.10.10.60
配置nfs
vim /etc/exports /home/data 10.10.10.0/24(rw,no_root_squash) exportfs -arv
啓動nfs
systemctl start nfs-server systemctl status nfs-server
在node1 node2 上手動掛載測試
[root@node1 ha.d]# mount -t nfs 10.10.10.60:/home/data/html /var/www/html [root@node1 ha.d]# cat /var/www/html/index.html html on nfs server 10.10.10.60 [root@node1 ha.d]# umount /var/www/html
[root@node2 ha.d]# mount -t nfs 10.10.10.60:/home/data/html /var/www/html [root@node2 ha.d]# cat /var/www/html/index.html html on nfs server 10.10.10.60 [root@node2 /]# umount /var/www/html
修改heartbeat 設置
[root@node1 ha.d]# vim haresources node1.test.com 10.10.10.5/24 Filesystem::10.10.10.60:/home/data/html::/var/www/html::nfs httpd
複製到node2並啓動服務
scp haresources node2:/etc/ha.d/ service heartbeat start;ssh node2 service heartbeat start
node1節點 檢查
[root@node1 ha.d]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr:10.10.10.50 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4330 errors:0 dropped:0 overruns:0 frame:0 TX packets:3581 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:561109 (547.9 KiB) TX bytes:658645 (643.2 KiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr:10.10.10.5 Bcast:10.10.10.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:61 errors:0 dropped:0 overruns:0 frame:0 TX packets:61 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:12332 (12.0 KiB) TX bytes:12332 (12.0 KiB) [root@node1 ha.d]# netstat -nlptu|grep 80 tcp 0 0 :::80 :::* LISTEN 4808/httpd [root@node1 ha.d]# ps aux |grep http root 4808 0.0 0.3 175276 3736 ? Ss 20:24 0:00 /usr/sbin/httpd apache 4810 0.0 0.2 175276 2460 ? S 20:24 0:00 /usr/sbin/httpd apache 4811 0.0 0.2 175276 2444 ? S 20:24 0:00 /usr/sbin/httpd apache 4814 0.0 0.2 175276 2444 ? S 20:24 0:00 /usr/sbin/httpd apache 4815 0.0 0.2 175276 2444 ? S 20:24 0:00 /usr/sbin/httpd apache 4816 0.0 0.2 175276 2444 ? S 20:24 0:00 /usr/sbin/httpd apache 4817 0.0 0.2 175276 2444 ? S 20:24 0:00 /usr/sbin/httpd apache 4818 0.0 0.2 175276 2444 ? S 20:24 0:00 /usr/sbin/httpd apache 4819 0.0 0.2 175276 2444 ? S 20:24 0:00 /usr/sbin/httpd root 4826 0.0 0.0 103304 896 pts/0 S+ 20:25 0:00 grep http [root@node1 ha.d]# ps aux |grep heartbeat root 4272 0.0 1.4 65496 14348 ? SLs 20:24 0:00 heartbeat: master control process nobody 4278 0.0 0.7 58764 7616 ? SL 20:24 0:00 heartbeat: FIFO reader nobody 4279 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: write: mcast eth0 nobody 4280 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: read: mcast eth0 nobody 4281 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: write: ping 10.10.10.2 nobody 4282 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: read: ping 10.10.10.2 root 4828 0.0 0.0 103304 896 pts/0 S+ 20:25 0:00 grep heartbeat node2節點 [root@node2 /]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:05:71:E9 inet addr:10.10.10.51 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe05:71e9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:23901 errors:0 dropped:0 overruns:0 frame:0 TX packets:18324 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:24337685 (23.2 MiB) TX bytes:7683518 (7.3 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:61 errors:0 dropped:0 overruns:0 frame:0 TX packets:61 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:26550 (25.9 KiB) TX bytes:26550 (25.9 KiB) [root@node2 /]# netstat -nlptu|grep 80 [root@node2 /]# ps aux |grep http root 3735 0.0 0.0 103308 852 pts/0 S+ 20:26 0:00 grep http [root@node2 /]# ps aux |grep heartbeat root 3684 0.0 1.4 65496 14348 ? SLs 20:24 0:00 heartbeat: master control process nobody 3689 0.0 0.7 58764 7616 ? SL 20:24 0:00 heartbeat: FIFO reader nobody 3690 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: write: mcast eth0 nobody 3691 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: read: mcast eth0 nobody 3692 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: write: ping 10.10.10.2 nobody 3693 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: read: ping 10.10.10.2 root 3739 0.0 0.0 103308 852 pts/0 S+ 20:27 0:00 grep heartbeat
打開網頁 http://10.10.10.5
中止第一個節點
[root@node1 ha.d]# service heartbeat stop Stopping High-Availability services: Done.
node1節點服務器所有中止 ,全部服務轉移到node2
[root@node2 /]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:05:71:E9 inet addr:10.10.10.51 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe05:71e9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:24306 errors:0 dropped:0 overruns:0 frame:0 TX packets:18704 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:24389056 (23.2 MiB) TX bytes:7747299 (7.3 MiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:05:71:E9 inet addr:10.10.10.5 Bcast:10.10.10.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:61 errors:0 dropped:0 overruns:0 frame:0 TX packets:61 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:26550 (25.9 KiB) TX bytes:26550 (25.9 KiB) [root@node2 /]# netstat -nlptu|grep 80 tcp 0 0 :::80 :::* LISTEN 4197/httpd [root@node2 /]# ps aux |grep http root 4197 0.0 0.3 175276 3728 ? Ss 20:27 0:00 /usr/sbin/httpd apache 4199 0.0 0.2 175276 2460 ? S 20:27 0:00 /usr/sbin/httpd apache 4202 0.0 0.2 175276 2444 ? S 20:27 0:00 /usr/sbin/httpd apache 4203 0.0 0.2 175276 2444 ? S 20:27 0:00 /usr/sbin/httpd apache 4205 0.0 0.2 175276 2444 ? S 20:27 0:00 /usr/sbin/httpd apache 4207 0.0 0.2 175276 2444 ? S 20:27 0:00 /usr/sbin/httpd apache 4210 0.0 0.2 175276 2444 ? S 20:27 0:00 /usr/sbin/httpd apache 4214 0.0 0.2 175276 2444 ? S 20:27 0:00 /usr/sbin/httpd apache 4217 0.0 0.2 175276 2444 ? S 20:27 0:00 /usr/sbin/httpd root 4224 0.0 0.0 103308 856 pts/0 S+ 20:28 0:00 grep http [root@node2 /]# ps aux |grep heartbeat root 3684 0.0 1.4 65496 14348 ? SLs 20:24 0:00 heartbeat: master control process nobody 3689 0.0 0.7 58764 7616 ? SL 20:24 0:00 heartbeat: FIFO reader nobody 3690 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: write: mcast eth0 nobody 3691 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: read: mcast eth0 nobody 3692 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: write: ping 10.10.10.2 nobody 3693 0.0 0.7 58892 7744 ? SL 20:24 0:00 heartbeat: read: ping 10.10.10.2 root 4226 0.0 0.0 103308 856 pts/0 S+ 20:28 0:00 grep heartbeat
刷新網頁 http://10.10.10.5
從新開啓node1
[root@node1 ha.d]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr:10.10.10.50 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5051 errors:0 dropped:0 overruns:0 frame:0 TX packets:4184 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:656248 (640.8 KiB) TX bytes:765685 (747.7 KiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr:10.10.10.5 Bcast:10.10.10.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:61 errors:0 dropped:0 overruns:0 frame:0 TX packets:61 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:12332 (12.0 KiB) TX bytes:12332 (12.0 KiB) [root@node1 ha.d]# netstat -nlptu|grep 80 tcp 0 0 :::80 :::* LISTEN 5614/httpd [root@node1 ha.d]# ps aux |grep http root 5614 0.0 0.3 175276 3724 ? Ss 20:29 0:00 /usr/sbin/httpd apache 5616 0.0 0.2 175276 2456 ? S 20:29 0:00 /usr/sbin/httpd apache 5617 0.0 0.2 175276 2440 ? S 20:29 0:00 /usr/sbin/httpd apache 5619 0.0 0.2 175276 2440 ? S 20:29 0:00 /usr/sbin/httpd apache 5621 0.0 0.2 175276 2440 ? S 20:29 0:00 /usr/sbin/httpd apache 5622 0.0 0.2 175276 2440 ? S 20:29 0:00 /usr/sbin/httpd apache 5623 0.0 0.2 175276 2440 ? S 20:29 0:00 /usr/sbin/httpd apache 5624 0.0 0.2 175276 2440 ? S 20:29 0:00 /usr/sbin/httpd apache 5625 0.0 0.2 175276 2440 ? S 20:29 0:00 /usr/sbin/httpd root 5632 0.0 0.0 103304 896 pts/0 S+ 20:29 0:00 grep http [root@node1 ha.d]# ps aux |grep heartbeat root 5185 0.0 1.4 65496 14348 ? SLs 20:29 0:00 heartbeat: master control process nobody 5188 0.0 0.7 58764 7616 ? SL 20:29 0:00 heartbeat: FIFO reader nobody 5189 0.0 0.7 58892 7744 ? SL 20:29 0:00 heartbeat: write: mcast eth0 nobody 5190 0.0 0.7 58892 7744 ? SL 20:29 0:00 heartbeat: read: mcast eth0 nobody 5191 0.0 0.7 58892 7744 ? SL 20:29 0:00 heartbeat: write: ping 10.10.10.2 nobody 5192 0.0 0.7 58892 7744 ? SL 20:29 0:00 heartbeat: read: ping 10.10.10.2 root 5634 0.0 0.0 103304 896 pts/0 S+ 20:29 0:00 grep heartbeat
全部資源又所有轉移到node1
四 測試heartbeat CRM LAMP Wordpress
安裝mysql 和php
m install mysql-server php php-mysql
測試php
[root@node1 ha.d]# vim /var/www/html/info.php <?php phpinfo(); ?> [root@node1 ha.d]# service httpd start
打開http://10.10.10.50/info.php 測試PHP 信息
[root@node1 ha.d]# service httpd stop
測試mysql
[root@node1 ha.d]# service mysqld start [root@node1 ha.d]# mysql mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec) mysql> exit Bye [root@node1 ha.d]# service mysqld stop
設置mysql data on nfs
在nfs 服務器
mkdir /home/data/mysql
在節點1
mkdir /data vim /etc/my.cnf [mysqld] datadir=/data/ mount -t nfs 10.10.10.60:/home/data/mysql /data /usr/bin/mysql_install_db --user=mysql --datadir=/data/ [root@node1 ha.d]# service mysqld start [root@node1 ha.d]# mysql mysql> create database wordpress; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | | wordpress | +--------------------+ 4 rows in set (0.01 sec) mysql> exit Bye [root@node1 ha.d]# service mysqld stop [root@node1 ha.d]# umount /data
在節點2
[root@node2 /]# mkdir /data [root@node2 /]# vim /etc/my.cnf [mysqld] datadir=/data/ [root@node2 /]# mount -t nfs 10.10.10.60:/home/data/mysql /data [root@node2 /]# /usr/bin/mysql_install_db --user=mysql --datadir=/data/ [root@node2 /]# service mysqld start [root@node2 /]# mysql mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | | wordpress | +--------------------+ 4 rows in set (0.00 sec) mysql> exit Bye [root@node2 /]# service mysqld stop [root@node2 /]# umount /data
安裝 heartbeat-gui
yum install pygtk2-libglade xorg-x11-xauth rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm
echo "password" | passwd --stdin hacluster
yum install xorg-x11-xauth #若是未安裝圖型系統,要安裝此組件,要不xshell報錯 vim /etc/ha.d/ha.cf crm on service heartbeat start;ssh node2 service heartbeat start
在xshell 執行
hb_gui&
鏈接127.0.0.1 安裝gui默認生成hacluster 用戶, 默認無密碼
請使用echo "password" | passwd --stdin hacluster 建立密碼
鏈接成功後如圖顯示
開始添加資源 ,些次添加資源組 名爲wordpress
添加第一個資源名爲 ha_ip
類型爲IPaddr 參數爲 ip 10.10.10.5
添加第二個資源名爲ha_nfs_mysql ,和咱們以前測試時使用的參數一至,爲mysql的共享存儲
類型爲Filesystem
參數爲 device 10.10.10.60:/home/data/mysql
directory /data
fstype nfs
添加第三個資源名爲ha_nfs_httpd ,和咱們以前測試時使用的參數一至,爲httpd的共享存儲
類型爲Filesystem
參數爲 device 10.10.10.60:/home/data/html
directory /var/www/html
fstype nfs
添加第四個資源名爲ha_mysql
類型爲咱們安裝的mysqld ,不須要參數
添加第五個資源名爲ha_httpd
類型爲咱們安裝的httpd ,不須要參數
添加主機colocations ,爲資源起動全部的位置
第一個爲,ha_ip ha_nfs_mysql 必須在同一個node上
第一個爲,ha_ip ha_nfs_httpd 必須在同一個node上
第一個爲,ha_mysql ha_nfs_mysql 必須在同一個node上
第一個爲,ha_httpd ha_nfs_httpd 必須在同一個node上
以上設置保證全部資源啓動在同一個node上,根據須要修改。
添加資源order,意爲資源的啓動順序
第一個爲, ha_ip 比ha_nfs_mysql先啓動
若是不能啓動ha_ip ,則不啓動ha_nfs_mysql
中止時,先中止ha_nfs_mysql ,後中止ha_ip
若是不能中止ha_nfs_mysql,則不中止ha_ip
第二個爲, ha_ip 比ha_nfs_httpd先啓動
若是不能啓動ha_ip ,則不啓動ha_nfs_httpd
中止時,先中止ha_nfs_httpd ,後中止ha_ip
若是不能中止ha_nfs_httpd,則不中止ha_ip
第三個爲, ha_nfs_mysql 比ha_mysql先啓動
若是不能啓動ha_nfs_mysql ,則不啓動ha_mysql
中止時,先中止ha_mysql ,後中止ha_nfs_mysql
若是不能中止ha_mysql,則不中止ha_nfs_mysql
第四個爲, ha_nfs_httpd 比ha_httpd先啓動
若是不能啓動ha_nfs_httpd ,則不啓動ha_httpd
中止時,先中止ha_httpd,後中止ha_nfs_httpd
若是不能中止ha_httpd,則不中止ha_nfs_httpd
右鍵ha_wordpress ,start 啓動ha_wordpress資源
以上配置啓動順序爲 ha_ip --> ha_nfs_mysql --> ha_mysql
ha_ip --> ha_nfs_httpd--> ha_httpd
右鍵節點node2 standby
資源所有轉移動node1
安裝wordpress
wget https://cn.wordpress.org/wordpress-4.3.1-zh_CN.zip
unzip wordpress-4.3.1-zh_CN.zip
cp -rf wordpress/ /var/www/html/
http://10.10.10.5/wordpress/wp-admin/setup-config.php
若是沒有設置權限 ,
cd /var/www/html/
vim wp-config.php
複製上圖中生成的代碼,而後點擊進行安裝。
發表一個博客
設置node2 爲 standby
結果刷新後發表的內容也能夠顯示