centos7配置虚拟ip_centos临时设置ip

2022-11-07 17:20:31 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

环境概览

master:192.168.46.26 slave1:192.168.46.27 测试机:192.168.46.22(用于ping机器)

安装keepalived

代码语言:javascript复制
 yum install -y keepalived

修改master keepalived.conf 配置文件

代码语言:javascript复制
vim /etc/keepalived/keepalived.conf

interface 修改为自己的网卡(使用 ip addr 查看) priority 修改其参数为188 设置为主节点 virtual_ipaddress 配置虚拟ip

重启 keepalive 服务
代码语言:javascript复制
 systemctl restart keepalived.service
查看 虚ip是否启动成功
代码语言:javascript复制
ip addr
代码语言:javascript复制
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:f5:3d:f3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.46.26/18 brd 192.168.63.255 scope global ens33
       valid_lft forever preferred_lft forever
    `inet 192.168.46.88/32 scope global ens33`
       valid_lft forever preferred_lft forever
    inet6 fe80::345:1d44:e755:79c2/64 scope link
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
    link/ether 52:54:00:63:02:0a brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
    link/ether 52:54:00:63:02:0a brd ff:ff:ff:ff:ff:ff

inet 192.168.46.88/32 scope global ens33 表示成功启动虚拟ip

修改slave1 keepalived.conf 配置文件

代码语言:javascript复制
vim /etc/keepalived/keepalived.conf

interface 修改为自己的网卡(使用 ip addr 查看) priority 默认即可 virtual_ipaddress 配置虚拟ip

重启 keepalive 服务
代码语言:javascript复制
 systemctl restart keepalived.service
查看 虚ip是否启动成功
代码语言:javascript复制
ip addr
代码语言:javascript复制
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:63:37:39 brd ff:ff:ff:ff:ff:ff
    inet 192.168.46.27/18 brd 192.168.63.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::34aa:c1e2:dc99:6721/64 scope link
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
    link/ether 52:54:00:63:02:0a brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
    link/ether 52:54:00:63:02:0a brd ff:ff:ff:ff:ff:ff

此节点作为从节点使用当主节点挂掉后,会使用此节点

使用测试机器ping 虚拟ip 看是否可以ping通

代码语言:javascript复制
# ping 192.168.46.88
PING 192.168.46.88 (192.168.46.88) 56(84) bytes of data.
64 bytes from 192.168.46.88: icmp_seq=1 ttl=64 time=0.149 ms
64 bytes from 192.168.46.88: icmp_seq=2 ttl=64 time=0.303 ms
64 bytes from 192.168.46.88: icmp_seq=3 ttl=64 time=0.380 ms
64 bytes from 192.168.46.88: icmp_seq=4 ttl=64 time=0.239 ms
64 bytes from 192.168.46.88: icmp_seq=5 ttl=64 time=0.324 ms

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/182991.html原文链接:https://javaforall.cn

0 人点赞