赞
踩
vim /etc/keepalived/keepalived.conf:
主从配置大体一样,修改文件提示的地方即可。
global_defs { notification_email { 28903817@sohu.com } notification_email_from 28903817@sohu.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id mysql_ha01 #成为从节点修改为mysql_ha02 script_user root } vrrp_instance VI_1 { state BACKUP interface ens33 #配置哪个网卡去进行心跳包的传输 virtual_router_id 51 #虚拟路由标识,这个标识是一个数字(取值在0-255之间,用来区分多个instance的VRRP组播),同一个vrrp实例使用唯一的标识,确保和master2相同,同网内不同集群此项必须不同,否 priority 100 #成为主节点 从节点可小于100。 nopreempt #不抢占资源 advert_int 1 #心跳包的频率 1秒一次 authentication { #两台主机通信心跳包的加密 auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.244.100/24 #虚拟ip(类似于--proxy-address) } notify_master "/etc/keepalived/notify.sh master" notify_backup "/etc/keepalived/notify.sh backup" notify_fault "/etc/keepalived/notify.sh fault" } virtual_server 192.168.244.100 3306 { delay_loop 2 #每个2秒检查一次real_server状态 lb_algo rr #LVS算法 lb_kind DR #LVS算法 persistence_timeout 60 #会话保持时间 protocol TCP real_server 192.168.244.168 3306 { weight 3 # 配置节点权值,数字越大权重越高 notify_down /etc/keepalived/bin/mysql.sh #down后执行的脚本 TCP_CHECK { connect_timeout 3 #连接超时时间 nb_get_retry 3 #重连次数 delay_before_retry 3 #重连间隔时间 connect_port 3306 #健康检查端口 } } }
#!/bin/bash
pkill keepalived
chmod -R 777 /etc/keepalived/bin/mysql.sh
yum install -y mailx
vim /etc/mail.rc
set bsdcompat
set from=82436965@qq.com #邮箱地址
set smtp=smtp.qq.com
set smtp-auth-user=82436965@qq.com
set smtp-auth-password=kpuhuqvppcedjjeh #需要开启邮箱pop3
set smtp-auth=login
set ssl-verify=ignore
echo “hello” | mail -s “mail test” 82436965@qq.com
vim /etc/keepalived/notify.sh
#!/bin/bash contact='82436965@qq.com' notify() { mailsubject="$(hostname) to be $1, vip floating" mailbody="$(date +'%F %T'): vrrp transition, $(hostname) changed to be $1" echo "$mailbody" | mail -s "$mailsubject" $contact } case $1 in master) notify master ;; backup) notify backup ;; fault) notify fault ;; *) echo "Usage: $(basename $0) {master|backup|fault}" exit 1 ;; esac
chmod /etc/keepalived/notify.sh
killall keepalived
Configuration file ‘/etc/keepalived/keepalived.conf’ is not a regular non-executable file
排查:查看keepalived.conf 的权限
ll /etc/keepalived/keepalived.conf
解决方案:
#chmod 644 /etc/keepalived/keepalived.conf
注:keepalived的配置文件的权限只能是644,否则就行报错
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。