• 维护keepalived与mysql漂移脚本


    环境拓扑

     

    chengAlived

    #!/bin/bash
    function checkModelone(){
    	echo "重新进行获取"
    	wget 192.168.158.147:3306 -O mysql
    	echo "获取成功"
    	echo "进行判断..."
    	grep "5.7.17" mysql > /dev/null
    	if [ $? -eq 0 ]; then
    	       	echo "mysql正在运行..."
    		echo "检查keepalived进程是否存在..."
    		ps aux|grep keepalived |grep -v grep
    		if [ $? -ne 0 ]
    		then
    			echo "keepalived进程丢失"
    			echo "准备重启keepalived..."
    			/usr/local/keepalived/sbin/keepalived -f /etc/keepalived/keepalived.conf
                            echo "重启成功"
    		else
    			echo "keepalived 正在运行..." 
    		fi
    	else
    		echo "mysql端口异常..."
    		echo "准备杀除keepalived进程进行漂移"
    		chengkill keepalived
    		echo "漂移作业完毕"
    	fi
    }
    
    function checkModeltwo(){
       checkModelone
    }
    while [ true ]; do
    	/bin/sleep 10
    	if [ -d "mysql" ];then
    		touch mysql
    	else
    		if [ -s ./mysql ]; then
    			echo "文件不为空"
    			checkModelone
    			du -sh mysql
    		else
    			echo "文件为空"
    			checkModeltwo
    		fi
    	fi
    done

    运行规则:nohup ./chengAlived.sh &

    说明+:

    运行后, 会判断是否存在名字为"mysql"的文件, 否则新建, 把wget后的内容写进这个文件, 通过3306端口使用grep判断mysql版本号, 对keepalived漂移进行管理.

    讲解+

    第一台机器mysql主机+vip

    第二台机器keepalived+lvs

    启动脚本

    nohup ./chengAlive.sh &

     进程

    ps aux | grep chengAlive.sh 
    
    
    [root@localhost test]# ps aux | grep chengAlive.sh 
    root      16407  0.0  0.1 113128  1412 pts/1    S    15:27   0:00 /bin/bash ./chengAlive.sh
    root      16410  0.0  0.1 112676  1008 pts/1    R+   15:27   0:00 grep --color=auto chengAlive.sh

     日志(mysql处于正常开启状态)

    模拟宕机

     假如mysql挂掉了(这是158.147)

    然后keepalived查看脚本日志信息(158.149)

     

    上面,,由于mysql已挂, kill掉keepalived, 实现漂移操作

    抢占模拟

     如果mysql重新启动(158.147)

     

    再看keepalive(158.149)脚本日志

    重新自动启动keepalive.抢占成功.

    完毕.

  • 相关阅读:
    hdu 5082
    Codeforces Round #265 (Div. 2) E. Substitutes in Number
    Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
    机器学习算法概述第五章——CART算法
    机器学习算法代码实现——线性回归
    机器学习算法概述第一章——线性回归
    机器学习之线性回归模板超详注释
    How to create a on-demand AWR snapshot?
    Emptying the buffers cache
    java/groovy 计算时间
  • 原文地址:https://www.cnblogs.com/chenglee/p/8722720.html
Copyright © 2020-2023  润新知