Keepalive+Nginx搭建主從負載服務器

keepalive+nginx搭建主從負載服務器

keepalive配置文件 從:


  1. ! Configuration File for keepalived

  2. global_defs {

  3.   notification_email {

  4.   [email protected]

  5.        }

  6.   notification_email_from [email protected]

  7.   smtp_server mail.yaoshi.com

  8.   smtp_connect_timeout 30

  9.   router_id LVS_DEVEL

  10. }

  11. vrrp_instance VI_1 {

  12.    state MASTER

  13.    interface eth0

  14.    virtual_router_id 51

  15.    mcast_src_ip 192.168.11.39

  16.    priority 80

  17.    advert_int 1

  18.    authentication {

  19.        auth_type PASS

  20.        auth_pass chtopnet

  21.    }

  22.    virtual_ipaddress {

  23.        192.168.11.208

  24.    }

  25. }

keepalive 主:


  1. !Configuration File for keepalived

  2. global_defs {

  3.   notification_email {

  4.   [email protected]

  5.        }

  6.   notification_email_from [email protected]

  7.   smtp_server mail.yaoshi.com

  8.   smtp_connect_timeout 30

  9.   router_id LVS_DEVEL

  10. }

  11. vrrp_instance VI_1 {

  12.    state MASTER

  13.    interface eth0

  14.    virtual_router_id 51

  15.    mcast_src_ip 192.168.11.27

  16.    priority 100

  17.    advert_int 1

  18.    authentication {

  19.        auth_type PASS

  20.        auth_pass chtopnet

  21.    }

  22.    virtual_ipaddress {

  23.        192.168.11.208

  24.    }

  25. }

nginx配置 :


  1. user  nobody nobody;

  2. worker_processes  1;

  3. #error_log  logs/error.log;

  4. #error_log  logs/error.log  notice;

  5. error_log  logs/error.log  debug;

  6. pid        logs/nginx.pid;

  7. events {

  8.    use epoll;

  9.    worker_connections  1024;

  10. }

  11. http {

  12.    include       mime.types;

  13.    default_type  application/octet-stream;

  14.    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

  15.                      '$status $body_bytes_sent "$http_referer" '

  16.                      '"$http_user_agent" "$http_x_forwarded_for"';

  17.    access_log  logs/access.log  main;

  18.    sendfile        on;

  19.    #tcp_nopush     on;

  20.    #keepalive_timeout  0;

  21.    keepalive_timeout  65;

  22.    gzip  on;

  23.    gzip_min_length 1k;

  24.    gzip_buffers    6   16k;

  25.    gzip_http_version   1.1;

  26.    gzip_comp_level 2;

  27.    gzip_types  text/plain  application/x-javascript    text/css application/xml;

  28.    gzip_vary   on;

  29. #   location / {

  30. #            root   html;

  31. #            index  index.html index.htm;

  32. #        }

  33.        error_page  404              /404.html;

  34.    upstream www.test.com {

  35.            server  192.168.11.37:80;

  36.            server  192.168.11.38:80;

  37.            }

  38.    server

  39.    {

  40.        listen  80;

  41.        server_name www.test.com 192.168.11.208;

  42.        index   index.htm  index.html;

  43.        #root /web/wwwroot;

  44.    location / {

  45.        proxy_pass http://www.test.com;

  46.        proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;

  47.        proxy_set_header   Host             $host;

  48.        proxy_set_header   X-Real-IP        $remote_addr;

  49.        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

  50.        include proxy.conf;

  51.      }

  52.    log_format  blog_test_com  '$remote_addr - $remote_user [$time_local] $request '

  53.                                '"$status" $body_bytes_sent "$http_referer" '

  54.                                '"$http_user_agent" "$http_x_forwarded_for"';

  55.              access_log logs/blog_test_com;

  56.     }

  57.    }

proxy.conf 配置

  1. [root@localhost conf]# cat proxy.conf  

  2. proxy_redirect  off;

  3. proxy_set_header    Host    $host;

  4. proxy_set_header    X-Real-IP $remote_addr;

  5. proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;

  6. client_body_buffer_size 128k;

  7. proxy_connect_timeout 90;

  8. proxy_send_timeout 90;

  9. proxy_read_timeout 90;

  10. proxy_buffer_size   4k;

  11. proxy_buffers 6 32k;

  12. proxy_busy_buffers_size 64k;

  13. proxy_temp_file_write_size 64k;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章