高可用集群keepalived
keepalived里面用到的核心技术是什么?
VRRP:虚拟路由冗余协议,解决静态网关单点风险
物理层包括:路由器(主设备、备用设备)、三层交换机(用于连接主备设备)
软件层:keepalived
相关技术:
主备设备连接--心跳线
主备设备优先级
主备设备工作方式:抢占式、非抢占式
主备设备安全认证
工作模式:主备 主主 备主(虚拟路由器2)
linux里面配置集群有哪些
LB:负载均衡集群 典型代表:LVS/HAProxy/nginx
HA:高可用集群 典型代表:keepalived实现无状态应用的高可用。mysql、redis等有状态应用通过自身的高可用解决方案 如mysql的组复制、pxc。
HPC:高性能集群
Keepalived 架构和安装
官网:http://keepalived.org/
包安装
#CentOS
[root@centos ~]#yum -y install keepalived
#ubuntu
[root@ubuntu2004 ~]#apt -y install keepalived
Ubuntu 安装 keepalived
[root@ubuntu2004 ~]#apt -y install keepalived
#默认没有配置文件无法启动
#利用范例生成配置文件
[root@ubuntu2004 ~]#cp /usr/share/doc/keepalived/samples/keepalived.conf.sample /etc/keepalived/keepalived.conf
[root@ubuntu2004 ~]#systemctl start keepalived.service
查看进程
[root@ubuntu2004 ~]#ps auxf |grep keepalived
脚本编译安装
[root@ubuntu2004 ~]#cat install_keepalived.sh
#!/bin/bash
KEEPALIVED_VERSION=2.2.7
#KEEPALIVED_VERSION=2.2.2
#KEEPALIVED_VERSION=2.0.20
KEEPALIVED_FILE=keepalived-${KEEPALIVED_VERSION}.tar.gz
KEEPALIVED_INSTALL_DIR=/apps/keepalived
SRC_DIR=/usr/local/src
KEEPALIVED_URL=https://keepalived.org/software/
CPUS=`grep -c processor /proc/cpuinfo`
. /etc/os-release
color () {
RES_COL=60
MOVE_TO_COL="echo -en 33[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en 33[1;32m"
SETCOLOR_FAILURE="echo -en 33[1;31m"
SETCOLOR_WARNING="echo -en 33[1;33m"
SETCOLOR_NORMAL="echo -en E[0m"
echo -n "$1" && $MOVE_TO_COL
echo -n "["
if [ $2 = "success" -o $2 = "0" ] ;then
${SETCOLOR_SUCCESS}
echo -n $" OK "
elif [ $2 = "failure" -o $2 = "1" ] ;then
${SETCOLOR_FAILURE}
echo -n $"FAILED"
else
${SETCOLOR_WARNING}
echo -n $"WARNING"
fi
${SETCOLOR_NORMAL}
echo -n "]"
echo
}
download_file (){
cd ${SRC_DIR}
if [ $ID = 'centos' -o $ID = 'rocky' ];then
rpm -q wget &> /dev/null || yum -y install wget
elif [ $ID = 'ubuntu' ];then
dpkg -l |grep wget || { apt update; apt install -y wget; }
else
color "不支持此操作系统,退出!" 1
exit
fi
if [ ! -e ${KEEPALIVED_FILE} ];then
wget --no-check-certificate ${KEEPALIVED_URL}${KEEPALIVED_FILE}
[ $? -ne 0 ] && { color "KEEPALIVED源码包下载失败" 1 ; exit; }
fi
}
install_keepalived () {
if [ $ID = 'centos' -o $ID = 'rocky' ];then
yum -y install make gcc ipvsadm autoconf automake openssl-devel libnl3-devel iptables-devel net-snmp-devel glib2-devel pcre2-devel libmnl-devel systemd-devel &> /dev/null
elif [ $ID = 'ubuntu' ];then
apt update
apt -y install make gcc ipvsadm build-essential pkg-config automake autoconf libipset-dev libnl-3-dev libnl-genl-3-dev libssl-dev libxtables-dev libip4tc-dev libip6tc-dev libipset-dev libmagic-dev libsnmp-dev libglib2.0-dev libpcre2-dev libnftnl-dev libmnl-dev libsystemd-dev
else
color "不支持此操作系统,退出!" 1
fi
tar xf ${KEEPALIVED_FILE}
cd keepalived-${KEEPALIVED_VERSION}
./configure --prefix=${KEEPALIVED_INSTALL_DIR} --disable-fwmark
make -j $CPUS && make install
if [ $? -eq 0 ];then
color "KEEPALIVED编译安装成功" 0
else
color "KEEPALIVED编译安装失败,退出!" 1
exit
fi
[ -d /etc/keepalived ] || mkdir -p /etc/keepalived
cp ${KEEPALIVED_INSTALL_DIR}/etc/keepalived/keepalived.conf.sample /etc/keepalived/keepalived.conf
cp ./keepalived/keepalived.service /lib/systemd/system/
}
start_keepalived () {
systemctl daemon-reload
systemctl enable --now keepalived &> /dev/null
systemctl is-active keepalived
if [ $? -eq 0 ] ;then
color "Keepalived 服务安装成功!" 0
else
color "Keepalived 服务安装失败!" 1
exit 1
fi
}
download_file
install_keepalived
start_keepalived
安装后查看状态
[root@ubuntu2004 ~]#systemctl status keepalived.service
查看IP
inet 192.168.200.16/32 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.200.17/32 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.200.18/32 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe69:a082/64 scope link
ping生成的这些IPping不通,要把配置文件中的vrrp_strict取消掉
[root@ubuntu2004 ~]#ping 192.168.200.16
PING 192.168.200.16 (192.168.200.16) 56(84) bytes of data.
ping: sendmsg: 不允许的操作
[root@ubuntu2004 ~]#vim /etc/keepalived/keepalived.conf
#vrrp_strict
[root@ubuntu2004 ~]#systemctl restart keepalived.service
[root@ubuntu2004 ~]#ping 192.168.200.16
PING 192.168.200.16 (192.168.200.16) 56(84) bytes of data.
64 字节,来自 192.168.200.16: icmp_seq=1 ttl=64 时间=0.027 毫秒
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
人工智能本质上是一种“复制”,它通过技术分析方法将现实作者的“风格”提取出来,再借由大量的“素材”整合出带有这些“风格”的新作品,而现阶段这种创作还谈不上“创新”,但“创新”也只是时间问题。 人类社会一直存在这样的“复制”,学习、师承都是对前人的“风格”的复制…