来自 技术 2019-03-16 00:00 的文章

heartbeat部署

开发十年,就只剩下这套架构体系了!>>>

环境

系统: CentOS-7-x86_64-Minimal-1804注意: 下面的heartbeat 安装包只适用于 CentOS-7-x86_64-Minimal-1804 如需要其他版本 需要下载源码生成创建配置文件

cat <<'EOF' >info.sh192.168.2.71 node1.local192.168.2.72 node2.localEOFssh互信

list=$(cat info.sh | awk '{print $1}' | xargs)bash <(curl -sSL http://kaifa.hc-yun.com:30050/xiongjunfeng/mongo/raw/branch/master/ssh-key.sh) "$list" $RootPass同步hosts文件

echo >> /etc/hostscat info.sh >> /etc/hostsfor node in $list; do scp /etc/hosts $node:/etc/hostsdonehost=$(cat info.sh | awk '{print $2}' | xargs)for node in $host; do ssh $node "hostnamectl set-hostname $node; hostname"done创建安装脚本

cat >/tmp/heartbeat.sh <<'EEOOFF'#!/bin/bash# 关闭防火墙,Selinuxsystemctl stop firewalldsystemctl disable firewalldsetenforce 0sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config# 配置yum源mkdir /etc/yum.repos.d/OldRepomv /etc/yum.repos.d/*.repo /etc/yum.repos.d/OldRepo/curl -so /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repocurl -so /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.reposed -i '/aliyuncs.com/d' /etc/yum.repos.d/Centos-7.repo /etc/yum.repos.d/epel-7.repo# 时间同步yum install -y ntpdatentpdate ntp1.aliyun.comhwclock -wecho "*/20 * * * * $(which ntpdate) ntp1.aliyun.com > /dev/null 2>&1 && $(which hwclock) -w" > /var/spool/cron/rootchmod 600 /var/spool/cron/root# 配置软件依赖安装源 (cluster-glue-libs-devel 安装源)cat <<EOF >/etc/yum.repos.d/gf-epel-7.repo[epel-testing]name=Extra Packages for Enterprise Linux 7 - $basearch - Testingbaseurl=http://mirror.ghettoforge.org/distributions/gf/el/7/testing/x86_64enabled=1gpgcheck=0EOF# 下载软件d_url='http://kaifa.hc-yun.com:30027'curl -O $d_url/mongo/other/heartbeat-3.0.6-1.el7.centos.x86_64.rpmcurl -O $d_url/mongo/other/heartbeat-libs-3.0.6-1.el7.centos.x86_64.rpm# 安装yum localinstall -y heartbeat-*rm -rf heartbeat-3.0.6-1.el7.centos.x86_64.rpm heartbeat-libs-3.0.6-1.el7.centos.x86_64.rpm# 配置cp /usr/share/doc/heartbeat-3.0.6/{ha.cf,authkeys,haresources} /etc/ha.d/cat <<EOF >/etc/ha.d/ha.cfdebugfile /var/log/ha-debuglogfile /var/log/ha-loglogfacility local0udpport 694keepalive 1deadtime 15warntime 5initdead 30bcast eth0auto_failback onnode node1.localnode node2.localcrm noEOF# 两端认证方式 authkeyscat <<EOF >>/etc/ha.d/authkeysauth 11 sha1 cxix9lkzq2aevnxv43yn68yoh2y7zp2cfwufgs7wEOFchmod 600 /etc/ha.d/authkeys# haresources添加资源(2.30为VIP 配置到eth0 网卡)cat <<EOF >/etc/ha.d/haresourcesnode1.local IPaddr::192.168.2.30/24/eth0EOFEEOOFF发送脚本

scp /tmp/heartbeat.sh node1.local:/rootscp /tmp/heartbeat.sh node2.local:/rootrm -f /tmp/heartbeat.sh执行安装

ssh node1.local 'sh /root/heartbeat.sh'ssh node2.local 'sh /root/heartbeat.sh'验证

1.启动服务(两台都启动)

systemctl start heartbeat

2.查看VIP(默认是在node1.local)

ip add | grep 192.168.2.30

3.停止node1.local heartbeat服务或禁用网络然后到node2.local查看VIP

# node1.local systemctl stop heartbeat # node1.local,node2.local(此时VIP应该在node2) ip add | grep 192.168.2.30

4.node1.local自动恢复 node1.local启动 heartbeat服务后自动恢复

# node1.localsystemctl start heartbeatip add | grep 192.168.2.30

禁用自动恢复

# node1.local, node2.localsed -i 's/auto_failback on/auto_failback off' /etc/ha.d/ha.cfsystemctl start heartbeat