shell 实现MHA的master_ip_failover

这是一个用于在MHA环境中进行主库IP切换的Shell脚本。脚本定义了变量如SSH端口、VIP地址、网络设备等,并包含开始、停止和状态检查等函数。通过命令行参数获取配置信息,根据命令调用相应函数执行IP切换操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/bash
		#--------------第一部分:变量及函数定义-----------------#
	###Begin Variables define###
	ssh_port=22
	cmd=/sbin/ifconfig
	vip=172.16.4.116	
	device=eth0:0
	netmk=255.255.255.0
	start_vip="${cmd} ${device} ${vip} netmask ${netmk} up"
	stop_vip="${cmd} ${device} ${vip} netmask ${netmk} down"
	###End Variables define###

	###Begin Status Funciont###
	status()
	{
	exit 0	
	}	
	###End Status Funciont###

	###Begin Stop Or Stopssh Funciont###
	stop()
	{
	exit 0
	}
	###End Stop Or Stopssh Funciont###

	###Begin Start Funciont###
	start()
	{
	/usr/bin/ssh -p ${ssh_port} ${ssh_user}@${orig_master_host} ""${stop_vip}"" 	
	/usr/bin/ssh -p ${ssh_port} ${ssh_user}@${new_master_host} ""${start_vip}""	
	exit 0
	}
	###End Start Funciont###
		#--------------第一部分:变量及函数定义-----------------#

		#--------------第二部分:命令行参数-----------------#
	###Begin Get The Command-Line Parameters###

	eval set -- "`getopt -a -q -o n -l command::,ssh_user:,orig_master_host:,orig_master_ip:,new_master_host:,new_master_ip: -- "$@"`"

	if [ $? != 0 ] ; then echo "Terminating..." >&2 ;exit 1;fi

	while true
	do
		case "$1" in
			--command)
				command="${2}";	
				shift;;
			--ssh_user)
				ssh_user="${2}";
				shift;;
			--orig_master_host)
				orig_master_host="${2}";
				shift;;
			--orig_master_ip)
				orig_master_ip="${2}";
				shift;;
			--new_master_host)
				new_master_host="${2}";
				shift;;
			--new_master_ip)
				new_master_ip="${2}";
				shift;;
			--)
				shift;
				break;;
		esac
	shift		
	done		
	###End Get The Command-Line Parameters###
		#--------------第二部分:命令行参数-----------------#

		#--------------第三部分:函数调用-----------------#
	if [ "${command}" == "status" ];
	then
	status;
	fi
	
	
	if [ "${command}" == "stop" ] || [ "${command}" == "stopssh" ] ;
	then
	stop;
	fi

	if [ "${command}" == "start" ];
        then    
        start;
        fi
		#--------------第三部分:函数调用-----------------#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值