前言
nginx使用docker部署;keepalived使用传统部署。 准备两台服务器:192.168.1.6 和192.168.1.7
部署keepalived
keepalived可以将多个无状态的单点通过虚拟IP(VIP)漂移的方式搭建成一个高可用服务
这里下载最新的版本V2.2.7:
- 先决条件-安装基础依赖
-
#RHEL/CentOS
yum install curl gcc openssl-devel libnl3-devel net-snmp-devel
# Ubuntu
apt-get install curl gcc libssl-dev libnl-3-dev libnl-genl-3-dev libsnmp-dev
tar -xzvf keepalived-2.2.7.tar.gz
cd keepalived-2.2.7
./configure --prefix=/usr/local/keepalived-2.2.7 --sysconf=/etc prefix:keepalived安装位置 sysconf:keepalived配置文件位置,默认/etc
编译
make
安装
sudo make install
配置
创建/etc/keepalived/keepalived.conf配置文件: 主节点(MASTER)的配置:
global_defs { router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 1 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.100 } }
子节点(BACKUP)的配置:
global_defs { router_id LVS_DEVEL } vrrp_instance VI_1 { state BACKUP interface ens33 virtual_router_id 2 priority 90 advert_int 1 nopreemt authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.100 } }
解释:
state MASTER
表示该节点为主节点;
virtual_router_id 1
虚拟路由id,取值范围0-255,主节点(MASTER)和子节点(BACKUP)不要设置一致;
interface ens33
指定网卡名称,使用ip addr
查看;
advert_int 1
主、子节点心跳频率,单位为秒
mcast_src_ip 192.168.1.6
指定节点的IP地址;
authentication
用户名密码,主节点(MASTER)和子节点(BACKUP)设置一致;
virtual_ipaddress { 192.168.1.100 }
虚拟IP(VIP)地址,待会测试就是使用该IP地址访问;最好跟服务器同一个网段;主节点(MASTER)和子节点(BACKUP)设置一致;
keepalived.service
文件
[Unit] Description=Keepalived After=network.target [Service] ExecStart=/usr/local/keepalived-2.2.7/sbin/keepalived -D ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure Type=forking [Install] WantedBy=multi-user.target请确保将
ExecStart
的路径 /usr/local/keepalived-2.2.7/sbin/keepalived
替换为你 Keepalived 实际安装的路径
将创建的 keepalived.service
文件移动到 /etc/systemd/system/
目录中:
sudo mv keepalived.service /etc/systemd/system/
重新加载 systemd 配置
sudo systemctl daemon-reload
启动 Keepalived 服务
sudo systemctl start keepalived
重启
systemctl restart keepalived
停止
systemctl stop keepalived
查看运行状态
systemctl status keepalived
开机自启
systemctl enable keepalived
主节点和子节点都启动keepalived
,通过VIP访问,默认访问到主节点
标签:keepalived,192.168,id,MASTER,virtual,Ubuntu,安装,节点,keepalive From: https://www.cnblogs.com/Mr-shen/p/17850038.html