In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This example describes CentOS's method of implementing Load Balancer based on nginx reverse proxy. Share it for your reference, as follows:
Advantages of nginx doing Load Balancer:
1, working on the 7 layers of the network, you can do some diversion strategies for http applications, such as domain names, directory structure, its regular rules are more powerful and flexible than HAProxy, which is one of the main reasons why it is widely popular at present, nginx can be used far more than LVS
2, nginx dependence on network stability is very small, in theory can ping pass can carry out load function, this is also one of its advantages; on the contrary, LVS dependence on network stability is relatively large, I have a deep understanding of this
3, nginx installation and configuration is relatively simple, testing is more convenient, it can basically print out the error log. LVS configuration and testing will take a long time, LVS is more dependent on the network
4, can bear high load pressure and stability, in the case of poor hardware can generally support tens of thousands of concurrent volume, load is relatively small than LVS
Notes:
1, Different installation methods nginx configuration file location is different
2, upstream If ip_hash mode is used, each request is allocated according to the hash result of accessing ip, so that each visitor can access a backend server fixedly, which can solve the problem of session.
Environment:
System: Centos6.6
nginx ip:192.168.20.103
web1 ip:192.168.20.193
web2 ip:192.168.20.194
First, install nginx
Two ways. I used the first one.
The first type of yum installation, you need to install a third-party yum source, because nginx is not in the yum source of centos by default, so you need to update
yum install wget #install download tools wget http://www.atomicorp.com/installers/atomic #download sh ./ atomic #install yum check-update #update yum source some need to update several times before there is the latest version of nginx otherwise it is the old version nginxyum remove httpd* php* #delete the software package that comes with the system can also add mysql* premise backup database yum install nginx #install nginx according to the prompt input y install chkconfig nginx on #set nginx boot start service nginx start #start nginx restart restart
2nd compilation installation
wget http://nginx.org/download/nginx-1.7.8.tar.gztar -zxvf nginx-1.7.8.tar.gzcd nginx-1.7.8./ configuremake && make install
II. Modify the configuration file
By default, nginx upstream implements Load Balancer by polling. In this way, each request is distributed to different backend servers one by one according to time sequence. If the backend server goes down, it can be automatically eliminated.
Another way is ip_hash: each request is allocated according to the hash result of the access ip, so that each visitor has fixed access to a backend server, which can solve the session problem.
/etc/nginx/nginx.conf added
#Load Balancer Configure upstream backend {#ip_hash;server 192.168.20.193;server 192.168.20.194;}
The requested URL/etc/nginx/conf.d/default.conf was not found on this server.
location / {#Set the host header and the real address of the client, so that the server can obtain the real IP of the client proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #Disable cache proxy_buffering off; #Address of reverse proxy proxy_pass http://backend; root /usr/share/nginx/html; index index.html index.htm; # example #ModSecurityEnabled on; #ModSecurityConfig /etc/nginx/modsecurity.conf;}
III. Testing
The first access forwards to 193 because upstream defaults to polling, and the second to 194.
I hope this article is helpful for CentOS server maintenance.
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.