ubuntu12.04下双机热备份的问题

Precise Pangolin (长期支持)
回复
shawin57
帖子: 8
注册时间: 2012-10-10 9:01
系统: ubuntu-server-64
送出感谢: 0
接收感谢: 0

ubuntu12.04下双机热备份的问题

#1

帖子 shawin57 » 2013-03-15 14:59

最近准备弄了双机热备份防止网站崩溃后不能及时解决的问题。基于ruby on rails架构采用keepalived+nginx做了一个双机热备份。
服务器1:主nginx+keepalived 10.1.2.30
服务器2:备用nginx+keepalived 10.1.2.31

然后这两台服务器共同虚拟出一个IP地址:10.1.2.50. 域名(假设为www.webtest.com)解析的IP地址为该地址。

将2台服务器配置好后,启动nginx和keepalived,访问www.webtest.com IP指向10.1.2.50 并能打开网页,但是测试的时候发现如果我关掉其中任何一台服务器,网页均不能打开。请各位帮忙看下。下面贴上主nginx的配置和keepalived的配置。
主nginx.conf
user rails;
worker_processes 8;

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

#pid logs/nginx.pid;
worker_rlimit_nofile 65500;

events {
use epoll;
worker_connections 65500;
}


http {
passenger_root /home/rails/.rvm/gems/ruby-1.9.3-p392/gems/passenger-3.0.19;
passenger_ruby /home/rails/.rvm/wrappers/ruby-1.9.3-p392/ruby;

passenger_max_pool_size 100;
# passenger_enabled on;
passenger_min_instances 3;
server_names_hash_bucket_size 128;
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
include mime.types;
default_type application/octet-stream;
tcp_nodelay on;
client_max_body_size 300m;
client_body_buffer_size 128k;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 16k;
proxy_buffers 4 32k;
proxy_temp_file_write_size 64k;

sendfile on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_comp_level 2;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml text/javascript;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

upstream webcache{
# ip_hash;
server 10.1.2.30:80 weight=1 max_fails=2 fail_timeout=20s;
server 10.1.2.31:80 weight=1 max_fails=2 fail_timeout=20s;
}
server {
listen 80;
server_name www.webtest.com;
root /home/rails/webapp/current/public;
access_log off;
location / {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
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;
proxy_pass http://webcache;
}
passenger_enabled on;
rails_env production;
if (-f $document_root/system/cache/$uri/index.html) {
rewrite (.*) /system/cache/$1/index.html break;
}

if (-f $document_root/system/cache/$uri.html) {
rewrite (.*) /system/cache/$1.html break;
}
}
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /opt/nginx/logs/access.log access;
}


主机keepalived配置

! Configuration File for keepalived
global_defs {
notification_email {
13122264905@wo.com.cn
}
notification_email_from keepalived@chtopnet.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id yeetou
}
vrrp_instance VI_1 {
state MASTER
interface eth0
dont_track_primary
garp_master_delay 10
virtual_router_id 51
mcast_src_ip 10.1.2.30
priority 150
advert_int 5
authentication {
auth_type PASS
auth_pass chtopnet
}
virtual_ipaddress {
10.1.2.50
}
}


备机keepalived配置

! Configuration File for keepalived
global_defs {
notification_email {
13122264905@wo.com.cn
}
notification_email_from keepalived@chtopnet.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id yeetou
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
dont_track_primary
garp_master_delay 10
mcast_src_ip 10.1.2.31
priority 50
advert_int 5
authentication {
auth_type PASS
auth_pass chtopnet
}
virtual_ipaddress {
10.1.2.50
}
}

各位大侠速速支个招
onlylove
论坛版主
帖子: 4437
注册时间: 2007-01-14 16:23
送出感谢: 0
接收感谢: 100 次

Re: ubuntu12.04下双机热备份的问题

#2

帖子 onlylove » 2013-03-15 15:15

你停掉一个的keepalived或者nginx,然后看下log
#include <stdio.h>
void main()
{
double world;
unsigned letter;
short stay;
long memories;
printf("I miss you.\n");
}
回复

回到 “Ubuntu 12.04 LTS”