一、集群
多个节点部署同一个服务就是集群
二、Keepalived概念
1、解决单点故障
2 、组件免费
3、 可用实现高可用HA机制
4、 基于VRRP 协议
三、安装 Keepalived
(1)下载地址: https://www.keepalived.org/software/keepalived-2.0.18.tar.gz
(2) 解压
tar -zxvf keepalived-2.0.18.tar.gz
(3)解压后进入到解压出来的目录,看到会有 configure ,那么就可用做配置了(配置安装和nginx一模一样)
(4)使用 configure 命令配置安装目录与核心配置文件所在位置
./configure --prefix=/usr/local/keepalived --sysconf=/etc
prefix:keepalived安装的位置
sysconf:keepalived核心配置文件所在位置,固定位置,改成其他位置keepalived启动不了,/var/log/messages中会报错
a) 配置过程中可能会出现警告信息,如下所示
*** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS.
b) 安装 libnl/libnl-devel依赖
yum -y install libnl libnl-devel
c) 重新configure 一下,此时OK
(5)安装keepalived
make && make install
(6) 进入到 /etc/keepalived,该目录下为keepalived核心配置文件
四、配置 Keepalived - 主
1、通过命令 vim keepalived.conf 打开配置文件
global_defs { # 路由id:当前安装keepalived的节点主机标识符,保证全局唯一 router_id keep_171 } vrrp_instance VI_1 { # 表示状态是MASTER主机还是备用机BACKUP state MASTER # 该实例绑定的网卡 interface ens33 # 保证主备节点一致即可 virtual_router_id 51 # 权重,master权重一般高于backup,如果有多个,那就是选举,谁的权重高,谁就当选 priority 100 # 主备之间同步检查时间间隔,单位秒 advert_int 2 # 认证权限密码,防止非法节点进入 authentication { auth_type PASS auth_pass 1111 } # 虚拟出来的ip,可以有多个(vip) virtual_ipaddress { 192.168.1.161 } }
附:查看网卡名称
ip addr
2.启动Keepalived
3.查看vip
五、配置 Keepalived -备
1. 通过命令 vim keepalived.conf 打开配置文件
global_defs { router_id keep_172 } vrrp_instance VI_1 { # 备用机设置为BACKUP state BACKUP interface ens33 virtual_router_id 51 # 权重低于MASTER priority 80 advert_int 2 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { # 注意:主备两台的vip都是一样的,绑定到同一个vip 192.168.1.161 } }
六、配置 Keepalived双主热备
规则:以一个虚拟ip分组归为同一路由
global_defs { router_id keep_171 } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.161 } } vrrp_instance VI_2 { state BACKUP interface ens33 virtual_router_id 52 priority 80 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.162 } }
备用节点配置
global_defs { router_id keep_172 } vrrp_instance VI_1 { state BACKUP interface ens33 virtual_router_id 51 priority 80 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.161 } } vrrp_instance VI_2 { state MASTER interface ens33 virtual_router_id 52 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.162 } }