keepalived配置文件示例

一、实验环境

keepalived-master:
  192.168.2.195
keepalived-backup:
  192.168.2.196
vip
  192.168.2.194

应用服务器
  nginx1:192.168.2.197
  nginx2:192.168.2.198

二、keepalived-master配置

global_defs {
   notification_email {
     weimingliang@guanshizhai.online
   }
   notification_email_from guanshizhaimonitor@guanshizhai.online
   smtp_server mail.guanshizhai.online
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       192.168.2.194
    }
}

virtual_server 192.168.2.194 80 {
    delay_loop 6
    lb_algo rr
    lb_kindr DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.2.197 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.2.198 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }  
}

三、keepalived-backup配置

global_defs {
   notification_email {
     weimingliang@guanshizhai.online
   }
   notification_email_from guanshizhaimonitor@guanshizhai.online
   smtp_server mail.guanshizhai.online
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       192.168.2.194
    }
}

virtual_server 192.168.2.194 80 {
    delay_loop 6
    lb_algo rr
    lb_kindr DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.2.197 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.2.198 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }  
}

四、nginx1配置

down.guanshizhai.online/s
  sh nginx_install.sh
  /usr/local/nginx/sbin/nginx 

五、nginx2配置

down.guanshizhai.online/s
  sh nginx_install.sh
  /usr/local/nginx/sbin/nginx 
Previous Post

keepalived命令详解

Next Post

lvs常用的操作

Related Posts