1.集群环境
node1:192.168.220.111
node2:192.168.220.112
2.准备工作
配置各节点SSH互信:
# node1 ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ‘‘ ssh-copy-id -i .ssh/id_rsa.pub [email protected] # node2 ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ‘‘ ssh-copy-id -i .ssh/id_rsa.pub [email protected]
配置主机名称与uname -n一致,并通过/etc/hosts解析:
# node1 hostname node1.wyb.com sed -i ‘s/localhost.localdomain/node1.wyb.com/g‘ /etc/sysconfig/network echo ‘192.168.220.111 node1.wyb.com node1‘ >> /etc/hosts echo ‘192.168.220.112 node2.wyb.com node2‘ >> /etc/hosts # node2 hostname node2.wyb.com sed -i ‘s/localhost.localdomain/node2.wyb.com/g‘ /etc/sysconfig/network echo ‘192.168.220.111 node1.wyb.com node1‘ >> /etc/hosts echo ‘192.168.220.112 node2.wyb.com node2‘ >> /etc/hosts
时间同步:
# node1 node2 ntpdate asia.pool.ntp.org echo ‘*/3 * * * * /usr/sbin/ntpdate asia.pool.ntp.org &> /dev/null‘ >> /var/spool/cron/root
3.安装
自3版本开始,heartbeat将原来项目拆分为了多个子项目(即多个独立组件),现在的组件包括:heartbeat、cluster-glue、resource-agents。各组件主要功能:
heartbeat:属于集群的信息层,负责维护集群中所有节点的信息以及各节点之间的通信。
cluster-glue:包括LRM(本地资源管理器)、STONITH,将heartbeat与crm(集群资源管理器)联系起来,属于一个中间层。
resource-agents:即各种资源脚本,由LRM调用从而实现各个资源的启动、停止、监控等。
设置yum源:
rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
安装heartbeat/pacemaker:
yum install heartbeat heartbeat-libs pacemaker pacemaker-libs resource-agents cluster-glue cluster-glue-libs
4.配置
heartbeat有3个配置文件:
密钥文件: authkeys,用来加密集群间事务信息传递,权限必须为600;
heartbeat:服务的配置文件ha.cf;
haresources: 资源管理配置文件;
默认目录下并没有相关配置文件,可以自己手动建立,也可以直接修改软件包中自带的模板,因为使用pacemaker管理资源所以不需要拷贝haresources文件,如果使用了crm管理资源,而在配置文件目录含有haresources文件,日志中会提示haresources没有使用。
cp -p /usr/share/doc/heartbeat-3.0.4/{authkeys,ha.cf} /etc/ha.d/
配置密钥文件:
(echo -ne "auth 1\n1 md5 ";dd if=/dev/random bs=512 count=1 | md5sum) >> /etc/ha.d/authkeys
配置主配置文件ha.cf:
#集群中的节点不会自动加入 autojoin none #heartbeat会记录debug日志,如果启用use_logd,则此选项会被忽略 #debugfile /var/log/ha-debug #记录所有non-debug消息,如果启用use_logd,则此选项会被忽略 logfile /var/log/ha-log #通过syslog记录日志 #logfacility local0 #指定两个心跳检测包的时间间隔 keepalive 1 #多久以后心跳检测决定集群中的node已经挂掉 deadtime 30 #心跳包检测的延时事件,如果延时,只是往日志中记录warning日志,并不切换服务 warntime 10 #在heartbeat启动后,在多长时间内宣布node是dead状态,因为有时候系统启动后,网络还需要一段时间才能启动 initdead 120 #如果udpport指令在bcast ucast指令的前面,则使用哪个端口进行广播,否则使用默认端口 udpport 694 #设置使用哪个网络接口发送UDP广播包,可以设置多个网络接口 bcast eth0 #设置在哪个网络接口进行多播心跳检测 #mcast eth0 239.0.0.1 694 1 0 #设置使用哪个网络接口进行UDP单播心跳检测,在.3上为10.1.1.2 #ucast eth0 10.1.1.3 #在主节点的服务恢复后,是否把从节点的服务切换回来 auto_failback on #告诉集群中有哪些节点,node名称必须是uname -n显示出来的名称,可以在一个node中设置多个节点,也可以多次设置node,每一个在集群中的node都必须被列出来 node node1.wyb.com node node2.wyb.com #设置ping节点,仲裁设备,可以指向网关 ping 192.168.220.2 #节点故障后,是否尝试重启heartbeat服务来恢复 respawn hacluster /usr/lib/heartbeat/ipfail #开启Pacemaker cluster manager,因为历史原因,次选项默认是off,但是应该保持该选项值为respawn。在设置为respawn默认自动使用以下配置 pacemaker respawn #默认配置文件中下面还有很多选项,由于暂时用不到所以暂时忽略
将配置文件复制到node2上:
scp /etc/ha.d/{authkeys,ha.cf} node2:/etc/ha.d/
5.安装crmsh
从pacemaker 1.1.8开始,crmsh 发展成一个独立项目,pacemaker中不再提供,说明我们安装好pacemaker后,是不会有crm这个命令行模式的资源管理器的。
# node1 node2 wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/crmsh-2.1-1.6.x86_64.rpm yum -y --nogpgcheck localinstall crmsh-2.1-1.6.x86_64.rpm
参考资料:
heartbeat + pacemaker实现pg流复制自动切换:
http://my.oschina.net/lianshunke/blog/200411?p={{currentPage-1}}
Heartbeat3.0.5+pacemaker:http://my.oschina.net/guol/blog/90128
Linux高可用(HA)集群之Pacemaker详解:http://www.linuxeye.com/Linux/1899.html