In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to do tcp load in nginx, I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Conditions for load configuration
(1) version 1.9.0 or above of nginx.
(2) the database needs master backup or above.
Example environment
Operating system: windows7
Nginx version: 1.13.3
IP of server A: 192.168.68.56
IP of server B: 192.168.68.139
Implementation of load configuration
Load balancing and automatic switching are realized to some extent by modifying the configuration of max_fails and fail_timeout.
Modify the config/nginx.conf file of nginx.
Add the configuration as follows:
Stream {
Upstream backend {
# hash $remote_addr consistent
Server 192.168.68.56:3306 max_fails=2 fail_timeout=10s
# IP and port are database configuration data
Server 192.168.68.139:3306 max_fails=2 fail_timeout=10s
# max_fails: the number of failed requests allowed defaults to 1. Returns the error defined by the proxy_next_upstream module when the maximum number of times is exceeded
# fail_timeout: the time to pause after a max_fails failure.
}
Server {
Listen *: 14330th # need to modify the universal access interface of the database to this
Proxy_pass backend
}
}
Note: stream and http are equal.
According to the above configuration, switch between two servers is simulated. If a server fails twice, the failed server will no longer be accessed within 10 seconds (adjustable). During this period, the failed database in the two computers can be restarted.
After testing, if the dual master master backup is configured, when one is down and then restarted, the data will be automatically synchronized.
However, using the above method actually belongs to the polling algorithm, there are some problems, it is not recommended to use.
Currently, using backup configuration, one of the databases can be restored to normal within a certain period of time when one of the databases is down.
The disadvantage is that it cannot operate within about 1 minute of downtime.
Are there any other better solutions under windows? Think about it later.
references
Five load algorithm modes of nginx
Polling (default)
Each request is assigned to a different backend server one by one in chronological order. If the backend server down is dropped, it can be automatically eliminated.
Weight
Specify the polling probability. The weight is proportional to the access ratio, which is used in the case of uneven performance of the backend server.
For example:
Upstream bakend {
Server 192.168.0.14 weight=10
Server 192.168.0.15 weight=10
}
Ip_hash
Each request is allocated according to the hash result of accessing the ip, so that each visitor accesses a back-end server on a regular basis, which can solve the session problem.
For example:
Upstream bakend {
Ip_hash
Server 192.168.0.14:88
Server 192.168.0.15:80
}
Fair (third party)
Requests are allocated according to the response time of the back-end server, and priority is given to those with short response time.
For example:
Upstream backend {
Server server1
Server server2
Fair
}
Url_hash (third party)
Allocate requests according to the hash result of accessing url, so that each url is directed to the same backend server, which is more effective when the backend server is cached.
Example: add hash statement to upstream. Other parameters such as weight cannot be written in server statement. Hash_method is the hash algorithm used.
Upstream backend {
Server squid1:3128
Server squid2:3128
Hash $request_uri
Hash_method crc32
}
Tips
Upstream bakend {
# define the Ip and device status of load balancer devices
Ip_hash
Server 127.0.0.1:9090 down
Server 127.0.0.1:8080 weight=2
Server 127.0.0.1:6060
Server 127.0.0.1:7070 backup
}
Added in server where load balancing is required
Proxy_pass http://bakend/;
The status of each device is set to:
1.down indicates that the server before the order does not participate in the load for the time being.
The default 2.weight is that the larger the 1.weight, the greater the weight of the load.
3.max_fails: the number of requests allowed to fail defaults to 1. Returns the error defined by the proxy_next_upstream module when the maximum number of times is exceeded
Time to pause after 4.fail_timeout:max_fails failure.
5.backup: all other non-backup machines down or request backup machines when they are busy. So this machine will be the least stressed.
Nginx supports setting multiple groups of load balancers at the same time, which can be used by unused server.
If client_body_in_file_only is set to On, the data from client post can be recorded into a file to be used as debug.
The directory of client_body_temp_path settings record files can be set up to 3-tier directories
Location matches the URL. You can redirect or do new agent load balancing.
After reading the above, have you mastered the method of how to do tcp load in nginx? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.