The previous article said keepalived Environment building, originally keepalived combined with LVS more advantages, but also can be combined with nginx to use. Next, let's say nginx environment is built
Environmental information:
Nginx (Master) 192.168.1.106
Nginx (bakup) 192.168.1.103
First install the Pcre
Yum Install Pcre-devel
After installation, understand the pressure nginx. I'm using nginx-1.6.2.tar.gz.
TAR-ZVXF nginx-1.6.2.tar.gz
CD nginx-1.6.2
./configure
The following information will be printed when the compilation is successful
Nginx path prefix: "/usr/local/nginx"nginx binary file:"/usr/local/nginx/sbin/nginx"To start the command path nginx configuration prefix:"/usr/local/nginx/conf"nginx configuration file:"/usr/local/nginx/conf/nginx.conf"configuration file path nginx pid file:"/usr/local/nginx/logs/nginx.pid"nginx error log file:"/usr/local/nginx/logs/error.log"nginx HTTP access log file:"/usr/local/nginx/logs/access.log"Log path Nginx HTTP client request body temporary files:"Client_body_temp"nginx HTTP proxy temporary files:"Proxy_temp"nginx http fastcgi temporary files:"Fastcgi_temp"nginx http Uwsgi temporary files:"Uwsgi_temp"nginx http scgi temporary files:"Scgi_temp"
Several paths to note
Then there is
Make
Make install
At this point, Nginx installation is finished. Then it's the configuration nginx.
Note that both machines have to be installed.
Vi/usr/local/nginx/conf/nginx.conf
worker_processes 1;events {worker_connections 1024;} HTTP {include mime.types; Default_type application /octet-stream; Sendfile on; Keepalive_timeout 65;upstream web_pools {server 192.168.1.102:8080 Weight=5 192.168.1.104:8080 weight=5; #server 10.0.0.10:80 weight=5 backup;} server {Listen 80; Location / {root html; Index index.html index.htm; Proxy_pass http: // web_pools;
Configuration files are mostly configuration Upstream,server
As you can see from the server, Nginx listens on the native 80 port. And then forwarded to Web_pools.
And then we can start the nginx.
Cd/usr/local/nginx/sbin
./nginx
[Email protected] sbin]# Ps-ef | grep nginxroot 8207 1 0 04:37? 00:00:00 nginx:master process./nginxnobody 8208 8207 0 04:37? 00:00:00 nginx:worker processroot 10342 10069 0 06:26 pts/1 00:00:00 grep nginx
Then you can test if the nginx is in effect.
You can launch two Tomcat in the 192.168.1.104 and 192.168.1.102 servers.
And then
http://192.168.1.106/test/index.jsp
Visit a bit
I put a test project under the 102 104 machine Tomcat, and there's a index.jsp file in the project.
If you can access it to show that the Nginx built successfully, you can also be one of the above, such as 102 tomcat off. See if the service is still available, and then start the Tomcat up and try again.
The same nginx is also built on 192.168.1.103 (backup)
The two machines have no problem with nginx, you can use keepalived VIP to visit.
http://192.168.1.100/Test/index.jsp
Next test, turn off one of the keepalived and then access the service.
Found still no problem.
But if the visit when the nginx hanging, will be another nginx automatically switch over it. The answer is no.
Keepalived is not aware that Nginx is not available on the machine.
So how do we solve this problem?
We can use the shell to implement the automatic switch after Nginx hangs.
Scripts are primarily implemented
Check the Nginx, found Nginx Hung, the machine keepalived service off
In this way, the keepalived backup will automatically switch over, and the request will be able to access the Nginx service on the backup.
After the master service is repaired, the request will be requested again on the master machine.
Keepalived+nginx high-Availability load Balancing Environment setup