案例:基於heartbeat v2 crm實現HA LAMP組合;要求:部署wordpress,用於編輯的文章中的任何數據在節點切換後都能正常訪問;
配置HA集羣的前提:
(1)先搭建需要用到的環境:
# yum install net-snmp-libs libnet PyXML
# yum install libnet
# 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已經做出了rpm包,libnet包在eprl源中,請確保安裝epel源,網上可以下到源碼包直接編譯安裝
node1.com IP爲172.16.37.20
node2.com IP爲172.16.37.21
(2)建立各節點之間的root用戶能夠基於密鑰認證
1.Client建立公鑰和私鑰
# ssh-keygen -t rsa -f /root/.ssh/id_rsa -P ''
2.把Client的公鑰發給Server
# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
(3)修改hosts文件,把node1.com和node2.com加入
節點間需要通過主機名互相通信,必須解析主機至IP地址;
(a) 建議名稱解析功能使用hosts文件來實現;
(b) 通信中使用的名字與節點名字必須保持一致:“uname -n”命令,或“hostname”展示出的名字保持一致;
(4)修改主機名
# vim /etc/sysconfig/network
(5)節點間時間必須同步:使用ntp協議實現;
# ntpdate time.windows.com;ssh 172.16.37.21 'ntpdate time.windows.com'
(6)開啓多播模式
# ip link set eth0 multicast on|off
(7)注意:定義成爲集羣服務中的資源,一定不能開機自動啓動;因爲它們將由crm管理;
# chkconfig httpd off
# chkconfig mysqld off
(8) 考慮仲裁設備是否會用到;
修改配置文件
/etc/ha.d目錄下:
# cp /usr/share/doc/heartbeat-2.1.4/ha.cf authkeys /etc/ha.d/
ha.cf: 主配置文件,定義各節點上的heartbeat HA集羣的基本屬性;
authkeys:集羣內節點間彼此傳遞消息時使用加密算法及密鑰;
haresources: 爲heartbeat v1提供資源管理器配置接口;v1版本專用的配置接口;
(1)編輯authkey文件
先用openssl生成一個隨機數 # openssl rand -base64 16
# vim /etc/ha.d/authkeys
auth 2
#1 crc
2 sha1 Td3P98V5kyv4+OtidCxQ2A
#3 md5 Hello!
[root@node1 ha.d]# chmod 600 authkeys
# chmod 600 /etc/ha.d/authkeys
(2)編輯ha.cf文件
#debugfile /var/log/ha-debug 是否開啓調試功能,已經調試功能的文件位置
logfile /var/log/ha-log 日誌文件的保存位置
#keepalive 1 每個多長時間發送一次心跳信息,默認單位爲s,也支持以ms爲單位
#deadtime 10 在檢測不到對方心跳,替換的時間
#warntime 8 警告時間
#initdead 120啓動heartbeat後多長時間開始檢查心跳
udpport 694 基於那個端口檢測心跳信息
#bcast eth0 # Linux linux廣播的端口
mcast eth0 225.0.10.1 694 1 0 多播的地址
#ucast eth0 192.168.1.2 組播的地址
#compression bz2 壓縮傳輸算法 on 主節點啓動是否自動切換回主節點
ping 172.16.0.1 仲裁設備,可以指向網關
#ping_group group1 10.10.10.25410.10.10.253仲裁設備組
#debug 1debug的級別
#compression_threshold 2壓縮的最低大小,單位爲kb
node node1.com node節點,切記,本處不能使用ip地址
node node2.com node節點,切記,本處不能使用ip地址
crm on 以crm的模塊開啓
爲用戶hacluster創建密碼,在安裝heartbeat-gui時,會自動安裝此用戶
echo 123456 |passwd --stdin hacluster
將配置好的配置文件拷到node2一份
# scp /etc/ha.d/ha.cf /etc/ha.d/authkeys node2.com:/etc/ha.d
準備nfs服務器,並使apache用戶對其有讀寫執行的權限,並準備主頁
# vim /etc/exports
/var/www/html 172.16.0.0/16(rw)
/data/database 172.16.0.0/16(rw)
用service nfs start啓動NFS服務
添加mysql用戶,注意要一致
[root@node2 ~]# groupadd -g 306 mysql
[root@node2 ~]# useradd -g 306 -u 306 mysql
通過圖形界面配置相關信息
# service heartbeat start;ssh node2.com 'service heartbeat start'
# hb_gui &