lvs集群

打印 上一主题 下一主题

主题 227|帖子 227|积分 681

nat模式


实验条件

除了测试主机,其他三台主机都必要添加或修改网卡,修改如以下显示
lvs主机




server1主机和server2主机




创建实验环境

lvs主机

  1. [root@lvs ~]# vmset.sh eth0 172.25.250.100 lvs
  2. [root@lvs ~]# vmset.sh eth1 192.168.0.100 lvs
  3. ###########eth1仅主机网卡
  4. [root@lvs ~]# vim /etc/NetworkManager/system-connections/eth1.nmconnection
  5. [root@lvs ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection
  6. [connection]
  7. id=eth1
  8. type=ethernet
  9. interface-name=eth1
  10. [ipv4]
  11. address1=192.168.0.100/24      
  12. method=manual
  13. ##########eth0 NAT网卡
  14. [root@lvs ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
  15. [connection]
  16. id=eth0
  17. type=ethernet
  18. interface-name=eth0
  19. [ipv4]
  20. address1=172.25.250.100/24,172.25.250.2
  21. method=manual
  22. [root@lvs ~]# nmcli connection reload
  23. [root@lvs ~]# nmcli connection up eth0
  24. [root@lvs ~]# nmcli connection up eth1
  25. ################打开内核路由,使eth1和eth0通信
  26. [root@lvs ~]# sysctl -a | grep ip_forward
  27. net.ipv4.ip_forward = 0
  28. net.ipv4.ip_forward_update_priority = 1
  29. net.ipv4.ip_forward_use_pmtu = 0
  30. [root@lvs ~]# echo net.ipv4.ip_forward = 1 > /etc/sysctl.conf
  31. [root@lvs ~]# sysctl -p     //使其生效
  32. net.ipv4.ip_forward = 1
复制代码


server1主机

  1. [root@server1 ~]# vmset.sh eth0 192.168.0.10 server1
  2. [root@server1 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
  3. [connection]
  4. id=eth0
  5. type=ethernet
  6. interface-name=eth0
  7. [ipv4]
  8. address1=192.168.0.10/24,192.168.0.100    //server1主机网关指向lvs主机
  9. method=manual
  10. [root@server1 ~]# nmcli connection reload
  11. [root@server1 ~]# nmcli connection up eth0
复制代码
server2主机

  1. [root@server2 ~]# vmset.sh eth0 192.168.0.20 server1
  2. [root@server2 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
  3. [connection]
  4. id=eth0
  5. type=ethernet
  6. interface-name=eth0
  7. [ipv4]
  8. address1=192.168.0.20/24,192.168.0.100    //server2主机网关指向lvs主机
  9. method=manual
  10. [root@server2 ~]# nmcli connection reload
  11. [root@server2 ~]# nmcli connection up eth0
复制代码
开始实验(基于httpd)

lvs主机下载安装ipvsadm

  1. [root@lvs ~]# yum install ipvsadm -y
  2. [root@lvs ~]# ipvsadm -Ln               //查看策略
  3. IP Virtual Server version 1.2.1 (size=4096)
  4. Prot LocalAddress:Port Scheduler Flags
  5.   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
复制代码
布置策略

  1. [root@lvs ~]# ipvsadm -A -t 172.25.250.100:80  -s rr     
  2. // -A 添加    // -t 指定TCP协议    //-s 指定算法   rr // 轮寻(你一个我一个....静态)
  3. [root@lvs ~]# ipvsadm -a -t 172.25.250.100:80 -r 192.168.0.10:80 -m
  4. [root@lvs ~]# ipvsadm -a -t 172.25.250.100:80 -r 192.168.0.20:80 -m
  5. [root@lvs ~]# ipvsadm -Ln
  6. IP Virtual Server version 1.2.1 (size=4096)
  7. Prot LocalAddress:Port Scheduler Flags
  8.   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
  9. TCP  172.25.250.100:80 rr
  10.   -> 192.168.0.10:80              Masq    1      0          0         
  11.   -> 192.168.0.20:80              Masq    1      0          0        
复制代码
server1,server2主机

  1. [root@server1 ~]# yum install httpd -y  //安装httpd
  2. [root@server1 ~]# echo this is server1 > /var/www/html/index.html
  3. [root@server2 ~]# echo this is server2 > /var/www/html/index.html
复制代码
测试

  1. [root@rhel9 ~]# for i in {1..10}
  2. > do
  3. > curl 172.25.250.100
  4. > done
  5. this is server1
  6. this is server2
  7. this is server1
  8. this is server2
  9. this is server1
  10. this is server2
  11. this is server1
  12. this is server2
  13. this is server1
  14. this is server2
复制代码
DR模式


创建环境

client主机

  1. [root@client ~]# vmset.sh 172.25.250.200 client
  2. [root@client ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
  3. [connection]
  4. id=eth0
  5. type=ethernet
  6. interface-name=eth0
  7. [ipv4]
  8. address1=172.25.250.200/24,172.25.250.100
  9. method=manual
  10. dns=114.114.114.114;
复制代码
router主机

  1. [root@router ~]# vmset.sh 172.25.250.100 router
  2. [root@router ~]# vmset.sh 192.168.0.100 router
  3. [root@router ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
  4. [connection]
  5. id=eth0
  6. type=ethernet
  7. interface-name=eth0
  8. [ipv4]
  9. address1=172.25.250.100/24,172.25.250.2
  10. method=manual
  11. dns=114.114.114.114;
  12. [root@router ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection
  13. [connection]
  14. id=eth1
  15. type=ethernet
  16. interface-name=eth1
  17. [ipv4]
  18. address1=192.168.0.100/24
  19. method=manual
  20. dns=114.114.114.114;
  21. ################打开内核路由,使eth1和eth0通信
  22. [root@router ~]# sysctl -a | grep ip_forward
  23. net.ipv4.ip_forward = 0
  24. net.ipv4.ip_forward_update_priority = 1
  25. net.ipv4.ip_forward_use_pmtu = 0
  26. [root@router ~]# echo net.ipv4.ip_forward = 1 > /etc/sysctl.conf
  27. [root@router ~]# sysctl -p     //使其生效
  28. net.ipv4.ip_forward = 1
复制代码
lvs主机

  1. [root@lvs ~]# nmcli connection delete eth0  //删掉eth0网卡ip,我们用lo环回来做一次性ip
  2. [root@lvs ~]# vmset.sh eth1 192.168.0.200 lvs
  3. [root@lvs ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection
  4. [connection]
  5. id=eth1
  6. type=ethernet
  7. interface-name=eth1
  8. [ipv4]
  9. address1=192.168.0.200/24,192.168.0.100           //网关指向路由
  10. method=manual
  11. dns=114.114.114.114;
  12. [root@lvs ~]# ip a a 192.168.0.50/32 dev lo     //环回添加一次性ip
复制代码
server1、server2主机

  1. #############server1主机
  2. [root@server1 ~]#  vmset.sh eth0 192.168.0.10 server1
  3. [root@server1 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
  4. [connection]
  5. id=eth0
  6. type=ethernet
  7. interface-name=eth0
  8. [ipv4]
  9. address1=192.168.0.10/24,192.168.0.100    // //网关指向路由
  10. method=manual
  11. [root@server1 ~]#  echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
  12. [root@server1 ~]#  echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
  13. [root@server1 ~]#  echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
  14. [root@server1 ~]#  echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
  15. [root@server1 ~]# ip a a 192.168.0.50/32 dev lo    //临时ip
  16. ############server2主机
  17. [root@server2 ~]#  vmset.sh eth0 192.168.0.20 server2
  18. [root@server2 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
  19. [connection]
  20. id=eth0
  21. type=ethernet
  22. interface-name=eth0
  23. [ipv4]
  24. address1=192.168.0.20/24,192.168.0.100    //网关指向路由
  25. method=manual
  26. [root@server2 ~]#  echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
  27. [root@server2 ~]#  echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
  28. [root@server2 ~]#  echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
  29. [root@server2 ~]#  echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
  30. [root@server2 ~]# ip a a 192.168.0.50/32 dev lo   //临时ip
复制代码
开始实验

lvs主机上安装ipvsadm

  1. [root@lvs ~]# yum install ipvsadm -y
  2. [root@lvs ~]# ipvsadm -Ln               //查看策略
  3. IP Virtual Server version 1.2.1 (size=4096)
  4. Prot LocalAddress:Port Scheduler Flags
  5.   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
复制代码
布置策略

  1. [root@lvs ~]# ipvsadm -A -t 192.168.0.50:80 -s wrr  
  2. [root@lvs ~]# ipvsadm -a -t 192.168.0.50:80 -r 192.168.0.10:80 -g -w 2  //权重2
  3. [root@lvs ~]# ipvsadm -a -t 192.168.0.50:80 -r 192.168.0.20:80 -g -w 1  //权重1
  4. [root@lvs ~]# ipvsadm -Ln
  5. IP Virtual Server version 1.2.1 (size=4096)
  6. Prot LocalAddress:Port Scheduler Flags
  7.   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
  8. TCP  192.168.0.50:80 wrr
  9.   -> 192.168.0.10:80              Route   2      0          0         
  10.   -> 192.168.0.20:80              Route   1      0          0         
复制代码
测试

  1. [root@client ~]# for i in {1..10}
  2. > do
  3. > curl 192.168.0.50
  4. > done
  5. this is server1
  6. this is server1
  7. this is server2
  8. this is server1
  9. this is server1
  10. this is server2
  11. this is server1
  12. this is server1
  13. this is server2
  14. this is server1
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

诗林

高级会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表