Keepalive+Atlas+DRBD+Heartbeat+mysql配置系列(二):shell脚本自动安装heartbeat
在centos6的时候可以直接yum安装,但到了centos7的时候,只能编译安装,故我找遍网上,终于发现了个可以在centos7里使用yum安装heartbeat的,现分享给大家.
系统:centos 7.x(64位)
环境ip:
node1(主节点)IP: 10.0.2.5 主机名:dbm5
node2(从节点)IP: 10.0.2.7 主机名:dbm7
虚拟IP地址(VIP): 10.0.2.10
1.准备工作
vim /etc/hosts
10.0.2.5 dbm5
10.0.2.7 dbm7
2.脚本内容:
cat /root/soft_shell/heartbeat.sh
#!/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 wget
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://http://download.slogra.com'
wget $d_url/heartbeat/heartbeat-3.0.6-1.el7.centos.x86_64.rpm
wget $d_url/heartbeat/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 #ha的日志文件记录位置 logfacility local0 #设置heartbeat的日志,这里用的是系统日志 udpport 694 #用于通信的UDP端口 keepalive 1 #设定心跳(监测)时间间隔为1秒 deadtime 15 #宣告死亡时间 warntime 5 #心跳延时时间 initdead 30 #初始化时间 bcast eth0 #接受广播心跳的网卡接口 auto_failback off #关闭自动切回恢复正常的主节点 node dbm5 #集群节点的名称,必须匹配uname -n的结果 node dbm7 crm no EOF
# 两端认证方式 authkeys
cat <<EOF >>/etc/ha.d/authkeys
auth 1
1 sha1 5014d852a9c2ed8101e7da7d0c9eabf22826225b
EOF
chmod 600 /etc/ha.d/authkeys
# haresources添加资源(10.0.2.10为VIP 配置到eth0 网卡)
cat <<EOF >/etc/ha.d/haresources
dbm5 10.0.2.10/24 drbddisk::drbd0 Filesystem::/dev/drbd0::/data::xfs::noatime mysqld
EOF
#######heartbeat控制mysql启动脚本#######
cat >/etc/ha.d/resource.d/mysqld<<EOF
#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH case "$1" in start) service mysqld start ;; stop) service mysqld stop ;; esac exit 0 EOF
3.启动Heartbeat
先在主节点(dbm5)上启动:
systemctl start heartbeat
等主节点(dbm5)启动好后,再启动备节点(dbm7):
systemctl start heartbeat
4.验证方法
可以停主节点的heartbeat,看看是否能切换到备节点,mysql是否能访问.剩下的验证方式就大家自己去发掘了.
评论: