高可用负载均衡配置(二) -- 负载均衡和高可用

3. 环境搭建

3.1 安装环境

  • Master 和 backup 一样
  • yum -y install nginx keepalived

3.2 配置代理

  • 修改 nginx 配置文件
    • vim /etc/nginx/nginx.conf
....
http {
    ...
    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_connect_timeout      60; 
    proxy_send_timeout         60; 
    proxy_read_timeout         60; 
    proxy_buffer_size          128k;
    proxy_buffers              4 64k;
    proxy_busy_buffers_size    128k;
    proxy_temp_file_write_size 128k;

    charset         utf-8;
    gzip                on;
    gzip_min_length     1k;
    gzip_buffers        8 16k;
    gzip_http_version   1.0;
    gzip_comp_level     5;
    gzip_types          application/javascript application/json application/x-javascript application/xml application/xml+rss text/css text/javascript text/plain text/xml;

    upstream web001 {
        server      192.168.11:81;
        server      192.168.12:81;
    }
    server {
        listen          80 default_server;
        server_name     localhost;
        access_log      /var/log/nginx/proxy_access.log     main;
        location / {
            proxy_pass http://web001;
        }      
    }
}

  • 将 node10011 的nignx 文件同步到 node10012 上.

3.3 配置keepalived

  • 修改 nginx 配置文件

  • Master

! Configuration File for keepalived
global_defs {
   notification_email {
        [email protected]
   }
   notification_email_from [email protected]
   smtp_server 192.168.10.9
   smtp_connect_timeout 30
   router_id master
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type keepalived
        auth_pass keepalivedpass
    }
    virtual_ipaddress {
        192.168.10.5
    }
}
  • BACKUP
! Configuration File for keepalived
global_defs {
   notification_email {
        [email protected]
   }   
   notification_email_from [email protected]
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id backup
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 100 
    advert_int 1
    authentication {
        auth_type keepalived
        auth_pass keepalivedpass
    }   
    virtual_ipaddress {
        192.168.10.5
    }   
}

你可能感兴趣的:(高可用负载均衡配置(二) -- 负载均衡和高可用)