keepalived

本文介绍Keepalived在Ubuntu 16.04上的部署过程,包括安装、配置注意事项及节点设置。通过具体实例展示了如何配置Master和Backup节点,并提供自定义脚本用于服务监控和性能测试。

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

1 Operating Environment

  • Linux Version
cat /etc/issue
cat /etc/redhat-release
Ubuntu 16.04.4 LTS \n \l
  • Configuration Info
NodeHOST-IP
VIP192.168.0.10
MASTER192.168.0.20
BACKUP192.168.0.30

2 Install

3 Setting

3.1 Configuration Precautions

3.1.1 Common Command

ActionCommandRemarks
Self-startingsystemctl enable keepalived
startsystemctl start keepalived
stopsystemctl stop keepalived
restartsystemctl restart keepalived
check processps -ef | grep keepalived
check ipifconfig | grep eth0
check ipip -a

3.1.2 Configuration Precautions

  • keepavlied.conf
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.ori
vim /etc/keepalived/keepalived.conf
  • Configuration Precautions
ItemPrecautionsRemarks
virtual_router_id必须一致0- 255之间
router_id必须不同
state根据策略配置MASTER or BACKUP
prioritydiff0- 255之间,相差50以上

3.2 MASTER Node Setting

! Configuration File for keepalived

vrrp_script chk_fs {
    script "/etc/keepalived/chk_fs.sh"
    interval 10
    weight 2
}

global_defs {
   router_id xxx_master
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 188
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    
    track_script {
    	# run the script
        chk_fs
    }
	
    virtual_ipaddress {
       192.168.0.20/24 dev eth0 label eth0:1
    }
}

3.3 BACKUP Node Setting

! Configuration File for keepalived

vrrp_script chk_fs {
        script "/etc/keepalived/chk_fs.sh"
        interval 10
        weight 2
}

global_defs {
   router_id xxx_backup
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 188
    priority 20
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    
    track_script {
    	# run the script
        chk_fs
    }
    
    virtual_ipaddress {
       192.168.0.30/24 dev eth0 label eth0:1
    }
}

4 keepalived-script

  • killall
# ubuntu
apt-get install psmisc
# redhat or CentOS
yum install psmisc -y

4.1 Script

  • Context
cd /etc/keepalived
vi chk_fs.sh
  • keepalived-script
#! /bin/bash
# num=`ps -ef |grep freeswitch |grep -v grep | wc -l`
num =`netstat -tnlp |grep ":5066"|wc -l`
if [ $num -eq 0 ]; 
then
	# /usr/local/freeswitch/bin/freeswitch -nc
	# /app/docker.sh
	sleep 3
	if [ `netstat -tnlp |grep ":5066"|wc -l` -eq 0 ]; 
	then
	     killall keepalived
	fi
fi

4.2 Performance Testing

  • script
#!/bin/sh
echo "shell:hello world!"
PATH=/bin:/sbin:/usr/bin:/usr/sbin
A=`ps -C nginx --no-header |wc -l`
if [ $A -eq 0 ]
then
     echo 'nginx server is died'
     killall keepalived
fi

echo "end: hello world!"
  • config
! Configuration File for keepalived

vrrp_script check_nginx_alive {
        script "/usr/bin/check_nginx_alive.sh"
        interval 3
        weight -10
}

global_defs {
   notification_email {
        wangjq@cmrh.com
   }
   notification_email_from wangjq@cmrh.com
   smtp_server mail.cmrh.com
   smtp_connect_timeout 30
   router_id CMRH_WEB
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 171
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass cmrh_web
    }

   track_script {
        ## run the script
        check_nginx_alive
    }

    virtual_ipaddress {
         100.69.216.171
    }
}

virtual_server 100.69.216.171 80 {
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    persistence_timeout 50
    protocol TCP

    real_server 100.69.216.168 80 {
        weight 1
        TCP_CHECK{
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
}

5 keepalived HA

vim monitorvip.sh
bash monitorvip.sh
#! /bin/bash
var=` /sbin/ifconfig -a | grep "inet" | awk '{print $2}' | awk -F ':' '{print $2}' `;
vip="vip";
result=$(echo $var | grep "${vip}");
if [ "$result" != "" ]
then
    echo "$s1 include $s2"
else
    echo "$1 not include $s2"
fi

5.1 CTI

  • CTI
#!/bin/sh
while true
do
time=$(date "+%Y-%m-%d %H:%M:%S")
var=` /sbin/ifconfig -a | grep "inet" | awk '{print $2}' | awk -F ':' '{print $2}' `;
vip="100.70.88.148";
result=$(echo ${var} | grep "${vip}");
if [ "$result" != "" ]
then

	echo  "[""${time}""]": ${var} >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
	echo  "[""${time}""]": ${vip} >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
	echo  "[""${time}""]": result value: ${result} >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
	
	echo "[""${time}""]": Virtual IP is on this host. Running CTI Service!  >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
	sn=`ps -ef | grep rainnytech.exe | grep -v grep`
	if [ "${sn}" = "" ]
	then
		echo "[""${time}""]": Virtual IP is on this host. CTI Service is not running! >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
		cd /var/rainny/cti/rainnyinfo/
		echo "[""${time}""]": Restart CTI Service! >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
		nohup mono rainnytech.exe &
		echo "[""${time}""]": Restart CTI Service has been completed! >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
		echo "[""${time}""]": ctiserver is restart >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log

	else
		echo "[""${time}""]":  Virtual IP is on this host. ctiserver is running >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log

	fi
else
	echo  "[""${time}""]": ${var} >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
	echo  "[""${time}""]": ${vip} >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
	echo  "[""${time}""]": result value: ${result} >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
	
	echo "[""${time}""]": Virtual IP is not on this host. stop CTI Service!  >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
	pid=`ps -ef | grep "rainnytech.exe" | grep -v grep | awk '{print $2}'`
	if [ "${pid}" = "" ]
	then
		echo "[""${time}""]": ctiserver is not running, not need to restart! >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
	else
		echo "[""${time}""]": ctiserver is running, stop ctiserver! >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
		kill -9 "${pid}"
		echo "[""${time}""]": Stoping ctiserver has been completed! >>/var/rainny/cti/rainnyinfo/ctiwatchdog.log
	fi
fi
sleep 7
done

5.2 FS

#!/bin/sh
while true
do
time=$(date "+%Y-%m-%d %H:%M:%S")
var=` /sbin/ifconfig -a | grep "inet" | awk '{print $2}' | awk -F ':' '{print $2}' `;
vip="100.70.88.147";
result=$(echo ${var} | grep "${vip}");
if [ "$result" != "" ]
then
        echo  "[""${time}""]": ${var}
		echo  "[""${time}""]": ${vip}
		
		echo  "[""${time}""]": ${var} >>/var/rainny/cti/log/freeswitch.log
		echo  "[""${time}""]": ${vip} >>/var/rainny/cti/log/freeswitch.log
		echo  "[""${time}""]": result value: ${result} >>/var/rainny/cti/log/freeswitch.log
		
		echo  "[""${time}""]": vip is on this host!
        echo  "[""${time}""]": VIP is on this host, restart FreeSWITCH Service! >>/var/rainny/cti/log/freeswitch.log
        sn=`ps -ef | grep freeswitch | grep -v grep`
        if [ "${sn}" = "" ]
        then
			echo "[""${time}""]": VIP is on this host, FreeSWITCH is not running >>/var/rainny/cti/log/freeswitch.log
			cd /usr/local/freeswitch/bin
			echo "[""${time}""]": Restart FreeSWITCH >>/var/rainny/cti/log/freeswitch.log
			./freeswitch -nonat -nc
			echo "[""${time}""]": restart completed >>/var/rainny/cti/log/freeswitch.log
			echo "[""${time}""]": freeswitch is restart >>/var/rainny/cti/log/freeswitch.log
        else
			echo "[""${time}""]": freeswitch is running >>/var/rainny/cti/log/freeswitch.log
        fi
else
        echo  "[""${time}""]": ${var}
		echo  "[""${time}""]": ${vip}
		
		echo  "[""${time}""]": ${var} >>/var/rainny/cti/log/freeswitch.log
		echo  "[""${time}""]": ${vip} >>/var/rainny/cti/log/freeswitch.log
		echo  "[""${time}""]": result value: ${result} >>/var/rainny/cti/log/freeswitch.log
        
		echo "[""${time}""]": !
		echo "[""${time}""]": vip is not on this host!
        echo "[""${time}""]": VIP is not on this host, stop FreeSWITCH Service! >>/var/rainny/cti/log/freeswitch.log
        pid=`ps -ef | grep "freeswitch" | grep -v grep | awk '{print $2}'`
        if [ "${pid}" = "" ]
        then
			echo "[""${time}""]": FreeSWITCH Service is Not Running >>/var/rainny/cti/log/freeswitch.log
        else
			echo "[""${time}""]": Shutdown FreeSWITCH >>/var/rainny/cti/log/freeswitch.log
			kill -9 "${pid}"
			echo "[""${time}""]": FreeSWITCH Service has been closed >>/var/rainny/cti/log/freeswitch.log
        fi
fi
sleep 7
done

Reference

https://www.cnblogs.com/sssblog/p/10273148.html

https://www.cnblogs.com/wangkongming/p/4221503.html

内容概要:文章详细介绍了ETL工程师这一职业,解释了ETL(Extract-Transform-Load)的概念及其在数据处理中的重要性。ETL工程师负责将分散、不统一的数据整合为有价值的信息,支持企业的决策分析。日常工作包括数据整合、存储管理、挖掘设计支持和多维分析展现。文中强调了ETL工程师所需的核心技能,如数据库知识、ETL工具使用、编程能力、业务理解能力和问题解决能力。此外,还盘点了常见的ETL工具,包括开源工具如Kettle、XXL-JOB、Oozie、Azkaban和海豚调度,以及企业级工具如TASKCTL和Moia Comtrol。最后,文章探讨了ETL工程师的职业发展路径,从初级到高级的技术晋升,以及向大数据工程师或数据产品经理的横向发展,并提供了学习资源和求职技巧。 适合人群:对数据处理感兴趣,尤其是希望从事数据工程领域的人士,如数据分析师、数据科学家、软件工程师等。 使用场景及目标:①了解ETL工程师的职责和技能要求;②选择适合自己的ETL工具;③规划ETL工程师的职业发展路径;④获取相关的学习资源和求职建议。 其他说明:随着大数据技术的发展和企业数字化转型的加速,ETL工程师的需求不断增加,尤其是在金融、零售、制造、人工智能、物联网和区块链等领域。数据隐私保护法规的完善也使得ETL工程师在数据安全和合规处理方面的作用更加重要。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值