查看本机所知道的其他机器的地址
[root@node12 ~]# arp -a
? (192.168.92.1) at 00:50:56:c0:00:08 [ether] on eth0
[root@node12 ~]#
配置VIP
ifconfig etho:2 192.168.92.100/24
这种是临时配置,一旦系统重启就会失效
找三台配置网络:
[root@node13 ~]# echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
[root@node13 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@node13 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@node13 ~]# echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
[root@node13 ~]# ifconfig lo:2 192.168.92.100 netmask 255.255.255.255
[root@node13 ~]#
下载httpd镜像
yum install httpd -y
分别去三台虚拟机上去修改地址:
[root@node14 ~]# cd /var/www/html/
[root@node14 html]# ll
total 0
[root@node14 html]# vi index.html
[root@node14 html]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualifie
d domain name, using 192.168.92.14 for ServerName [ OK ]
[root@node14 html]# cat index.html
from 192.168.92.14
[root@node14 html]#
安装负载均衡服务器:
[root@node11 ~]# yum install ipvsadm -y
[root@node11 ~]# ipvsadm -A -t 192.168.92.100:80 -s rr
[root@node11 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.92.100:80 rr
[root@node11 ~]#
创建链接:
[root@node11 ~]# ipvsadm -a -t 192.168.92.100:80 -r 192.168.92.13:80 -g
[root@node11 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.92.100:80 rr
-> 192.168.92.13:80 Route 1 0 0
[root@node11 ~]# ipvsadm -a -t 192.168.92.100:80 -r 192.168.92.14:80 -g
[root@node11 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.92.100:80 rr
-> 192.168.92.13:80 Route 1 0 0
-> 192.168.92.14:80 Route 1 0 0
[root@node11 ~]#
这就设置完了负载均衡
[root@node11 ~]# ipvsadm -lnc
可以将其中一个down掉:
[root@node14 ~]# ifconfig lo:2 down
拷贝与重命名的区别:
[root@node11 keepalived]# cp keepalived.conf keepalived.conf.bak
[root@node11 keepalived]# mv keepalived.conf.bak keepalived.conf.bak
mv: `keepalived.conf.bak' and `keepalived.conf.bak' are the same file
[root@node11 keepalived]#
在编辑的时候,删除3行使用3dd进行删除
在Linux系统中设置开机启动:
[root@node11 keepalived]# chkconfig keepalived on
在Linux系统中复制与黏贴
复制使用y
黏贴使用p
当要复制某一部分的时候,将光标移动到要复制部分的第一行位置,然后按下:.,$-1y
黏贴的时候,将光标移动到最后边,按下p
添加:
ifconfig lo:8 192.168.92.100 netmask 255.255.255.255
将keepalivede文件进行复制分发:
[root@node11 keepalived]# scp ./keepalived.conf [email protected]:'pwd'
The authenticity of host '192.168.92.15 (192.168.92.15)' can't be established.
RSA key fingerprint is 6f:ee:0e:76:34:f5:dc:e2:96:27:f1:cd:b4:d5:9f:36.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.92.15' (RSA) to the list of known hosts.
[email protected]'s password:
keepalived.conf 100% 1257 1.2KB/s 00:00
[root@node11 keepalived]# ll
total 4
-rw-r--r-- 1 root root 1257 Dec 16 10:25 keepalived.conf
[root@node11 keepalived]#
之前是使用yum下载keepalived,下载进行安装
Yum iinstall keepalived -y
然后cd进入/etc/keepalived,之后进行配置:
将keepalived.conf文件进行备份,然后进入修改:使得能够和其他的两台进行安装
修改完成之后进行启动:
service keepalived start
然后将该文件复制分发:
[root@node11 keepalived]# scp ./keepalived.conf [email protected]:/etc/keepalived
然后进入15节点去配置:
将master改为backup
然后将权重值由100改为50
priority 50
[root@node15 keepalived]# ifconfig去查看的时候,不会显示ip地址,因为11上边是master并且还处于活跃状态
[root@node15 keepalived]# ipvsadm -ln
去检查内存模块是正常的状态
将ipvsadm挂掉的命令:
[root@node13 ~]# ifconfig lo:2 down
去检查
[root@node11 keepalived]# curl 192.168.92.13:80
from 192.168.92.13
[root@node11 keepalived]#
配置:
[root@node13 ~]# ifconfig lo:8 192.168.92.100 netmask 255.255.255.255
停止服务:
Service httpd stop
将网卡down掉:
[root@node11 keepalived]# ifconfig eth0 down
启动网卡:
Ifconfig eth0 up(需要去workstation上进行设置)
检查进程:
ps -fe | grep keepalived
杀死进程:
[root@node11 ~]# kill -9 1184
————————————————————————————————————
正确的杀死方式是:
因为lvs和nginx之间有冲突,版本不兼容,所以需要将搭建的lvs进程停止
[root@node11 ~]# service keepalived stop
启动的话是使用:
[root@node11 ~]# service keepalived start
想要查看状态:
[root@node11 ~]# ifconfig
这样也可以进行查看验证:
[root@node11 ~]# ipvsadm -ln
以上是将主机的杀死了,还有备机上边的,也需要去进行杀死,方法与主机上边的相同。