keepalived需要用到虚拟ip.如果用虚拟机做的话.直接做虚拟网卡即可,但是线上不一样.具体如下所示:
1.登录华为云账户,进入控制台。选择服务列表
2.选择"网络" > 虚拟私有云VPC
3.根据网段选择创建好的VPC.
注:如果没有vpc.那么需要新建,页面右上角有创建VPC按钮
4.点击"elk-vpc",显示其内容,分别为:
5.选择子网"subnet"
6.选择"虚拟IP地址",会有选项"申请虚拟ip地址",如下所示
7.点击"申请虚拟Ip地址"后,会弹出窗口,如下所示
一般都是手动分配ip地址,填写需要的IP地址后.点击确定.如下所示
会显示出申请后的虚拟ip地址的情况,右边的绑定功能就是我们需要的.图中所示是我已绑定的服务器.
8.选择想要做keepalived的服务器名,按照提示操作就行了.
9.绑定成功后,需要到keepalived的主服务器设置vip.
10.通过cp新建虚拟网卡,
cp /etc/sysconfig/network-scripts/ifcfg-eth0{,':1'}
11.对该网卡进行编辑
vim /etc/sysconfig/network-scripts/ifcfg-eth0:1
DEVICE="eth0:1" #这里必改,与文件名同样
BOOTPROTO="static" #静态ip地址
ONBOOT="yes" #开机自启
TYPE="Ethernet"
PERSISTENT_DHCLIENT="yes"
IPADDR=192.168.1.100 #申请的虚拟vip
GATEWAY=192.168.1.1 #一般为1.如果不清楚,可以到vpc页面查看
NETMASK=255.255.255.0
ONPARENT=yes
12.设置完成后,记得机器(reboot)
13.启动后,通过指令ifconfig得出如下信息:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::f816:3eff:fe7f:7311 prefixlen 64 scopeid 0x20<link>
ether fa:16:3e:7f:73:11 txqueuelen 1000 (Ethernet)
RX packets 180 bytes 26080 (25.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 281 bytes 28003 (27.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0eth0:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
ether fa:16:3e:7f:73:11 txqueuelen 1000 (Ethernet)lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 2 bytes 272 (272.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 272 (272.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
注:如果是通过命令ip a s 查看的话,则显示如下:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether fa:16:3e:7f:73:11 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global noprefixroute dynamic eth0
valid_lft 31535939sec preferred_lft 31535939sec
inet 192.168.1.100/24 brd 192.168.1.255 scope global secondary noprefixroute eth0:1
valid_lft forever preferred_lft forever
inet6 fe80::f816:3eff:fe7f:7311/64 scope link
valid_lft forever preferred_lft forever
14.下载keepalive及配置,见另外的帖子:
至此,基于华为云搭建步骤完成.如果不够清楚可以看华为云自带的说明文档.
写这个博的原因是为了总结几点经验:
第一:ifconfig跟ipaddress show的不同;
第二:线上平台的偏移
偏移前:
漂移后
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.11 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::f816:3eff:feb9:1c4a prefixlen 64 scopeid 0x20<link>
ether fa:16:3e:b9:1c:4a txqueuelen 1000 (Ethernet)
RX packets 18488 bytes 1080133 (1.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3004 bytes 288380 (281.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 2 bytes 272 (272.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 272 (272.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
但是用命令ip a s 显示偏移后的结果为:
[root@lb-nginx02 ~]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether fa:16:3e:b9:1c:4a brd ff:ff:ff:ff:ff:ff
inet 192.168.1.11/24 brd 192.168.1.255 scope global noprefixroute dynamic eth0
valid_lft 31519810sec preferred_lft 31519810sec
inet 192.168.1.100/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::f816:3eff:feb9:1c4a/64 scope link
valid_lft forever preferred_lft forever
应该是ifconfig 跟ip a s的工具差异.但是在虚拟机操作时候.两者基本都能 看的.这个也就是个人能力问题了.后续深究;
主要是不知道是不是华为云平台的问题(弱弱的没自信),会出现192.168.1.100/32这样的ip偏移:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether fa:16:3e:7f:73:11 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global noprefixroute dynamic eth0
valid_lft 31535127sec preferred_lft 31535127sec
inet 192.168.1.100/32 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.1.100/24 brd 192.168.1.255 scope global secondary noprefixroute eth0:1
valid_lft forever preferred_lft forever
inet6 fe80::f816:3eff:fe7f:7311/64 scope link
valid_lft forever preferred_lft forever
能保证的是同样的操作,但是也有可能是业务能力理解得还不够,写这个boke mark下,以后有时间再研究