一、環境
CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64
主(heartbeat27=uname -n)
10.0.0.27(ip) 10.0.10.27(心跳) 10.0.0.29(vip)
備(heartbeat28=uname -n)
10.0.0.28(ip) 10.0.10.28(心跳) 10.0.0.29(vip)
二、cat /etc/hosts
10.0.0.27 heartbeat27
10.0.0.28 heartbeat28html
三、heartbeat27:(主執行)
route add -host 10.0.10.28 dev ens37
route -n
echo '/usr/sbin/route add -host 10.0.10.28 dev ens37' >> /etc/rc.d/rc.local
四、heartbeat28:(備執行)
route add -host 10.0.10.27 dev ens37
route -n
echo '/usr/sbin/route add -host 10.0.10.27 dev ens37' >> /etc/rc.d/rc.localnode
五、下載對應的源碼包並解壓
wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/958e11be8686.tar.bz2
wget http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2
wget https://github.com/ClusterLabs/resource-agents/archive/v3.9.6.tar.gzlinux
tar xf v3.9.6.tar.gz tar jxf 0a7add1d9996.tar.bz2 tar jxf 958e11be8686.tar.bz2
六、安裝基礎的依賴包
yum install gcc gcc-c++ autoconf automake libtool glib2-devel libxml2-devel bzip2 bzip2-devel e2fsprogs-devel libxslt-devel libtool-ltdl-devel -ynginx
asciidoc (yum未安裝成功) asciidoc-8.6.9.tar.gz tar xf asciidoc-8.6.9.tar.gza ./configure make make install
七、安裝上述三個安裝包
groupadd haclient
useradd -g haclient hacluster
7.一、安裝Reusable-Cluster-Components-glue--0a7add1d9996
cd Reusable-Cluster-Components-glue--0a7add1d9996
./autogen.sh (看到 Now run ./configure 表示自動生成完成)
./configure --prefix=/usr/local/heartbeat (必須將Cluster Glue和resource-agents和heartbeat都安裝在同一目錄 由於heartbeat須要依賴這些庫)c++
configure 成功以後的狀態: cluster-glue configuration: Version = 1.0.12 (Build: 0a7add1d9996b6d869d441da6c82fb7b8abcef4f) Features = Prefix = /usr/local/heartbeat Executables = /usr/local/heartbeat/sbin Man pages = /usr/local/heartbeat/share/man Libraries = /usr/local/heartbeat/lib Header files = /usr/local/heartbeat/include Arch-independent files = /usr/local/heartbeat/share Documentation = /usr/local/heartbeat/share/doc/cluster-glue State information = /usr/local/heartbeat/var System configuration = /usr/local/heartbeat/etc Use system LTDL = yes HA group name = haclient HA user name = hacluster
make (可能會報錯,a2x: ERROR: "xmllint" --nonet --noout --valid "/home/Reusable-Cluster-Components-glue--b5f160509785/doc/hb_report.8.xml" returned non-zero exit status 4 gmake[2]: *** [hb_report.8] Error 1 gmake[2]: Leaving directory `/home/Reusable-Cluster-Components-glue--b5f160509785/doc' gmake[1]: *** [all-recursive] Error 1 gmake[1]: Leaving directory `/home/Reusable-Cluster-Components-glue--b5f160509785/doc' make: * [all-recursive] Error 1) 執行此命令 yum -y install docbook-style-xsl make make install
7.二、安裝resource-agents-3.9.6/
cd resource-agents-3.9.6/
./autogen.sh
./configure --prefix=/usr/local/heartbeatgit
configure成功以後: resource-agents configuration: Version = UNKNOWN Build Version = 02beac55c1da0ad99a5a19bd3b2333bcff7e916c Features = Prefix = /usr/local/heartbeat Executables = /usr/local/heartbeat/sbin Man pages = /usr/local/heartbeat/share/man Libraries = /usr/local/heartbeat/lib Header files = /usr/local/heartbeat/include Arch-independent files = /usr/local/heartbeat/share Documentation = /usr/local/heartbeat/share/doc/resource-agents State information = /usr/local/heartbeat/var System configuration = /usr/local/heartbeat/etc HA_BIN directory prefix = /usr/local/heartbeat/libexec RA state files = /usr/local/heartbeat/var/run/resource-agents AIS Plugins = CFLAGS = -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib -ggdb3 -fgnu89-inline -fstack-protector-all -Wall -
ln -s /usr/local/heartbeat/lib/* /lib/ ln -s /usr/local/heartbeat/lib/* /lib64/ make make install
/root/Heartbeat-3-0-958e11be8686':<br/>configure: error: Core development headers were not found<br/>See
config.log' for more details)configure成功以後: heartbeat configuration: Version = "3.0.6" Executables = "/usr/local/heartbeat/sbin" Man pages = "/usr/local/heartbeat/share/man" Libraries = "/usr/local/heartbeat/lib64" Header files = "/usr/local/heartbeat/include" Arch-independent files = "/usr/local/heartbeat/share" Documentation files = "/usr/local/heartbeat/share/doc/heartbeat" State information = "/usr/local/heartbeat/var" System configuration = "/usr/local/heartbeat/etc" Init (rc) scripts = "/etc/rc.d/init.d" Init (rc) defaults = "/etc/sysconfig" Use system LTDL = "yes" HA group name = "haclient" HA group id = "1000" HA user name = "hacluster" HA user user id = "1000" Build dopd plugin = "yes" Enable times kludge = "yes" CC_WARNINGS = " -Wall -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wdeclaration-after-statement -Wpointer-arith -Wwrite-strings -Wcast-qual -Wcast-align -Wbad-function-cast -Winline -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -Wno-strict-aliasing -Werror " Mangled CFLAGS = " -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib -Wall -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wdeclaration-after-statement -Wpointer-arith -Wwrite-strings -Wcast-qual -Wcast-align -Wbad-function-cast -Winline -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -Wno-strict-aliasing -Werror -ggdb3 -funsigned-char" Libraries = "-lbz2 -lz -lc -luuid -lrt -ldl -lltdl" RPATH enabled = "" Distro-style RPMs = "no"
make(錯誤: /usr/local/heartbeat/include/heartbeat/glue_config.h:105:0: error: "HA_HBCONF_DIR" redefined [-Werror]
glue.config.h中 宏 HA_HBCONF_DIR被定義了屢次)
vi 編輯/usr/local/heartbeat/include/heartbeat/glue_config.h 註釋掉最後一行 定義宏的代碼
make
make installgithub
cd /usr/local/heartbeat/share/doc/heartbeat
cp ha.cf authkeys haresources /usr/local/heartbeat/etc/ha.d算法
vim /usr/local/heartbeat/etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694bootstrap
auto_failback on node heartbeat27 node heartbeat28
respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail(此處可能會出現問題:使用find / -name ipfail查找對應的路徑)
ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/RAExec/ /usr/local/heartbeat/lib/heartbeat/plugins/RAExec/
ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/ /usr/local/heartbeat/lib/heartbeat/plugins/vim
vim /usr/local/heartbeat/etc/ha.d/authkeys
修改:
auth 3 表示使用id爲3的驗證 下邊須要定義一個3的驗證算法 #(這裏要保持一致,輸了2下面就對應2,輸了3下面就對應3)
3 md5 Hello! #口令(Hello!)隨便給 主從配置相同便可
chmod 600 /usr/local/heartbeat/etc/ha.d/authkeys
輔助ip
ip addr add 10.0.0.29/24 dev ens33 label ens33:1
vim /usr/local/heartbeat/etc/ha.d/haresources
cd /usr/local/heartbeat/etc/ha.d/
scp authkeys ha.cf haresources root@10.0.0.28:/usr/local/heartbeat/etc/ha.d/ 而後修改新一下文件:
修改ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
auto_failback on node heartbeat27 node heartbeat28
respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail(此處可能會出現問題:使用find / -name ipfail查找對應的路徑) 修改haresources 文件
chmod 600 /usr/local/heartbeat/etc/ha.d/authkeys
安裝nginx(http://www.javashuo.com/article/p-awshfito-mx.html)
修改默認的index.html頁面,作測試(主要是爲了直觀的檢驗有無主動切換)
設置開機自啓動(http://www.javashuo.com/article/p-phfqfkhy-my.html)
啓動nginx
service heartbeat start
service heartbeat status
heartbeat OK [pid 1422 et al] is running on heartbeat27 [heartbeat27]...
瀏覽器中輸入vip (windows中要作解析)
能夠經過關閉主備服務器,觀察頁面呈現的形式,便可。
排版不是很好,解決問題就好!歡迎交流!!