Home > OS >  Build the LVS keepalived nginx environment, firewall has closed, separate access nginx application t
Build the LVS keepalived nginx environment, firewall has closed, separate access nginx application t

Time:09-29

:
Build the LVS + keepalived + nginx environment, firewall has closed, separate access nginx application there is no problem, can appear the VIP ping, but cannot access, the bosses help solve under
,

1. Server IP
nignx1 : 192.168.75.129:8000
nignx2 : 192.168.75.130:8000

the LVS + keepalived + master : 192.168.75.128
the LVS + keepalived + backup : 192.168.75.131


nginx IP information




the LVS + keepalived IP information




2. Nginx. Conf file:
# the user nobody;
Worker_processes 1;

# error_log logs/error. The log;
# error_log logs/error log notice;
# error_log logs/error. The log info;

# pid logs/nginx. Pid;


Events {
Worker_connections 1024;
}


HTTP {
. Include the mime types;
Default_type application/octet - stream;

# log_format main '$remote_addr - $remote_user [$time_local] "$request"'
# '$$body_bytes_sent status "$http_referer"'
# '" $http_user_agent "" $http_x_forwarded_for"';

# access_log logs/access. Log the main;

Sendfile on;
# tcp_nopush on;

# keepalive_timeout 0;
Keepalive_timeout 65;

# gzip on;

Server {
Listen, 8000;
Server_name localhost.

#charset koi8-r;

# access_log logs/host. Access. Log the main;

The location/{
The root HTML;
The index index. HTML index. HTM;
}

404/404 # error_page. HTML;

# redirect server error pages to the static page/50 x) HTML
#
Error_page 504/50, 500, 502, 503 x. HTML;
Location=/50 x) HTML {
The root HTML;
}
}
}

3. Two nginx server realserver file
SNS_VIP=192.168.75.140
The/etc/rc. D/init. D/functions provides
Case "$1" in
Start)
The ifconfig lo: 0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
/sbin/route add - host $SNS_VIP dev lo: 0
Echo "1" & gt; The/proc/sys/net/ipv4/conf/lo/arp_ignore
Echo "2" & gt; The/proc/sys/net/ipv4/conf/lo/arp_announce
Echo "1" & gt; The/proc/sys/net/ipv4/conf/all/arp_ignore
Echo "2" & gt; The/proc/sys/net/ipv4/conf/all/arp_announce
Sysctl -p & gt;/dev/null 2 & gt; & 1
Echo "RealServer Start OK
";;
Stop)
The ifconfig lo: 0 down
The route del $SNS_VIP & gt;/dev/null 2 & gt; & 1
Echo "0" & gt; The/proc/sys/net/ipv4/conf/lo/arp_ignore
Echo "0" & gt; The/proc/sys/net/ipv4/conf/lo/arp_announce
Echo "0" & gt; The/proc/sys/net/ipv4/conf/all/arp_ignore
Echo "0" & gt; The/proc/sys/net/ipv4/conf/all/arp_announce
Echo "RealServer Stoped
";;
*)
Echo "Usage: $0 {start | stop}"
The exit 1
Esac
The exit 0


4. The LVS + keepalived + master : 192.168.75.128 keepalived. Conf file:
! The Configuration File for keepalived
Bal_defs {
# # notification_email {email notification
# [email protected] # set alarm email address, you can set multiple, each one,
# [email protected]
# [email protected]
#}
# # notification_email_from [email protected] set the mail delivery address
# # smtp_server 192.168.200.1 set SMTP server address
30 # # smtp_connect_timeout set the connection to SMTP server timeout
Router_id LVS_DEVEL # said keepalived server running a logo, email is shown in the email subject information
# vrrp_skip_check_adv_addr
# vrrp_strict
# vrrp_garp_interval 0
# vrrp_gna_interval 0
}

Vrrp_instance VI_1 {
State the role of the MASTER # designated keepalived, MASTER said the host is the main server, BACKUP said that host is the standby server
IP interface eth0 # name card, use a command can see
Virtual_router_id 51 # virtual routing identification, the main set must be the same for the two nodes, belong to the same VRRP group to indicate each node
100 # define priority priority, the greater the number, the higher the priority, under the same vrrp_instance, MASTER the priority must be greater than the BACKUP of priority
Advert_int 1 # # set the MASTER and BACKUP synchronous check the time interval between the load balancer, units are seconds
Authentication {# set the authentication type and password
The auth_type PASS # set authentication type, there are mainly two PASS and AH
Auth_pass 1111 # set authentication codes, under the same vrrp_instance, MASTER and BACKUP must use the same password can normal communication
}
Virtual_ipaddress {# set the VIP
192.168.75.140 # can be multiple virtual IP, newline can
}
}

Virtual_server 192.168.75.140 8000 {# set the virtual server, you need to specify the virtual IP address and service port, with a space between the IP and port
Delay_loop 6 # # health examination time, the unit s
Lb_algo rr # load balance scheduling algorithm WLC | rr, and you will use the LVS scheduling algorithm to maintain consistent principle
Lb_kind DR # set the LVS load balancing mechanism, NAT, top, DR three mode optional
Persistence_timeout 50 # session holding time, the unit is the second, this option is useful for dynamic web pages, for the sharing session in the cluster system provides a good solution,
# has the function of this session, the user's request will be has been distributed to a service node, until more than keep the session time,
# it is important to note that the session will remain time is maximum response timeout, that is, users in the operation of the dynamic pages, if 50 seconds does not perform any work
# the next operation will be distributed to the other node, but if the user has been operating dynamic pages, is not restricted by time of 50 seconds
Protocol TCP # designated forwarding protocol type, has two kinds of TCP and UDP

Real_server 192.168.75.129 8000 {# real server, here is Nginx server
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related