In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly shows you "how to use HAProxy", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use HAProxy" this article.
1. Installation:
# tar zcvf haproxy-1.3.20.tar.gz # cd haproxy-1.3.20
# make TARGET=linux26 PREFIX=/usr/local/haproxy # installing haproxy to / usr/local/haproxy,TARGET indicates the linux kernel version, which can be adjusted according to your own machine
# make install PREFIX=/usr/local/haproxy
2. Start:
Configuration files are required when HAProxy starts. For the first contact, you can start using the default configuration file haproxy.cfg in examples in the installation folder. For clarity, create a configuration file directory first.
# mkdir / usr/local/haproxy/conf
Copy the haproxy.cfg from the installation directory to / usr/local/haproxy/conf
Start the service: / usr/local/haproxy/sbin/haproxy-f / usr/local/haproxy/conf/haproxy.cfg
If you encounter the following error during startup:
"Cannot create * * directory / file"
Solution: mkdir directory
3. Configuration:
The configuration file is divided into two main parts: the global area and the agent area.
Global: mainly related to process parameters. As follows:
Log 127.0.0.1 local0 # log 127.0.0.1 local1 notice
# log loghost local0 info
Maxconn 4096
Chroot / home/develop/haproxy
Uid 99
Gid 504 # develop group id
Daemon
Nbproc 1
Pidfile / home/develop/haproxy/logs/haproxy.pid
Please refer to the official website for the meaning of other parameters and specific parameters.
Agency area: divided into three parts: defaults, listen, frontend, backend
Defaults: default parameters are set for the zones declared below (such as listen, frontend, backend). If another defaults is declared under a defaults, then the same parameter takes the value of the lowest defaults. As follows:
Mode http # working mode http agent, that is, layer 7. Other values: tcp (working in layer 4) / health
Option httplog
Option httpclose
Option dontlognull
Option forwardfor
Option redispatch
Retries 2
Maxconn 2000
Balance roundrobin # back-end server load balancing mode
Stats uri / haproxy-stats
Contimeout 5000
Clitimeout 50000
Srvtimeout 50000
Frontend: describes a series of sockets used to receive client-side links, equivalent to listen, bind, and accept functions in socket programming. As follows:
Bind 192.168.198.79 mode tcp 7910 # haproxy bind address and listening port mode tcp
Acl shunt src 10.28.169.231
Use_backend new_server if shunt
Default_backend old_server
Backend: describes the real server. Multiple servers can be defined in a configuration file. As follows:
Server second 192.168.198.77GRV 7910 # Real backend server
Server third 192.168.198.78:7910
A combination of listen:frontend and backend, usually used in tcp forwarding.
Powerful acl:
The syntax of acl is as follows:
Acl [flags] [operator]...
As follows:
Mode tcp
Acl shunt src 10.28.169.231
The name of this acl is shunt,criterion, src,value is 10.28.169.231. There are no flags and operator parts in this acl.
This means that if the ip address of the client requesting the link is 10.28.169.231, it matches. At first glance, the effect is not very great, but it can form a conditional judgment. For example, such an application scenario: if the request client address is 10.28.169.231, it is forwarded to the 10.28.169.114 server for execution, and the other request clients are forwarded to 10.28.169.12 for execution. You can meet the requirements according to the following configuration items:
Frontend only1
Bind 192.168.198.79:7910
Mode tcp
Acl shunt src 10.28.169.231
Use_backend new_server if shunt
Default_backend old_server
Backend new_server
Server first 10.28.169.114:7910
Backend old_server
Server second 10.28.169.12:7910
The above is all the contents of the article "how to use HAProxy". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.