Group Network Diagram:
Configuration information:
/usr/local/nginx/conf/nginx.conf on the left NIGX server
#user nobody;
Worker_processes 1;
#error_log Logs/error.log;
#error_log Logs/error.log Notice;
#error_log Logs/error.log Info;
#pid Logs/nginx.pid;
Events {
Worker_connections 1024;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
#log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
# ' $status $body _bytes_sent ' $http _referer '
# ' "$http _user_agent" "$http _x_forwarded_for" ';
#access_log Logs/access.log Main;
Sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
Keepalive_timeout 65;
#gzip on;
server {
Listen 80;
server_name 192.168.248.200;
#charset Koi8-r;
#access_log Logs/host.access.log Main;
Location/{
root HTML;
Index index.html index.htm;
}
#error_page 404/404.html;
# REDIRECT Server error pages to the static page/50x.html
#
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
# Proxy The PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# Proxy_pass http://127.0.0.1;
#}
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root HTML;
# Fastcgi_pass 127.0.0.1:9000;
# Fastcgi_index index.php;
# Fastcgi_param Script_filename/scripts$fastcgi_script_name;
# include Fastcgi_params;
#}
# Deny access to. htaccess files, if Apache ' s document Root
# concurs with Nginx ' s one
#
#location ~/\.ht {
# Deny All;
#}
}
# Another virtual host using mix of ip-, name-, and port-based configuration
#
#server {
# Listen 8000;
# Listen somename:8080;
# server_name somename alias Another.alias;
# location/{
# root HTML;
# index index.html index.htm;
# }
#}
# HTTPS Server
#
#server {
# Listen 443 SSL;
# server_name localhost;
# ssl_certificate Cert.pem;
# Ssl_certificate_key Cert.key;
# Ssl_session_cache shared:ssl:1m;
# ssl_session_timeout 5m;
# ssl_ciphers high:!anull:! MD5;
# ssl_prefer_server_ciphers on;
# location/{
# root HTML;
# index index.html index.htm;
# }
#}
}
The configuration file for the Nginx server on the right/usr/loca/nginx/conf/nginx.conf the contents as follows:
#user nobody;
Worker_processes 1;
#error_log Logs/error.log;
#error_log Logs/error.log Notice;
#error_log Logs/error.log Info;
#pid Logs/nginx.pid;
Events {
Worker_connections 1024;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
#log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
# ' $status $body _bytes_sent ' $http _referer '
# ' "$http _user_agent" "$http _x_forwarded_for" ';
#access_log Logs/access.log Main;
Sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
Keepalive_timeout 65;
#gzip on;
server {
Listen 80;
server_name 192.168.248.200;
#charset Koi8-r;
#access_log Logs/host.access.log Main;
Location/{
root HTML;
Index index.html index.htm;
}
#error_page 404/404.html;
# REDIRECT Server error pages to the static page/50x.html
#
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
# Proxy The PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# Proxy_pass http://127.0.0.1;
#}
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root HTML;
# Fastcgi_pass 127.0.0.1:9000;
# Fastcgi_index index.php;
# Fastcgi_param Script_filename/scripts$fastcgi_script_name;
# include Fastcgi_params;
#}
# Deny access to. htaccess files, if Apache ' s document Root
# concurs with Nginx ' s one
#
#location ~/\.ht {
# Deny All;
#}
}
# Another virtual host using mix of ip-, name-, and port-based configuration
#
#server {
# Listen 8000;
# Listen somename:8080;
# server_name somename alias Another.alias;
# location/{
# root HTML;
# index index.html index.htm;
# }
#}
# HTTPS Server
#
#server {
# Listen 443 SSL;
# server_name localhost;
# ssl_certificate Cert.pem;
# Ssl_certificate_key Cert.key;
# Ssl_session_cache shared:ssl:1m;
# ssl_session_timeout 5m;
# ssl_ciphers high:!anull:! MD5;
# ssl_prefer_server_ciphers on;
# location/{
# root HTML;
# index index.html index.htm;
# }
#}
}
The default HTML file contents of the left Nginx server are: (/usr/local/nginx/html/index.html)
I am Nginx Master
Right nginx server default HTML file content is: (path above)
I am Nginx-slave
The keepalived configuration file for the left Nginx server is: (/etc/keepalived/keepalived.conf)
Global_defs {
router_id NodeA
}
Vrrp_instance Vi_1 {
State MASTER #设置为主服务器
Interface Ens33 #监测网络接口
virtual_router_id #主, the preparation must be the same
Priority # (master, standby machine take different priorities, host value is large, backup machine value is small, the higher the value of higher priority)
Advert_int 1 #VRRP multicast broadcast cycle seconds
Authentication {
Auth_type PASS #VRRP认证方式, the master must be consistent
Auth_pass 1111 # (password)
}
virtual_ipaddress {
192.168.248.200
}
The contents of the Keepalived configuration file for the right Nginx server are as follows:
Global_defs {
router_id NodeB
}
Vrrp_instance Vi_1 {
State BACKUP #设置为主服务器
Interface Ens33 #监测网络接口
virtual_router_id #主, the preparation must be the same
Priority # (master, standby to take different priorities, host value is large, backup machine value is small, the higher the value of the higher priority)
Advert_int 1 #VRRP multicast broadcast cycle seconds
Authentication {
Auth_type PASS #VRRP认证方式, the master must be consistent
Auth_pass 1111 # (password)
}
virtual_ipaddress {
192.168.248.200
}
Start the Nginx server and configure the firewall
#/usr/local/nginx/sbin/nginx
#firewall-cmd--permanent--add-port=80/tcp
#firewall-cmd--reload
The actual test results are as follows:
Close the left Nginx Ens33 port, causing the nginx to prepare the owner,
Nginx + keepalived for a highly reliable web site