keepalive+nginx搭建主从负载服务器
keepalive配置文件 从:
! Configuration File for keepalived
global_defs {
notification_email {
xuezm@yaoshi.com
}
notification_email_from xuezm@yaoshi.com
smtp_server mail.yaoshi.com
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.11.39
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass chtopnet
}
virtual_ipaddress {
192.168.11.208
}
}
keepalive 主:
!Configuration File for keepalived
global_defs {
notification_email {
xuezm@yaoshi.com
}
notification_email_from xuezm@yaoshi.com
smtp_server mail.yaoshi.com
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.11.27
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass chtopnet
}
virtual_ipaddress {
192.168.11.208
}
}
nginx配置 :
user nobody nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log debug;
pid logs/nginx.pid;
events {
use epoll;
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;
gzip_min_length 1k;
gzip_buffers 6 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
# location / {
# root html;
# index index.html index.htm;
# }
error_page 404 /404.html;
upstream www.test.com {
server 192.168.11.37:80;
server 192.168.11.38:80;
}
server
{
listen 80;
server_name www.test.com 192.168.11.208;
index index.htm index.html;
#root /web/wwwroot;
location / {
proxy_pass http://www.test.com;
proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
include proxy.conf;
}
log_format blog_test_com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/blog_test_com;
}
}
proxy.conf 配置
[root@localhost conf]# cat proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 6 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;