shell实现mysql高可用
2016-02-27 16:38
519 查看
笔粗墨糙,望见谅。
简单的理解高可用(不要去探究其到底包含了多少层意思),在我看来,只有两个方面:
1,及时的故障转移(基于vrrp协议的ip漂移);
2,尽量做到数据不丢失,或者很少的丢失。
基于vrrp协议的ip漂移可以利用keepalived来实现,此次重要介绍数据不丢失的解决方案
简单的理解高可用(不要去探究其到底包含了多少层意思),在我看来,只有两个方面:
1,及时的故障转移(基于vrrp协议的ip漂移);
2,尽量做到数据不丢失,或者很少的丢失。
基于vrrp协议的ip漂移可以利用keepalived来实现,此次重要介绍数据不丢失的解决方案
#!/bin/sh # user=`cat ashe.conf |grep -w recovery_user|awk -F '=' '{print $2}'|sed s/[[:space:]]//g`; port=`cat ashe.conf |grep -w new_master_port|awk -F '=' '{print $2}'|sed s/[[:space:]]//g`; binlog_dir=`cat ashe.conf |grep -w /data/mysql/data/3306|awk -F '=' '{print $2}'|sed s/[[:space:]]//g`; #此函数为检测已经传输过去的binlog是否已经经过sql线程回放完成, function check_sql_thread_status() { #变量x为从机已经执行到的最后的GTID; #变量y为从机接收到的GTID; #判断是否两值相等时,跳出,执行下一步。 while [[ "$x" != "$y" ]] do # echo $x >> /var/log/ashe_ha.log # echo $y >> /var/log/ashe_ha.log done echo 'the new master has complete the local relay_log,,,and start recovery.'>>/var/log/ashe_ha.log; } #此函数为:原主机上日志恢复至新主,需要改进处为,日志处理 function recovery() { #根据配置文件获取连接参数 echo "starting recovery to new master(192.168.134.135).....">>/var/log/ashe_ha.log; echo "mysqlbinlog -vv -j $b $a | mysql -u$user -p$password -h$host -P$port">>/var/log/ashe_ha.log; cd $binlog_dir; mysqlbinlog -vv -j $b $a | mysql -u$user -p$password -h$host -P$port 2>/var/log/ashe_ha.log; echo "recovery complete.">>/var/log/ashe_ha.log; ##########wwhile 循环依次回放日志,从当前日志开始回放,??????????????????????????????????????????????? } #send_massage_to_slave,发送主机宕机事件给从机 function send_massage_to_slave() { mysql -u$user -p$password -h$host -P$port -ss -e "insert into ashe.ashe values(1);" } ####################按顺序执行的shell脚本########################################## while :; do i=`netstat -nltp|grep 3306` echo $i if [ -z "$i" ] then # #############################本机记录日志 echo -n `date`>>/var/log/ashe_ha.log; echo " mysql server is down">>/var/log/ashe_ha.log; ###################################调用check_sql_thread_status函数 check_sql_thread_status; ###################################停止从机复制线程。 mysql -u$user -p$password -h$host -P$port -e "stop slave;"; recovery; send_massage_to_slave; exit; else # ############################# echo -n `date`>>/var/log/ashe_ha.log; echo " mysql server is ok">>/var/log/ashe_ha.log fi sleep 2; done
相关文章推荐
- windows 7 使用 powershell 的几个本地操作常用命令
- linux 下shell脚本执行多个命令的方法
- shell 编程之 for while until 循环
- shell获取Linux主机信息(mac地址,处理器,主板,uuid,硬盘)的方法
- PowerShell-Exchange:Environment Reports 推荐
- PowerShell-Exchange:Services Monitor Report
- Powershell 1.1 computer configuration
- bash
- Powershell-Exchange:Generate Health Report
- shell编程(1)
- spark-shell和scala错误
- spark-shell和scala错误
- 为MacOS X创建.bash_profile
- python结合shell查询google关键词排名的实现代码
- HBase的Shell操作
- GitBash 自定义命令提示符
- shell编程练习001(20160226)
- shell 编程之 if...else case...esac
- ubuntu 12.04 怎么取得超级用户权利
- shell 常用命令