LB-HAproxy load balancing deployment

HAproxy load balancing has been widely used in our production environment, and its excellent performance has also been recognized by the people; then we say it's a little Haproxy;

1. The layer 4 can be achieved, load balancing layer 7;

2. friendly visual interface, support for web display;

3. The heart rate monitor, can automatically identify the fault point, remove the latter is added (the Nginx automatic identification is to send data over the TCP webserver, to prove whether health; index.html HAproxy by accessing the webserver's health to determine whether normal) ;

4. The heart rate monitor can be implemented in conjunction with LVS the LVS;

5.HAproxy by persistent link the cookie, and algorithms to achieve results in the same sh LVS scheduling, but to be more useful than the sh;

Taiwan ready haproxy 'servers, two httpd server

 Home httpd server we conduct some modifications, we observe more convenient;

[root@sxb-2 ~]# echo 102 > /var/www/html/index.html
[root@sxb-3 ~]# echo 103 > /var/www/html/index.html

Next we configure HAproy server;

1. Install the software;

[root@sxb-1 haproxy-1.7]# tar xf haproxy-1.7.5.tar.gz
[root@sxb-1 haproxy-1.7]# cd haproxy-1.7.5/
[root@sxb-1 haproxy-1.7.5]# ls
CHANGELOG     doc       include      Makefile  scripts  tests
contrib       ebtree    LICENSE      README    src      VERDATE
CONTRIBUTING  examples  MAINTAINERS  ROADMAP   SUBVERS  VERSION

Compile and install;

[root@host1 haproxy-1.7.5]# make TARGET=linux2628  PREFIX=/usr/local/haproxy/ 
[root@host1 haproxy-1.7.5]# make TARGET=linux2628  PREFIX=/usr/local/haproxy/ install

HAproxy configuration file (configuration file we need to be able to write their own, must be the end of the .cfg)

[root @ sxb- 1 HAProxy] # vim haproxy.cfg
 , Ltd. Free Join 
# parameter is the process level, usually operating systems and related 
    log          127.0 . 0.1    local3      # we need to set the log file; 
    maxconn          4096    
    the User the nobody 
    Group the nobody 
    daemon    
    the PidFile          / usr / local / HAProxy / haproxy.pid 

defaults 
# default configuration parameters that can be used frontend, backend, Listen components 
    log             , Ltd. Free Join 
    the MODE HTTP    
    maxconn          2048 
    timeout Connect 10s 
    timeout Client 1M 
    timeout Server 1M

    retries          . 3    
    Option redispatch 

the listen HAProxy - Monitor     
#Fronted and backend combination of 
    the bind          *: 8080 
    MODE HTTP 
    Option forwardfor 
    Option httpclose 
    stats enable 
    stats Show - Legends 
    stats Refresh 5S 
    stats URI      / stats 
    stats the auth ADMIN: ADMIN 

frontend main 
front end receives the requested # virtual nodes, Frontend specify a specific back-end of the backend 
    the bind          *: 80 
    log          , Ltd. Free Join
    forwardfor Option 
    Option httpclose            
    default_backend HTML - Server 

backend HTML - Server 
Configuration cluster # backend services, real server, a Backend servers corresponding to the one or more entities 
    Balance of the RoundRobin 
    Option httpchk the GET    / index.html 
    Server HTML -A 192.168 . 5.102 : 80 check security check 
    Server HTML -B 192.168 . 5.103 : 80  check security check

This is the URL-based load balancing;

Start HAproxy services;

[root@sxb-1 haproxy]# ./sbin/haproxy -f haproxy.cfg

Here, our HAproxy ready for use;

这里我们通过web页面我们可以看到两台httpd服务器的信息都显示出来了,接下来我们测试HAproxy的负载均衡;

[root@sxb-1 ~]# curl 192.168.88.101
102
[root@sxb-1 ~]# curl 192.168.88.101
103
[root@sxb-1 ~]# curl 192.168.88.101
102
[root@sxb-1 ~]# curl 192.168.88.101
103

测试HAproxy的健康检查;我们停掉102的httpd服务器;

[root@sxb-2 ~]# systemctl stop httpd
[root@sxb-1 ~]# curl 192.168.88.101
103
[root@sxb-1 ~]# curl 192.168.88.101
103
[root@sxb-1 ~]# curl 192.168.88.101
103

当我们停掉102后HAproxy自动识别故障点,并剔除,

我们恢复102httpd服务;

[root@sxb-2 ~]# systemctl start httpd
[root@sxb-1 ~]# curl 192.168.88.101
103
[root@sxb-1 ~]# curl 192.168.88.101
102
[root@sxb-1 ~]# curl 192.168.88.101
103
[root@sxb-1 ~]# curl 192.168.88.101
102

当问题恢复后,HAproxy会自动将102加入到集群中;

我们来测试一下cookie的持久化链接;

我们要对配置文件进行一些修改

重启其服务我们来测试;

因为cookie的缓存功能,我们会一直访问102;当我们停掉102服务后;cookie会为我们选择其他通道;

我们来测试cookie

 

Guess you like

Origin www.cnblogs.com/loganSxb/p/11285966.html