keepalived配置使用

keepalived安装

tar -zxvf ***
yum install -y gcc gcc-c++ wget popt-devel openssl openssl-devel
yum install -y libnl libnl-devel libnl3 libnl3-devel
yum install -y libnfnetlink-devel
./configure --sysconf=/etc
make
make install

master1 编辑keepalived的配置文件keepalived.conf

global_defs {
notification_email {
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL_A
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER
interface ens160 #自己的网卡
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.111 #自己网段的虚拟ip
}
}

master2 keepalived的配置文件

global_defs {
notification_email {
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL_B
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state SLAVE
interface ens160
virtual_router_id 52
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.111
}
}

启动keepalived

systemctl start keepalived.service
systemctl enable keepalived.service

查看IP地址信息

keepalived配置使用_第1张图片

可以看到自己配置的虚拟ip

之后就可以用这个虚拟ip链接mysql,并且停掉一台服务器也可以操作数据库

你可能感兴趣的:(linux,服务器,运维)