zoukankan      html  css  js  c++  java
  • 构建LVS负载均衡集群

    一、地址转换模式(LVS-NET)

    需要三台虚拟机和一台测试机,111(需要两块网卡,另一块网卡是VMnet2模式),112,113

    1、111:[root@nginx ~]# yum -y install ipvsadm

    [root@nginx ~]# ipvsadm -v

    [root@nginx ~]# cd /etc/sysconfig/network-scripts/

    [root@nginx network-scripts]# cp ifcfg-eno16777728 ifcfg-eno33554968

    [root@nginx network-scripts]# vim ifcfg-eno33554968                //里面的内容更改如下

    NAME=eno33554968
    #UUID=232cc483-0507-42d9-b200-cda4618b9019
    DEVICE=eno33554968
    ONBOOT=yes
    IPADDR=172.16.1.1

    [root@nginx network-scripts]# systemctl restart network
    [root@nginx network-scripts]# ip a        // 查看一下

    三台虚拟机的防火墙及全机制全部关掉:

    [root@nginx ~]# systemctl stop firewalld
    [root@nginx ~]# iptables -F
    [root@nginx ~]# setenforce 0

    [root@nginx ~]# vim /etc/sysctl.conf           //开启路由转发功能:添加一行

    net.ipv4.ip_forward = 1

    [root@nginx ~]# sysctl -p                  //使其生效

    [root@nginx ~]# ipvsadm -A -t 172.16.1.1:80 -s rr
    [root@nginx ~]# ipvsadm -a -t 172.16.1.1:80 -r 192.168.200.112 -m -w 1
    [root@nginx ~]# ipvsadm -a -t 172.16.1.1:80 -r 192.168.200.113 -m -w 1
    [root@nginx ~]# ipvsadm -Ln                            //查看

    2、112、113:[root@node1 ~]# yum -y install httpd

    [root@node1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777728                 //修改指向的网关为111

    [root@node1 ~]# systemctl restart network

    [root@node1 ~]# route -n

    [root@node1 ~]# systemctl start httpd

    111:[root@node1 ~]# echo "111111111111" > /var/www/html/index.html

    112:[root@node1 ~]# echo "2222222222" > /var/www/html/index.html

    3、小脚本

    [root@nginx ~]# while :
    > do
    > elinks --dump http://172.16.1.1
    > sleep 1
    > done

    [root@nginx ~]# ipvsadm -Ln

    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
    -> RemoteAddress:Port Forward Weight ActiveConn InActConn
    TCP 172.16.1.1:80 rr
    -> 192.168.200.112:80 Masq 1 0 3
    -> 192.168.200.113:80 Masq 1 0 4

  • 相关阅读:
    nodejs事件和事件循环详解
    keycloak集群化的思考
    Python解释器和IPython
    IndexedDB详解
    在onelogin中使用OpenId Connect Implicit Flow
    在onelogin中使用OpenId Connect Authentication Flow
    SAML和OAuth2这两种SSO协议的区别
    wildfly 21的配置文件和资源管理
    【老孟Flutter】2021 年 Flutter 官方路线图
    【老孟Flutter】为什么 build 方法放在 State 中而不是在 StatefulWidget 中
  • 原文地址:https://www.cnblogs.com/990624lty-jhc/p/11592240.html
Copyright © 2011-2022 走看看