1. 安装LVS集群
1)查看安装LVS管理工具:
- LVS-server主
[root@lvs-server ~]# rpm -qa ipvsadm
[root@lvs-server ~]# yum install ipvsadm -y
Installed:
ipvsadm.x86_64 0:1.27-7.el7
Complete!
[root@lvs-server ~]# rpm -qa ipvsadm
ipvsadm-1.27-7.el7.x86_64
[root@lvs-server ~]#
- LVS-server备
[root@lvs2-server ~]# yum install ipvsadm -y
Installed:
ipvsadm.x86_64 0:1.27-7.el7
Complete!
[root@lvs2-server ~]# rpm -qa ipvsadm
ipvsadm-1.27-7.el7.x86_64
[root@lvs2-server ~]#
2)内核层面的,所以需要链接一下:
- LVS-server主
[root@lvs-server ~]# ln -s /usr/src/kernels/`uname -r` /usr/src/linux
[root@lvs-server ~]# ll /usr/src/
total 0
drwxr-xr-x. 2 root root 6 Mar 10 2016 debug
drwxr-xr-x. 2 root root 6 Mar 10 2016 kernels
lrwxrwxrwx 1 root root 38 Aug 31 15:09 linux -> /usr/src/kernels/3.10.0-514.el7.x86_64
- LVS-server备
[root@lvs2-server ~]# ln -s /usr/src/kernels/`uname -r` /usr/src/linux
[root@lvs2-server ~]# ll /usr/src/
total 0
drwxr-xr-x. 2 root root 6 Mar 10 2016 debug
drwxr-xr-x. 2 root root 6 Mar 10 2016 kernels
lrwxrwxrwx 1 root root 38 Aug 31 15:21 linux -> /usr/src/kernels/3.10.0-514.el7.x86_64
3)内核中查看ipvs:没有的话输入命令(ipvsadm、modprobe ip_vs)
- LVS-server主
[root@lvs-server ~]# ipvsadm #
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@lvs-server ~]# lsmod | grep ip_vs
ip_vs 141092 0
nf_conntrack 111302 8 ip_vs,nf_nat,nf_nat_ipv4,nf_nat_ipv6,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_ipv4,nf_conntrack_ipv6
libcrc32c 12644 2 xfs,ip_vs
- LVS-server备
[root@lvs2-server ~]# modprobe ip_vs
[root@lvs2-server ~]# lsmod | grep ip_vs
ip_vs 141092 0
nf_conntrack 111302 6 ip_vs,nf_nat,nf_nat_ipv4,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_ipv4
libcrc32c 12644 2 xfs,ip_vs
2.配置LVS负载均衡服务
2.1 DR模式
使用vip:10.0.0.10,域名www.example.com(对应服务)。
1)给LVS配置VIP地址:
- LVS-server主
[root@lvs-server ~]# ip addr