heartbeat部署

环境

系统: CentOS-7-x86_64-Minimal-1804

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

创建配置文件

cat <<'EOF'   >info.sh
192.168.2.71   node1.local
192.168.2.72   node2.local
EOF

ssh互信

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/hosts
cat info.sh >> /etc/hosts
for node in $list; do
    scp /etc/hosts $node:/etc/hosts
done

host=$(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

# 关闭防火墙,Selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# 配置yum源
mkdir /etc/yum.repos.d/OldRepo
mv /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.repo
curl -so /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i '/aliyuncs.com/d' /etc/yum.repos.d/Centos-7.repo /etc/yum.repos.d/epel-7.repo

# 时间同步
yum install -y ntpdate
ntpdate ntp1.aliyun.com
hwclock -w
echo "*/20 * * * * $(which ntpdate) ntp1.aliyun.com > /dev/null 2>&1 && $(which hwclock) -w" > /var/spool/cron/root
chmod 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 - Testing
baseurl=http://mirror.ghettoforge.org/distributions/gf/el/7/testing/x86_64
enabled=1
gpgcheck=0
EOF

# 下载软件
d_url='http://kaifa.hc-yun.com:30027'
curl -O $d_url/mongo/other/heartbeat-3.0.6-1.el7.centos.x86_64.rpm
curl -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.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
udpport 694

keepalive 1
deadtime 15
warntime 5
initdead 30

bcast eth0
auto_failback on

node node1.local
node node2.local

crm no
EOF

# 两端认证方式 authkeys
cat <<EOF  >>/etc/ha.d/authkeys

auth 1
1 sha1 cxix9lkzq2aevnxv43yn68yoh2y7zp2cfwufgs7w
EOF
chmod 600 /etc/ha.d/authkeys

# haresources添加资源(2.30为VIP 配置到eth0 网卡)
cat <<EOF   >/etc/ha.d/haresources
node1.local IPaddr::192.168.2.30/24/eth0
EOF
EEOOFF

发送脚本

scp /tmp/heartbeat.sh node1.local:/root
scp /tmp/heartbeat.sh node2.local:/root
rm -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.local
systemctl start heartbeat
ip add | grep 192.168.2.30

禁用自动恢复

# node1.local, node2.local
sed -i 's/auto_failback on/auto_failback off' /etc/ha.d/ha.cf
systemctl start heartbeat

转载于:https://my.oschina.net/yx571304/blog/3023101

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值