主節點node1:192.168.200.101/24
備節點node2: 192.168.200.102/24
nfs: 192.168.200.103/24
安裝前準備
heartbeat v2
ha web 實例
一、節點名稱修改:
[root@node1 ~]#hostname node1
[root@node1 ~]# uname -n
node1
[root@node1 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=node1html
二、ssh 互相通訊:
[root@node1 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' //自動生成祕鑰
[root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node2 //傳送至節點node2
[root@node1 ~]# ssh node2 'ifconfig' //測試是否能操做節點node2
eth0 Link encap:Ethernet HWaddr 00:0C:29:65:7C:3F
inet addr:192.168.200.102 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe65:7c3f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:469456 errors:0 dropped:0 overruns:0 frame:0
TX packets:632160 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:224664819 (214.2 MiB) TX bytes:339254044 (323.5 MiB)node
node2 節點配置相同,傳送給node1.web
三、主機名解析:
cat /etc/hosts
192.168.200.101 node1
192.168.200.102 node2vim
四、時間同步:
主節點配置:
[root@node1 ~]# yum -y install ntp
[root@node1 ~]# cp -p /etc/ntp.conf /etc/ntp.conf.origin
[root@node1 ~]# vim /etc/ntp.conf
22 server 127.127.1.0 //手動添加此兩行內容
23 fudge 127.127.1.0 startum 8服務器
[root@node1 ~]#service ntpd start
正在啓動 ntpd: [肯定]
[root@node1 ~]#chkconfig ntpd on
從節點配置:
[root@node2 ~]# yum -y instal ntpdate
[root@node2 ~]# ntpdate 192.168.200.101
4 Aug 16:41:16 ntpdate[40441]: adjust time server 192.168.200.101 offset -0.067223 sec
添加計劃任務每5分鐘執行一次。
[root@node2 ~]# crontab -l
*/5 * * * * /sbin/ntpdate 192.168.200.101 &>/dev/null
[root@nfs ~]# crontab -l
*/5 * * * * /sbin/ntpdate 192.168.200.101 &>/dev/nulldom
nfs 和 node2 同樣同步時間與node1時間服務器。ssh
準備的安裝包
[root@node1 heartbeat]# ls
cluster-glue-1.0.5-6.el6.x86_64.rpm perl-TimeDate-1.16-13.el6.noarch.rpm
cluster-glue-libs-1.0.5-6.el6.x86_64.rpm PyXML-0.8.4-19.el6.x86_64.rpm
heartbeat-3.0.4-2.el6.x86_64.rpm resource-agents-3.9.5-24.el6_7.1.x86_64.rpm
heartbeat-libs-3.0.4-2.el6.x86_64.rpm start.sh
lib64ltdl7-2.2.6-6.1mdv2009.1.x86_64.rpm
安裝的順序:
一、rpm -ivh PyXML-0.8.4-19.el6.x86_64.rpm
二、rpm -ivh resource-agents-3.9.5-24.el6_7.1.x86_64.rpmcurl
三、rpm -ivh cluster-glue-libs-1.0.5-6.el6.x86_64.rpm工具
四、rpm -ivh perl-TimeDate-1.16-13.el6.noarch.rpm測試
五、rpm -ivh cluster-glue-1.0.5-6.el6.x86_64.rpm
六、rpm -ivh heartbeat-libs-3.0.4-2.el6.x86_64.rpm heartbeat-3.0.4-2.el6.x86_64.rpm //同時安裝。
備節點node2 安裝順序相同。
安裝後有三個配置文件:
一、祕鑰文件,600,authkeys
二、heartbeat服務的配置文件ha.cf
三、資源管理配置文件:haresources(v2有2個資源管理器一個是crm,另外一個默認v2版本使用haresources做爲資源管理器)
[root@node1 heartbeat-3.0.4]# cd /etc/ha.d/
[root@node1 ha.d]# cp /usr/share/doc/heartbeat-3.0.4/{haresources,authkeys,ha.cf} ./
[root@node1 ha.d]# cat authkeys
#auth 1
#1 crc
#2 sha1 HI!
#3 md5 Hello!
auth 3
3 md5 3c94943451e56d84786bdf5072964350 // dd if=/dev/random cout=1 bs=512 |md5sum 添加一個隨機碼 放到md5 後面。
[root@node1 ha.d]# grep -v "^#" ha.cf
logfacility local0
keepalive 2
bcast eth0 # Linux
auto_failback on
node node1
node node2
[root@node1 ha.d]# cat haresources
node1 IPaddr::192.168.200.254/24/eth0:0 httpd
備節點和主節點配置同樣。
======================================================================
各節點關閉httpd開機自啓,讓heartbeat啓動httpd服務。
service httpd stop
chkconfg httpd off
[root@node1 ~]# echo "node1" > /var/www/html/index.html
[root@node2 ~]# echo "node2" > /var/www/html/index.html
測試:
主節點
[root@node1 html]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:4C:DD:5D
inet addr:192.168.200.101 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe4c:dd5d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8825 errors:0 dropped:0 overruns:0 frame:0
TX packets:4271 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1030060 (1005.9 KiB) TX bytes:723112 (706.1 KiB)
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:4C:DD:5D
inet addr:192.168.200.254 Bcast:192.168.200.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
備節點
[root@node2 ha.d]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:65:7C:3F
inet addr:192.168.200.102 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe65:7c3f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:465233 errors:0 dropped:0 overruns:0 frame:0
TX packets:629414 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:224046430 (213.6 MiB) TX bytes:338744439 (323.0 MiB)
當主節點掛了備節點是否能接過來。
使用heartbeat自帶的測試腳本工具
[root@node1 ha.d]# /usr/share/heartbeat/hb_standby
Going standby [all].
主節點
[root@node1 html]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:4C:DD:5D
inet addr:192.168.200.101 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe4c:dd5d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8825 errors:0 dropped:0 overruns:0 frame:0
TX packets:4271 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1030060 (1005.9 KiB) TX bytes:723112 (706.1 KiB)
備節點
[root@node2 ha.d]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:65:7C:3F
inet addr:192.168.200.102 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe65:7c3f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:465386 errors:0 dropped:0 overruns:0 frame:0
TX packets:629536 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:224070947 (213.6 MiB) TX bytes:338766983 (323.0 MiB)
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:65:7C:3F
inet addr:192.168.200.254 Bcast:192.168.200.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
========================================================================================================
配置nfs
[root@nfs ~]# cat /etc/exports
/web/htdocs 192.168.200.0/24(insecure,ro,no_root_squash)
echo "nfs server" >/web/htdocs/index.html
service rpcbind start
service nfs start
先開啓rpc在開啓nfs 順序不能搞錯。關閉也是先關閉rpc在關閉nfs.[root@node1 ~]# showmount -e 192.168.200.103 //查看掛載狀況Export list for 192.168.200.103:/web/htdocs 192.168.200.0/24[root@node1 ~]# mount 192.168.200.103:/web/htdocs /var/www/html/ //測試手動掛載[root@node1 ~]#umount /var/www/html/ //而後在卸載先中止heartbeat node1 和node2 ,由於資源必須先啓動在服務的前面。而後配置haresources文件,添加Filesystem段nfs服務.[root@node1 ~]# vim /etc/ha.d/haresources node1 IPaddr::192.168.200.254/24/eth0:0 Filesystem::192.168.200.103:/web/htdocs::/var/www/html::nfs httpd========================================================================================================測試服務[root@node1 ~]# curl http://192.168.200.254nfs server[root@node2 ~]# curl http://192.168.200.254nfs server