LVS#Haproxy+MysqL four-layer load balancing

Haproxy+MyaqL realizes the basic knowledge of four-layer load balancing

1.
Haproxy basic software: haproxy-mainly for 7 layers of load balancing, and can also do 4 layers of load balancing.
  Apache can also do 7 layers of load balancing, but it is very troublesome. No one uses it in actual work.
  Load balancing is the
  7-layer load balancing corresponding to the OSI protocol : the 7-layer http protocol is used, and the
  4-layer load balancing: the tcp protocol plus the port number is used for load balancing.

ha-proxy overview
  ha-proxy is a high-performance load balancing software. Because it focuses on load balancing, it is better and more professional in load balancing than nginx.
The characteristics of ha-proxy (has a nice monitoring page)
ha-proxy, as the current popular load balancing software, must have its outstanding side. The following introduces the advantages of ha-proxy over LVS, Nginx and other load balancing software
.
  •Support tcp / http two protocol layer load balancing, making its load balancing function very rich.
  • Support 8 kinds of load balancing algorithms, especially in http mode, there are many very real load balancing algorithms, suitable for various needs.
  • The performance is very good. The event-driven link processing mode and single-process processing mode (similar to Nginx) make its performance excellent.
  • Have an excellent monitoring page to understand the current status of the system in real time.
  • Powerful ACL support, giving users great convenience.

2.
Haproxy algorithm 1. Roundrobin
performs polling based on weights. This is the most balanced and fair algorithm when the processing time of the server remains evenly distributed. This algorithm is dynamic, which means its weight can be adjusted at runtime. However, in design, each backend server can only accept a maximum of 4128 connections
2. static-rr
polls based on weights, similar to roundrobin, but is a static method, and adjusting its server weight at runtime will not take effect. However, There is no limit on the number of back-end server connections
3. Leastconn
new connection requests are dispatched to the back-end server with the least number of connections.

两台haproxy配置文件:
[root@ha-proxy-master ~]# cat /etc/haproxy/haproxy.cfg
Haproxy L4
=================================================================================
global
    log         127.0.0.1 local2
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    nbproc      1
defaults
    mode                    http
    log                     global
    option                  redispatch
    retries                 3
    maxconn                 4000
    contimeout	            5000
    clitimeout	            50000
	srvtimeout	            50000
listen stats
    bind			*:80
    stats                   	enable
    stats uri              	/haproxy
    stats auth           	qianfeng:123
frontend  web
    mode                   	http
    bind                    	    *:80
    option                  httplog
    default_backend    httpservers
backend httpservers
    balance     roundrobin
    server  http1 192.168.246.162:80 maxconn 2000 weight 1  check inter 1s rise 2 fall 2
    server  http2 192.168.246.163:80 maxconn 2000 weight 1  check inter 1s rise 2 fall 2
listen mysql
    bind *:3306
    mode tcp
    balance roundrobin
    server mysql1 192.168.246.163:3306 weight 1  check inter 1s rise 2 fall 2
    server mysql2 192.168.246.162:3306 weight 1  check inter 1s rise 2 fall 2
找一台机器做为客户端去测试,在测试的时候注意mysql的远程登录权限

Haproxy+MyaqL realizes four-layer load balancing experiment operation

1. Two databases are prepared and different databases are created for easy distinction

 yum -y install mariadb mariadb-server
 systemctl start mariadb
 mysql
 creata database db1;
 create database db2;
 grant all on *.* to 'root'@'%' identified by '123';
 flush privileges;

2. Haproxy configuration

[root@haproxy-slave ~]# vim /etc/haproxy/haproxy.cfg
global
    log         127.0.0.1 local2
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    nbproc      1
defaults
    mode                    http
    log                     global
    option                  redispatch
    retries                 3
    maxconn                 4000
    contimeout              5000
    clitimeout              50000
        srvtimeout                  50000
listen stats
    bind                        *:80
    stats                       enable
    stats uri                   /haproxy
    stats auth                  qianfeng:123
listen mysql
    bind *:3306
    mode tcp
    balance roundrobin
    server mysql1 192.168.138.132:3306 weight 1  check inter 1s rise 2 fall 2
    server mysql2 192.168.138.135:3306 weight 1  check inter 1s rise 2 fall 2
[root@haproxy-slave ~]# systemctl status haproxy
    

3. Client access verification

[root@haproxy-slave ~]# mysql -u root -p123 -h 192.168.138.131

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/kakaops_qing/article/details/109207977