vivion32 发表于 2018-11-13 07:34:56

keepalive+nginx搭建主从负载服务器

  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配置 :
  


[*]usernobody nobody;
[*]worker_processes1;
[*]
[*]#error_loglogs/error.log;
[*]#error_loglogs/error.lognotice;
[*]error_loglogs/error.logdebug;
[*]
[*]pid      logs/nginx.pid;
[*]
[*]
[*]events {
[*]    use epoll;
[*]    worker_connections1024;
[*]}
[*]
[*]
[*]http {
[*]    include       mime.types;
[*]    default_typeapplication/octet-stream;
[*]
[*]    log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
[*]                      '$status $body_bytes_sent "$http_referer" '
[*]                      '"$http_user_agent" "$http_x_forwarded_for"';
[*]
[*]    access_loglogs/access.logmain;
[*]
[*]    sendfile      on;
[*]    #tcp_nopush   on;
[*]
[*]    #keepalive_timeout0;
[*]    keepalive_timeout65;
[*]
[*]    gzipon;
[*]    gzip_min_length 1k;
[*]    gzip_buffers    6   16k;
[*]    gzip_http_version   1.1;
[*]    gzip_comp_level 2;
[*]    gzip_typestext/plainapplication/x-javascript    text/css application/xml;
[*]    gzip_vary   on;
[*]#   location / {
[*]#            root   html;
[*]#            indexindex.html index.htm;
[*]#      }
[*]      error_page404            /404.html;
[*]
[*]    upstream www.test.com {
[*]            server192.168.11.37:80;
[*]            server192.168.11.38:80;
[*]            }
[*]
[*]    server
[*]    {
[*]      listen80;
[*]      server_name www.test.com 192.168.11.208;
[*]      index   index.htmindex.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_formatblog_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 配置
  


[*]# cat proxy.conf
[*]proxy_redirectoff;
[*]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;
  



页: [1]
查看完整版本: keepalive+nginx搭建主从负载服务器