Working with scenes
Using Haproxy to carry out load balancing, for data transmission under socket, non-HTTP access load balancing.
Assuming that the scenario is as follows, Terminal 1 and Terminal 2 are responsible for collecting data and then want to forward the data to the server for analysis through the load balancer.
Hope:
1, when two terminals are working properly, but only one server (server 1), will send all the data to this server.
2, when two terminals are working properly, and there are two servers, will form as shown in the situation, two servers processing two terminals of data, the average distribution.
3, when 2 of the situation occurs in a server down (server 1), then two terminals will be collected data to another server (server 2) for processing.
Features: The original terminal to send data to the server is the use of message middleware zeromq to communicate, while maintaining the connection is the socket long connection, so in the Haproxy boot process, you need to indicate the TCP connection (Network 4 layer), rather than HTTP (Network 7 layer) connection. Operation Process
Installation reference: Installation and configuration of high load balanced learning Haproxy
http://www.cnblogs.com/ilanni/p/4750081.html Settings configuration file haproxy.cfg
Global # Settings log 127.0.0.1 Local2 # log syntax: Log <address_1>[max_level_1] # Global logging configuration, using log keyword, # refers to Use the Local0 log device in the Syslog service on 127.0.0.1 # to record logs with info log level chroot/usr/local/haproxy #改变当前工作目录 pidfile/u Sr/local/haproxy/logs/haproxy.pid #当前进程id文件 maxconn 4000 #最大连接数 user Haproxy #所属用户 Group Hap Roxy #所属组 Daemon #以守护进程方式运行haproxy #stats socket/usr/local/haproxy/stats defaults mode TCP #默认的模式mo
De {tcp|http|health},tcp is Layer 4, HTTP is 7, health will only return OK log global #应用全局的日志配置 option Tcplog Option dontlognull option Redispatch retries 3 Timeout Connect 10s #连接超时 Timeout Client 1m #客户端超时 timeout server 1m #服务器端超时 Maxconn 3000 #每个进程可用的最大连接数 Listen rabbitmq_local_cluster 10.100
.100.171:8082 Mode TCP Balance roundrobin #负载均衡算法 Server web001 10.100.100.171:7000 check Inter \ Fall 3 Weight #定义的多个后端 Server web002 10.100.100.171:7001 check Inter Fall 3 weight #定义的多个后端 Listen Private_mo nitoring:8101 mode HTTP option httplog stats enable stats uri/stats stats refresh 1s
Common Commands
Copy configuration file to haproxy installation directory
sudo cp/home/ishadow/desktop/haproxy.cfg/usr/local/haproxy/
Load the specified profile haproxy.cfg start Haproxy
Sudo/usr/local/haproxy/sbin/haproxy-f/usr/local/haproxy/haproxy.cfg
Close all initiated haproxy processes (Haproxy can be started repeatedly)
Killall Haproxy
Final Effect
Access Url:http://10.100.100.171:8101/stats to view Haproxy real-time load and request conditions
Summarize
1, Haproxy installation is not difficult, but the configuration file will vary depending on the use of the scene, you need to understand the configuration file.
2. Using Haproxy in HTTP mode is to balance the request load, while using Haproxy in TCP mode is to balance the connection load.
3, TCP mode is the network model 4th layer connection, and the upper-level protocol, so whether the use of middleware such as ZEROMQ, RABBITMQ will not affect the Haproxy load balancing algorithm, and will not affect the use of haproxy.
4, Haproxy can complete the load sharing, failure transfer, master-slave backup and other tasks under a variety of scenarios, set up a good configuration file.
Installation reference:
Http://www.cnblogs.com/ilanni/p/4750081.html