双节点集群IP地址信息:
节点01:ghzy-hr01 172.30.15.84
节点02:ghzy-hr02 172.30.15.85
虚拟IP:172.30.15.83
1、设置主机名;
vim /etc/hostname
设置主机名后,需要重启生效
2、设置hosts主机名解析;
vim /etc/hosts在配置文件中增加以下内容:
172.30.15.84 ghzy-hr01
172.30.15.85 ghzy-hr02
3、关闭Selinux;
setenforce 0
sed -i “s/SELINUX=enforcing/SELINUX=disabled/” /etc/selinux/config
4、关闭firewall防火墙;
systemctl stop firewalld
systemctl disable firewalld
5、配置集群操作系统SSH互信;
ghzy-hr01上执行
ssh-keygen -t rsa #生成公钥一直回车即可
ssh-copy-id -i .ssh/id_rsa.pub root@ghzy-hr02
ghzy-hr02上执行
ssh-keygen -t rsa #生成公钥一直回车即可
ssh-copy-id -i .ssh/id_rsa.pub root@ghzy-hr01
6、核对两台服务器时间,最好使用NTP进行时间同步;
1、安装编译环境
yum install -y gcc gcc-c++ autoconf automake libtool glib2-devel libxml2-devel bzip2 bzip2-devel e2fsprogs-devel libxslt-devel libtool-ltdl-devel asciidoc
2、创建用户和组
groupadd haclient
useradd -g haclient hacluster
3、下载软件包
wget http://www.xxshell.com/download/heartbeat/Reusable-Cluster-Components-glue.tar.gz
wget http://www.xxshell.com/download/heartbeat/resource-agents-3.9.6.tar.gz
wget http://www.xxshell.com/download/heartbeat/Heartbeat-3.0.tar.gz
4、安装Reusable-Cluster-Components-glue
tar -xzvf Reusable-Cluster-Components-glue.tar.gz
cd Reusable-Cluster-Components-glue
./autogen.sh
./configure –prefix=/usr/local/heartbeat –with-daemon-user=hacluster –with-daemon-group=haclient –enable-fatal-warnings=no LIBS=’/lib64/libuuid.so.1'
make
make install
echo $?
cd ..
5、安装resource-agents-3.9.6
tar -xzvf resource-agents-3.9.6.tar.gz
cd resource-agents-3.9.6
./autogen.sh
./configure –prefix=/usr/local/heartbeat –with-daemon-user=hacluster –with-daemon-group=haclient –enable-fatal-warnings=no LIBS=’/lib64/libuuid.so.1'
make
make install
echo $?
cd ..
6、安装Heartbeat-3.0
tar -xzvf Heartbeat-3.0.tar.gz
cd Heartbeat-3.0
./bootstrap
export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"
./configure –prefix=/usr/local/heartbeat –with-daemon-user=hacluster –with-daemon-group=haclient –enable-fatal-warnings=no LIBS=’/lib64/libuuid.so.1'
make
make install
echo $?
在主服务器ghzy-hr01上复制HeartBeat包中doc下列文件到指定目录
cp doc/{ha.cf,haresources,authkeys} /usr/local/heartbeat/etc/ha.d/
2、在主服务器ghzy-hr01上编辑ha.cf配置文件
vim /usr/local/heartbeat/etc/ha.d/ha.cf
修改内容如下:
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 1
deadtime 10
warntime 5
initdead 60
udpport 694
ucast ens192 172.30.15.85
auto_failback on
node ghzy-hr01
node ghzy-hr02
ping 172.30.15.1
respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail
说明:
debugfile /var/log/ha-debug:该文件保存heartbeat的调试信息。
logfile /var/log/ha-log:heartbeat的日志文件。
keepalive 1:心跳的时间间隔,默认时间单位为秒s。
deadtime 10:心跳超时时间,超过该则认为对方已经失效。
warntime 5:超出该时间间隔未收到对方节点的心跳,则发出警告并记录到日志中。
initdead 60:在某系统上,系统启动或重启之后需要经过一段时间网络才能正常工作,该选项用于解决这种情况产生的时间间隔,取值至少为deadtime的2倍。
udpport 694:设置广播通信使用的端口,694为默认使用的端口号。
ucast ens192 172.30.15.85:设置单播对方机器心跳检测的网卡和IP。
auto_failback on:heartbeat的两台主机分别为主节点和从节点。主节点在正常情况下占用资源并运行所有的服务,遇到故障时把资源交给从节点由从节点运行服务。在该选项设为on的情况下,一旦主节点恢复运行,则自动获取资源并取代从节点,否则不取代从节点。
respawn heartbeat /usr/lib/heartbeat/ipfail:指定与heartbeat一同启动和关闭的进程,该进程被自动监视,遇到故障则重新启动。最常用的进程是ipfail,该进程用于检测和处理网络故障,需要配合ping语句指定的ping node来检测网络连接。如果你的系统是64bit,请注意该文件的路径。
3、在主服务器ghzy-hr01上编辑haresources配置
vim /usr/local/heartbeat/etc/ha.d/haresources
在第一行添加以下内容:
ghzy-hr01 172.30.15.83/24/ens192
说明:
172.30.15.83:为虚拟IP(VIP)
24:该网段的子网掩码
ens192:为业务网卡名称
ghzy-hr01 172.30.15.83/24/ens192 【进程名称】后面还可以添加进程名称,用来同时监控服务器与进程
4、在主服务器ghzy-hr01上编辑authkeys,配置加密参数并附加权限;
vim /usr/local/heartbeat/etc/ha.d/authkeys
在最后添加加密参数:
auth 2
2 md5 Hello
说明:
auth 2:表示使用ID为2的验证 下边需要定义一个2的验证算法
2 md5 Hello #ID 2的验证加密为md5,并添加密码。
给authkeys配置权限
chmod 600 /usr/local/heartbeat/etc/ha.d/authkeys
5、拷贝配置文件到ghzy-hr02服务器上;
scp /usr/local/heartbeat/etc/ha.d/{ha.cf,haresources,authkeys} root@ghzy-hr02:/usr/local/heartbeat/etc/ha.d/
拷贝完成后登录ghzy-hr02修改ha.cf配置文件将ucast的IP地址修改为ghzy-hr01的修改为“ucast ens192 172.30.15.84”。
6、配置网卡支持文件
mkdir -pv /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/
cp /usr/lib/ocf/lib/heartbeat/ocf-* /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/
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/
#注意:一般启动时会报错因为 ping和ucast这些配置都需要插件支持 需要将lib64下面的插件软连接到lib目录 才不会抛出异常。
7、两台节点上启动heartbeat服务
systemctl enable heartbeat
systemctl start heartbeat
评论