色胃康胶囊 发表于 2019-1-3 07:49:14

集群 之 LVS + Heartbeat

  1.安装ipvsadm
  根据内核版本下载相应的ipvsadm的版本。
# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz  
# ln -s /usr/src/kernels/2.6.18-194.el5-i686/ /usr/src/linux
# tar zxvf ipvsadm-1.24.tar.gz
# cd ipvsadm-1.24
# make && make install  检查是否安装成功
  
# ipvsadm --help
ipvsadm v1.24 2005/12/10 (compiled with popt and IPVS v1.2.1)
Usage:
ipvsadm -A|E -t|u|f service-address [-s scheduler] [-p ] [-M netmask]
ipvsadm -D -t|u|f service-address
ipvsadm -C
ipvsadm -R
ipvsadm -S [-n]
ipvsadm -a|e -t|u|f service-address -r server-address
ipvsadm -d -t|u|f service-address -r server-address
ipvsadm -L|l
ipvsadm -Z [-t|u|f service-address]
ipvsadm --set tcp tcpfin udp  若显示帮助信息,则表示安装成功。
  2.安装heartbeat
  heartbeat的安装从3.0版本开始不同,需要先后安装三个包:glub--Resourace Agent--heartbeat
  创建用户和组
  
# groupadd haclient
# useradd -g haclient hacluster  
  1).安装heartbeat之前需要先安装libnet,它是一个高层次的api工具。
  
# wget http://sourceforge.net/projects/libnet-dev/files/libnet-1.1.6.tar.gz
# tar zxvf libnet-1.1.6.tar.gz
# cd libnet-1.1.6
# ./configure
# make && make install  2)安装glub
  安装可能用到的软件包
  
# yum -y install libxslt libxslt-devel libgcrypt-devel autoconf automake pkgconfiglibgpg-error-devel libtool sgml-common opensp openjade xml-commondocbook-dtds docbook-style  
# wget http://hg.linux-ha.org/glue/archive/glue-1.0.9.tar.bz2
# tar jxvf glue-1.0.9.tar.bz2
# cd Reusable-Cluster-Components-glue--glue-1.0.9/
# ./autogen.sh
# ./configure --prefix=/opt/heartbeat
# make && make install  此时容易报错
  
gmake: Entering directory `/root/LVS/Reusable-Cluster-Components-glue--glue-1.0.9/doc'
/usr/bin/xsltproc \
--xinclude \
http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl hb_report.xml
error : Operation in progress
warning: failed to load external entity "http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl"
cannot parse http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
gmake: *** 错误 4
gmake: Leaving directory `/root/LVS/Reusable-Cluster-Components-glue--glue-1.0.9/doc'
gmake: *** 错误 1
gmake: Leaving directory `/root/LVS/Reusable-Cluster-Components-glue--glue-1.0.9/doc'
make: *** 错误 1  解决方法:
  这是由于缺少docbook-style-xsl软件包
  
# yum -y install docbook-style-xsl
# make clean
# make && make install  3)安装Agent
  
# tar zxvf v3.9.2
# cd ClusterLabs-resource-agents-b735277/
# ./autogen.sh
此时提示错误
configure.ac:9: error: Autoconf version 2.63 or higher is required  解决方法如下:
  
# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.gz
# tar zxvf autoconf-2.68.tar.gz
# cd autoconf-2.68
# ./configure
# make && make install  此时再执:
  
# cd ClusterLabs-resource-agents-b735277/
# ./autogen.sh
会提示错误
autoreconf: automake failed with exit status: 1  解决方法如下:
  
wget http://ftp.gnu.org/gnu/automake/automake-1.11.2.tar.gz
tar zxvf automake-1.11.2.tar.gz
cd automake-1.11.2
./configure
make && make install  
# ./autogen.sh
# ./configure
# make && make install
会提示错误如下  
gmake: *** 错误 127
../heartbeat/IPv6addr: error while loading shared libraries: libplumb.so.2: cannot open shared object file: No such file or directory
gmake: Leaving directory `/root/LVS/ClusterLabs-resource-agents-b735277/doc'
gmake: *** 错误 1
gmake: Leaving directory `/root/LVS/ClusterLabs-resource-agents-b735277'
make: *** 错误 2  
  解决方法如下:
  
./configure --prefix=/opt/heartbeat/ CFLAGS=-I/opt/heartbeat/include LDFLAGS=-L/opt/heartbeat/lib LIBS='/lib/libuuid.so.1'
# vim /etc/ld.so.conf
/usr/local/lib
/opt/heartbeat/lib/
#ldconfig  
  这两个是在3.0版本编译时常碰到的错误
  
  4)安装heartbeat
  
# wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/7e3a82377fa8.tar.bz2
# tar jxvf 7e3a82377fa8.tar.bz2
# cd Heartbeat-3-0-7e3a82377fa8/
# ./bootstrap
# ./ConfigureMe configure --prefix=/opt/heartbeat/
# make && make install  此时由于安装路径不是采用默认的,而是指定为安装/opt/heartbeat就会出现找不到库文件的问题
  
In file included from ../include/lha_internal.h:41,
from strlcpy.c:1:
/prog/heartbeat/include/heartbeat/glue_config.h:50:1: error: "HA_SYSCONFDIR" redefined
In file included from ../include/lha_internal.h:38,
from strlcpy.c:1:
../include/config.h:401:1: error: this is the location of the previous definition
In file included from ../include/lha_internal.h:41,
from strlcpy.c:1:
/prog/heartbeat/include/heartbeat/glue_config.h:105:1: error: "HA_HBCONF_DIR" redefined
In file included from ../include/lha_internal.h:38,
from strlcpy.c:1:
../include/config.h:386:1: error: this is the location of the previous definition
gmake: *** Error 1
gmake: Leaving directory `/prog/heartbeat-3-0-7/replace'
make: *** Error 1  解决此错误的方法为:
  到opt/heartbeat/include/heartbeak/glue_config.h文件中把第50行,第105行的内容删除即可
  本次对heartbeat安装了两次,建议安装时采用默认的安装路径。
  安装一个插件
  
# yum -y install perl-Socket6 perl-libwww-perl perl-URI perl-MailTools perl-HTML-Parser  
  3.创建heartbeat的配置文件
  
# cp /opt/heartbeat/share/doc/heartbeat/ha.cf /etc/ha.d/
# cp /opt/heartbeat/share/doc/heartbeat/authkeys /etc/ha.d/
# cp /opt/heartbeat/share/doc/heartbeat/haresources /etc/ha.d/
# cp /opt/heartbeat/etc/ha.d/shellfuncs /etc/ha.d/
# cp LVS/Heartbeat-3-0-7e3a82377fa8/heartbeat/init.d/heartbeat /etc/rc.d/init.d/
# chkconfig --add heartbeat  ha.cf :heartbeat的主配置文件
  authkeys:双机互连的验证文件
  haresources:集群资源文件。
  4.修改配置文件
  
  
  在主机zhu3上的配置
# vim /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility   local0
keepalive 8
deadtime 60
warntime 60
initdead 120
udpport 694
baud    19200
ucast eth0 192.168.70.135
auto_failback on
node    zhu3
node    zhu1
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster  
# vim /etc/ha.d/authkeys
auth 1
1 crc  
# vim haresources
zhu3 lvs IPaddr::192.168.70.70/24/eth0 ldirectord  
root@zhu3 ha.d]# vim /etc/init.d/lvs
#!/bin/bash
VIP=192.168.70.70
/etc/rc.d/init.d/functions
/sbin/ipvsadm --set 10 10 10
case "$1" in
start)
/sbin/ifconfig lo:0 down
/sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev eth0:0
;;
stop)
/sbin/ifconfig eth0:0 down
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac  chmod +x /etc/init.d/lvs
  
# serive heartbeat start
# ip a
1: lo:mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0:mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:d3:3b:5e brd ff:ff:ff:ff:ff:ff
inet 192.168.70.133/24 brd 192.168.70.255 scope global eth0
inet 192.168.70.70/24 brd 192.168.70.255 scope global secondary eth0:2
inet6 fe80::20c:29ff:fed3:3b5e/64 scope link
valid_lft forever preferred_lft forever
3: sit0:mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0  在主机zhu1上的配置
  ......
  
  由于zhu1上的安装路径是在/opt/heartbeat/下,所以在启动时常见的错误有
  
  
# service heartbeat start
/etc/init.d/heartbeat: line 53: /etc/ha.d/shellfuncs: 没有那个文件或目录
解决方法:
# cp /opt/heartbeat/etc/ha.d/shellfuncs /etc/ha.d/
# service heartbeat start
/etc/ha.d/shellfuncs: line 96: /usr/lib/ocf/lib//heartbeat/ocf-shellfuncs: 没有那个文件或目录
修改文件中行的路径
. /opt/heartbeat/usr/lib/ocf/lib//heartbeat/ocf-shellfuncs
# ln -s /opt/heartbeat/usr/lib/ocf /usr/lib/ocf  
  测试高可用性
  
# ip a
1: lo:mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0:mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:d3:3b:5e brd ff:ff:ff:ff:ff:ff
inet 192.168.70.133/24 brd 192.168.70.255 scope global eth0
inet 192.168.70.70/24 brd 192.168.70.255 scope global secondary eth0:2
inet6 fe80::20c:29ff:fed3:3b5e/64 scope link
valid_lft forever preferred_lft forever
3: sit0:mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0  
root@zhu1 ~]# ip a
1: lo:mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0:mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:ba:9d:f1 brd ff:ff:ff:ff:ff:ff
inet 192.168.70.135/24 brd 192.168.70.255 scope global eth0
inet6 fe80::20c:29ff:feba:9df1/64 scope link
valid_lft forever preferred_lft forever
3: sit0:mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0  
# service heartbeat stop
Stopping High-Availability services:                     
# ip a
1: lo:mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0:mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:d3:3b:5e brd ff:ff:ff:ff:ff:ff
inet 192.168.70.133/24 brd 192.168.70.255 scope global eth0
inet6 fe80::20c:29ff:fed3:3b5e/64 scope link
valid_lft forever preferred_lft forever
3: sit0:mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0
# ip a
1: lo:mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0:mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:ba:9d:f1 brd ff:ff:ff:ff:ff:ff
inet 192.168.70.135/24 brd 192.168.70.255 scope global eth0
inet 192.168.70.70/24 brd 192.168.70.255 scope global secondary eth0:0
inet6 fe80::20c:29ff:feba:9df1/64 scope link
valid_lft forever preferred_lft forever
3: sit0:mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  



页: [1]
查看完整版本: 集群 之 LVS + Heartbeat