欢迎来到天天文库
浏览记录
ID:39574634
大小:48.00 KB
页数:5页
时间:2019-07-06
《使用keepalived实现对mysql主从复制的主备自动切换》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、keepalived实现对mysql主从复制的主备自动切换使用MySQL+keepalived是一种非常好的解决方案,在MySQL-HA环境中,MySQL互为主从关系,这样就保证了两台MySQL数据的一致性,然后用keepalived实现虚拟IP,通过keepalived自带的服务监控功能来实现MySQL故障时自动切换。实验环境中用两台主机搭建了一个mysql主从复制的环境,两台机器分别安装了keepalived,用一个虚IP实现mysql服务器的主备自动切换功能.模拟环境:VIP:192.168.1.197:虚拟IP地址Master
2、:192.168.1.198:主数据库IP地址Slave:192.168.1.199:从数据库IP地址备注:MySQL的主从同步配置不在此文档中说明(前提:主从同步已完成)安装步骤:1、keepalived的安装Yuminstall-ykeepalivedChkconfigkeepalivedon2、keepalived.conf文件的配置Master:keepalived.confvi/etc/keepalived/keepalived.conf!ConfigurationFileforkeepalivedglobal_defs{n
3、otification_email{kenjin@xishiqu.com}notification_email_fromkenjin@xishiqu.comsmtp_connect_timeout3smtp_serversmtp.xishiqu.comrouter_idMySQL-ha}vrrp_scriptcheck_run{#声明vrrp_script的函数check_runscript"/root/keepalived_check_mysql.sh"#监控MySQL的脚本interval5}vrrp_sync_groupVG1{
4、group{VI_1}}vrrp_instanceVI_1{stateMASTER#指定主服务器节点为主节点,备用节点上设置需一致interfaceeth0#指定虚拟IP的网络接口virtual_router_id88#VRRP组名,两个节点的设置必须一样,以指明各个节点属于同一VRRP组priority100#主节点的优先级(1-254之间),备用节点必须比主节点优先级低。advert_int1#组播信息发送间隔,两个节点设置必须一样nopreemptauthentication{#设置验证信息,两个节点必须一致auth_typeP
5、ASSauth_pass1111}track_script{#调用函数代码块check_run}virtual_ipaddress{#虚拟IP(对外提供MySQL服务的IP地址)192.168.1.197#不能和网内其他IP地址冲突}}Slave:keepalived.conf!ConfigurationFileforkeepalivedglobal_defs{notification_email{kenjin@xishiqu.com}notification_email_fromkenjin@xishiqu.comsmtp_conn
6、ect_timeout3smtp_serversmtp.xishiqu.cnrouter_idMySQL-ha}vrrp_scriptcheck_run{script"/root/keepalived_check_mysql.sh"interval5}vrrp_sync_groupVG1{group{VI_1}}vrrp_instanceVI_1{stateMASTERinterfaceeth1#本地网口按实际情况配置virtual_router_id88priority99advert_int1nopreemptauthentica
7、tion{auth_typePASSauth_pass1111}track_script{check_run}virtual_ipaddress{192.168.1.197}}3、mysql状态检测脚本在目录root下创建脚本keepalived_check_mysql.sh:vim/root/keepalived_check_mysql.sh#!/bin/bashMYSQL=/usr/local/mysql/bin/mysqlMYSQL_HOST=localhostMYSQL_USER=rootMYSQL_PASSWORD=1234
8、56CHECK_TIME=3#mysqlisworkingMYSQL_OKis1,mysqldownMYSQL_OKis0MYSQL_OK=1functioncheck_mysql_helth(){$MYSQL-h$MY
此文档下载收益归作者所有