Heartbeat高可用http
-
實驗圖
-
heartbeat高可用http
一、實驗圖:
二、heartbeat高可用http(Heartbeat V1 haresource)
-
heartbeat節點ssh互信
-
heartbeat節點名稱相互解析,uname -n
-
heartbeat節點時間一致性
安裝前準備:
ssh多節點互信
[root@node4 ~]# ssh-keygen -t rsa [root@node4 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node3 root@node3's password: Now try logging into the machine, with "ssh 'root@node3'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. [root@node4 ~]#
節點時間一致檢查
[root@node4 ~]# ntpdate 192.168.3.10 [root@node4 ~]# ssh node3 'date';date Mon Jul 4 20:30:39 CST 2016 Mon Jul 4 20:30:39 CST 2016 [root@node4 ~]#
多節點名稱解析
[root@node4 ~]# ssh node3 'uname -n';uname -n node3 node4 [root@node4 ~]#
安裝heartbeat:
[root@node4 ~]# yum install perl-TimeDate PyXML libnet net-snmp-libs libtool-ltdl -y [root@node4 ~]# 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 [root@node3 ~]# yum install perl-TimeDate PyXML libnet net-snmp-libs libtool-ltdl -y [root@node3 ~]# 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配置文件:
[root@node4 ~]# cd /usr/share/doc/heartbeat-2.1.4/ [root@node4 heartbeat-2.1.4]# cp authkeys ha.cf haresources /etc/ha.d/ [root@node4 heartbeat-2.1.4]# cd /etc/ha.d/ [root@node4 ha.d]# [root@node4 ha.d]# vi authkeys #配置雙節點心跳信息通信密碼 auth 3 3 md5 Hello!manager1 [root@node4 ha.d]# vi ha.cf logfile /var/log/ha-log #定義日志格式 keepalive 2 deadtime 30 warntime 10 udpport 694 #監聽694端口 mcast eth0 225.0.3.1 694 1 0 #節點多播方式轉發心跳信息 auto_failback on node node3 #heartbeat集群存在節點數 node node4 ping 192.168.3.1 #ping節點仲裁 compression bz2 compression_threshold 2 [root@node4 ha.d]# chmod 600 authkeys #修改認證密碼文件的權限 [root@node4 ha.d]# vi haresources node4 192.168.3.50/24/eth0 httpd #以node4節點為dc,并且定義集群VIP與資源http服務 [root@node4 ha.d]# scp ha.cf haresources authkeys node3:/etc/ha.d/ #node3節點也需要此配置 ha.cf 100% 10KB 10.3KB/s 00:00 haresources 100% 5939 5.8KB/s 00:00 authkeys 100% 651 0.6KB/s 00:00 [root@node4 ha.d]#
安裝httpd服務:
[root@node4 ha.d]# yum install httpd -y [root@node4 ha.d]# echo "<h1>nnode4 web server</h1>" > /var/www/html/index.html [root@node4 ha.d]# chkconfig httpd off #關閉http服務開機自啟動 [root@node4 ha.d]# service httpd stop #關閉http服務,因為資源服務的啟動都是有heartbeat來完成 Stopping httpd: [ OK ] [root@node4 ha.d]# [root@node3 ha.d]# yum install httpd -y [root@node3 ha.d]# echo "<h1>nnode3 web server</h1>" > /var/www/html/index.html [root@node3 ~]# chkconfig httpd off [root@node3 ~]# service httpd stop Stopping httpd: [ OK ] [root@node3 ~]#
啟動heartbeat服務,并測試:
[root@node4 ha.d]# service heartbeat restart Stopping High-Availability services: Done. Waiting to allow resource takeover to complete: Done. Starting High-Availability services: 2016/07/04_20:59:23 INFO: Resource is stopped Done. [root@node4 ha.d]# [root@node3 ~]# service heartbeat restart #我在node3啟動heartbeat時,報錯,檢查報錯是認證文件的權限不對,修改修改權限為600就可以了 Stopping High-Availability services: Done. Waiting to allow resource takeover to complete: Done. Starting High-Availability services: 2016/07/04_21:00:13 INFO: Resource is stopped Heartbeat failure [rc=6]. Failed. heartbeat: udpport setting must precede media statementsheartbeat[2154]: 2016/07/04_21:00:13 ERROR: Ba d permissions on keyfile [/etc/ha.d/authkeys], 600 recommended.heartbeat[2154]: 2016/07/04_21:00:13 ERROR: Authentication configuration error. heartbeat[2154]: 2016/07/04_21:00:13 ERROR: Configuration error, heartbeat not started. [root@node3 ha.d]# chmod 600 authkeys [root@node3 ha.d]# service heartbeat restart Stopping High-Availability services: Done. Waiting to allow resource takeover to complete: Done. Starting High-Availability services: 2016/07/04_21:01:51 INFO: Resource is stopped Done. [root@node3 ha.d]#
ns1測試:
[root@ns1 ~]# curl 192.168.3.50 <h1>nnode4 web server</h1> [root@ns1 ~]#
這一部分到此OK,接著做.
二、heartbeat高可用http(Heartbeat V2 crm heartbeat gui工具)
修改配置:
[root@node4 ha.d]# service heartbeat stop [root@node3 ha.d]# service heartbeat stop [root@node4 ha.d]# vi ha.cf crm on [root@node3 ha.d]# vi ha.cf crm on
安裝heartbeat-gui工具:
[root@node4 ~]# yum install pygtk2-libglade [root@node4 ~]# rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm [root@node3 ~]# yum install pygtk2-libglade [root@node4 ~]# rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm
啟動heartbeat服務:
[root@node4 ~]# service heartbeat start [root@node3 ~]# service heartbeat start [root@node4 ~]# passwd hacluster #此用戶使我們在安裝heartbeat-gui時創建,我們登錄gui時需要此用戶和密碼,默認沒有密碼,需要我們設置,才能準確登錄gui [root@node3 ~]# passwd hacluster [root@node4 ~]# hb_gui & #打開gui工具報錯,gui工具是監聽在5560端口,如果打不開,可以檢查此端口是否監聽 [1] 2810 [root@node4 ~]# Traceback (most recent call last): File "/usr/bin/hb_gui", line 41, in <module> import gtk, gtk.glade, gobject File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module> _init() File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init _gtk.init_check()RuntimeError: could not open display X11-forward報錯 需要安裝如下包,安裝完成之后重新登錄shell即可 [root@node4 ~]# yum install -y xorg-x11-xauth [root@node4 ~]# hb_gui & node3不知道為什么報錯了,直接killall heartbeat 系統重啟,之后就可以了。
測試gui工具:
設置http服務:
接著添加web_vip,有順序,先啟動的資源,先添加,后啟動的資源后添加,那我們應該先啟動IP,接著再去啟動http服務
測試web服務:
[root@ns1 ~]# curl 192.168.3.50 <h1>nnode4 web server</h1>
修改node4為standby:
服務已經發生切換:
[root@ns1 ~]# curl 192.168.3.50 <h1>nnode3 web server</h1>
設置共享存儲:
[root@ns1 ~]# exportfs -arv exporting 192.168.3.0/24:/www/htdocs [root@ns1 ~]# echo "<h1>nfs web server</h1>" > /www/htdocs/index.html
客戶端安裝nfs-utils,并且測試掛載:
[root@node4 ~]# yum install nfs-utils -y [root@node4 ~]# cat /var/www/html/index.html <h1>nfs web server</h1> [root@node4 ~]#
停止資源,重新配置資源組:
測試網頁:
[root@ns1 ~]# curl 192.168.3.50 <h1>nfs web server</h1> [root@ns1 ~]#
設置node3為standby,檢查服務轉移到node4:
Heartbeat高可用mysql在此環境上接著做。
原創文章,作者:nice_neo_linux,如若轉載,請注明出處:http://www.www58058.com/22001
厲害?。。?/p>