Keepalived配置简介

Keepalived配置文件使用以下概要

全局定义概要

global_defs {
    notification_email {
        email
        email
    }
    notification_email_from email
    smtp_server host
    smtp_connect_timeout num
    lvs_id string
}
关键字 定义 类型
global_defs 标识全局定义配置块 Block
notification_email 用于收取邮件通知的电子邮箱 List
notification_email_from 处理“MAIL FROM:”SMTP命令时使用的电子邮箱 List
smtp_server 用于发送邮件通知的SMTP服务器 alphanum
smtp_connection_timeout 指定SMTP流处理的超时时间 numerical
lvs_id 指定LVS导向器的名字 alphanum

email类型:使用 SMTP RFC 中指定字符集的字符串,例如:user@domain.com

虚拟服务器定义概要

virtual_server (@IP PORT)|(fwmark num) {
    delay_loop num
    lb_algo rr|wrr|lc|wlc|sh|dh|lblc
    lb_kind NAT|DR|TUN
    (nat_mask @IP)
    persistence_timeout num
    persistence_granularity @IP
    virtualhost string
    protocol TCP|UDP

    sorry_server @IP PORT
    real_server @IP PORT {
        weight num
        TCP_CHECK {
            connect_port num
            connect_timeout num
        }
    }
    real_server @IP PORT {
        weight num
        MISC_CHECK {
            misc_path /path_to_script/script.sh
            (or misc_path “ /path_to_script/script.sh <arg_list>”)
        }
    }
}
real_server @IP PORT {
    weight num
    HTTP_GET|SSL_GET {
        url { # You can add multiple url block
            path alphanum
            digest alphanum
        }
        connect_port num
        connect_timeout num
        retry num
        delay_before_retry num
    }
}
关键字 定义 类型
virtual_server 标识虚拟服务器定义块 Block
fwmark 指定虚拟服务器是FWMARK  
delay_loop 以秒为单位指定检查之间的间隔时间 numerical
lb_algo 选择一个特定的调度程序(rr|wrr|lc|wlc…) string
lb_kind 选择一个特定的转发方法(NAT|DR|TUN) string
persistence_timeout 为持久连接指定超时时间 numerical
persistence_granularity 为持久连接指定粒度掩码  
virtualhost 指定用于HTTP|SSL_GET的虚拟主机 alphanum
protocol 指定协议类型(TCP|UDP) numerical
sorry_server 当所有真实服务器都宕掉时添加到池中的服务器  
real_server 指定一个真实服务器成员  
weight 为真实服务器指定负载均衡的权重 numerical
TCP_CHECK 使用TCP连接检查真实服务器的可用性  
MISC_CHECK 使用用户定义的脚本检查真实服务器的可用性  
misc_path 标识要运行脚本的完整路径 path
HTTP_GET 使用HTTP GET请求检查真实服务器的可用性  
SSL_GET 使用HTTPS GET请求检查真实服务器的可用性  
url 标识url定义块 Block
path 指定url路径 alphanum
digest 指定特定url路径的摘要 alphanum
connect_port 指定连接远程服务器的TCP端口 numerical
connect_timeout 指定连接远程服务器的超时时间 numerical
retry 最大重试次数 numerical
delay_before_retry 两次连续重试之间的延迟 numerical

注解

如果您没有将LVS与Linux内核2.2系统一起使用,那么“net_mask”关键字就是过时的。此标志使您能够定义反向NAT粒度。

注解

目前,健康检查框架只实现了基于TCP协议的服务监控。

注解

类型“path”指的是被调用脚本的完整路径。对于需要参数的脚本,路径和参数必须用双引号括起来。

VRRP实例定义概要

vrrp_sync_group string {
    group {
        string
        string
    }
    notify_master /path_to_script/script_master.sh
        (or notify_master “ /path_to_script/script_master.sh <arg_list>”)
    notify_backup /path_to_script/script_backup.sh
        (or notify_backup “/path_to_script/script_backup.sh <arg_list>”)
    notify_fault /path_to_script/script_fault.sh
        (or notify_fault “ /path_to_script/script_fault.sh <arg_list>”)
}
vrrp_instance string {
    state MASTER|BACKUP
    interface string
    mcast_src_ip @IP
    lvs_sync_daemon_interface string
    virtual_router_id num
    priority num
    advert_int num
    smtp_alert
    authentication {
        auth_type PASS|AH
        auth_pass string
    }
    virtual_ipaddress { # Block limited to 20 IP addresses
        @IP
        @IP
        @IP
    }
    virtual_ipaddress_excluded { # Unlimited IP addresses
        @IP
        @IP
        @IP
    }
    notify_master /path_to_script/script_master.sh
        (or notify_master “ /path_to_script/script_master.sh <arg_list>”)
    notify_backup /path_to_script/script_backup.sh
        (or notify_backup “ /path_to_script/script_backup.sh <arg_list>”)
    notify_fault /path_to_script/script_fault.sh
        (or notify_fault “ /path_to_script/script_fault.sh <arg_list>”)
}
关键字 定义 类型
vrrp_instance 标识VRRP实例定义块 Block
state 在标准使用中指定实例状态  
interface 指定实例运行所要用到的网络接口 string
mcast_src_ip 指定VRRP通告的IP头的源地址  
lvs_sync_daemon_inteface 指定LVS sync_daemon运行所要用到的网络接口 string
virtual_router_id 指定实例所属的VRRP路由器ID numerical
priority 指定实例在VRRP路由器中的优先级 numerical
advert_int 以秒为单位指定通告的间隔时间(设置为1) numerical
smtp_alert 激活MASTER状态转换的SMTP通知  
authentication 标识VRRP认证定义块 Block
auth_type 指定要使用哪种身份认证(PASS|AH)  
auth_pass 指定要使用的密码字符串 string
virtual_ipaddress 标识VRRP VIP定义块 Block
virtual_ipaddress_excluded 标识VRRP VIP排除定义块 Block
notify_master 指定在切换到master时要执行的脚本 path
notify_backup 指定在切换到backup时要执行的脚本 path
notify_fault 指定在切换到故障状态时要执行的脚本 path
vrrp_sync_group 标识VRRP同步组定义块 Block

path类型:脚本的系统路径,例如:/usr/local/bin/transit.sh <arg_list>