Centos8 Keepalived安装以及yum源404问题
最近打算用keepalive做nginx集群,在使用yum 安装的时候yum源报404, 虽然说用安装包安装也行,但是yum安装还是很方便,下来就解决这个问题
1.先cd /etc/yum.repos.d
2.删除 /etc/yum.repos.d 目录中的所有文件,替换 /etc/yum.repos.d 目录中的 CentOS-Base.repo 内容。
[base]
name=CentOS-8-stream - Base - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos/8-stream/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS-8-stream - Extras - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos/8-stream/extras/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-8-stream - Plus - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos/8-stream/centosplus/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-8-stream - PowerTools - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos/8-stream/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-8-stream - AppStream - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos/8-stream/AppStream/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
3.然后执行
yum clean all
yum makecache
4.安装keepalived
可以 执行 yum search keepalived 或者 yum search all keepalived搜索yum库有没有
执行命令 yum install -y keepalived
5.查看安装位置
执行 rpm -ql keepalived
6.启动
yum安装完后默认回添加到 系统服务中 执行
service keepalived start
已经启动:
如果你是以安装包的方式安装需要自己添加到系统服务中,一般都在/usr/local/src下安装,以下以此目录为例 将keepalived添加到系统服务:
步骤:
安装步骤:
wget http://www.keepalived.org/software/keepalived-2.0.19.tar.gz
tar -zvxf keepalived-2.0.19.tar.gz
cd keepalived-2.0.19
./configure --prefix=/usr/local/keepalived
#如果出现错误*** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS.
#执行:yum -y install libnl libnl-devel
make && make install
添加到系统服务 以service keepalived start 方式启动步骤:
cp /usr/local/src/keepalived-2.0.19/keepalived/etc/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
//在etc下创建 keepalived 目录
mkdir /etc/keepalived/
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
echo "/etc/init.d/keepalived start" >> /etc/rc.local
chmod +x /etc/rc.d/init.d/keepalived
chkconfig keepalived on
#相关启动命令
service keepalived start
service keepalived restart
service keepalived stop
#主备打开ip_forward转发功能
echo "1" > /proc/sys/net/ipv4/ip_forward
keepalived 主机 config配置
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_Master
}
vrrp_instance VI_1 {
state MASTER #指定instance初始状态,实际根据优先级决定.backup节点不一样
interface eth0 #虚拟IP所在网卡 根据实际情况填写自己的
virtual_router_id 51 #VRID,相同VRID为一个组,决定多播MAC地址
priority 100 #优先级,另一台改为90.backup节点不一样
advert_int 1 #检查间隔
authentication {
auth_type PASS #认证方式,可以是pass或ha
auth_pass 123456 #认证密码
}
virtual_ipaddress {
192.168.37.112 #VIP
}
# 三个指令,如果主机状态变成Master|Backup|Fault之后会去执行的通知脚本,脚本要自己写
notify_master ""
notify_backup ""
notify_fault ""
}
备机配置:
唯一不同的就是state、priority以及router_id
备用上的keepalived.conf配置
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_Backup
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.37.112
}
}
配置完成后 启动两个 keepalived 执行 ip a 查看 绑定的服务
当主节点挂掉 vip会挂到 备机上
启动master vip 会挂到 master上
如果你喜欢本文
请长按二维码,关注 不吃肉的犟驴