keepalived配置文件说明

vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
     root@linux.tang.chao               #设置报警邮件地址,可以设置多个,每行一个。
     123456789@qq.com                   #需开启本机的sendmail服务
   }
   notification_email_from keepalived@localhost         #设置邮件的发送地址
   smtp_server 127.0.0.1                                #设置smtp server地址
   smtp_connect_timeout 30                              #设置连接smtp server的超时时间
   router_id LVS_DEVEL                                  #表示运行keepalived服务器的一个标识。发邮件时显示在邮件主题的信息
}

vrrp_instance VI_1 {
    state MASTER              #指定keepalived的角色,MASTER表示此主机是主服务器,BACKUP表示此主机是备用服务器
    interface eth0            #指定HA监测网络的接口
    virtual_router_id 51      #虚拟路由标识,这个标识是一个数字,同一个vrrp实例使用唯一的标识。即同一vrrp_instance下,MASTER和BACKUP必须是一致的
    priority 100              #定义优先级,数字越大,优先级越高,在同一个vrrp_instance下,MASTER的优先级必须大于BACKUP的优先级
    advert_int 1              #设定MASTER与BACKUP负载均衡器之间同步检查的时间间隔,单位是秒
    authentication {          #设置验证类型和密码
        auth_type PASS        #设置验证类型,主要有PASS和AH两种
        auth_pass 1111        #设置验证密码,在同一个vrrp_instance下,MASTER与BACKUP必须使用相同的密码才能正常通信
    }
    virtual_ipaddress {       #设置虚拟IP地址,可以设置多个虚拟IP地址,每行一个
        10.0.0.3
    }
}

#ipvsadm -A -t 10.0.0.3:80 -s wrr -p 50  相当于virtual_server的配置
virtual_server 10.0.0.10 80 {       #设置虚拟服务器,需要指定虚拟IP地址和服务端口,IP与端口之间用空格隔开
    delay_loop 6                    #设置运行情况检查时间,单位是秒
    lb_algo rr                      #设置负载调度算法,这里设置为rr,即轮询算法
    lb_kind DR                      #设置LVS实现负载均衡的机制,有NAT、TUN、DR三个模式可选
    persistence_timeout 50          #会话保持时间,单位是秒。这个选项对动态网页是非常有用的,为集群系统中的session共享提供了一个很好的解决方案。
                                    #有了这个会话保持功能,用户的请求会被一直分发到某个服务节点,直到超过这个会话的保持时间。
                                    #需要注意的是,这个会话保持时间是最大无响应超时时间,也就是说,用户在操作动态页面时,如果50秒内没有执行任何操作,
                                    #那么接下来的操作会被分发到另外的节点,但是如果用户一直在操作动态页面,则不受50秒的时间限制
    protocol TCP                    #指定转发协议类型,有TCP和UDP两种

    real_server 10.0.0.7 80 {       #配置服务节点1,需要指定real server的真实IP地址和端口,IP与端口之间用空格隔开
        weight 3                    #配置服务节点的权值,权值大小用数字表示,数字越大,权值越高,设置权值大小可以为不同性能的服务器
                                    #分配不同的负载,可以为性能高的服务器设置较高的权值,而为性能较低的服务器设置相对较低的权值,这样才能合理地利用和分配系统资源
        TCP_CHECK {                 #realserver的状态检测设置部分,单位是秒
            connect_timeout 10      #表示3秒无响应超时
            nb_get_retry 3          #表示重试次数
            delay_before_retry 3    #表示重试间隔
            connect_port 80
        }
    }
    real_server 10.0.0.8 80 {
        weight 3
        TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
}
#ipvsadm -a -t 10.0.0.10:80 -r 10.0.0.7:80 -g -w 1 
#ipvsadm -a -t 10.0.0.10:80 -r 10.0.0.8:80 -g -w 1

  

ipvsadm-save
ipvsadm -C
ipvsadm --set 30 5 60
第一个参数为tcp超时时间,第二个参数为tcpfin超时时间,第三个参数为udp超时时间

ipvsadm --persistent 与 --set

keepalived+LVS超时设置产生的realserver的tcp连接不释放问题

 

ipvsadm-save -n >/tmp/ipvsadm-lb01.bak
 cat /tmp/ipvsadm-lb01.bak
-A -t 10.0.0.3:80 -s wrr -p 20
-a -t 10.0.0.3:80 -r 10.0.0.7:80 -g -w 1
-a -t 10.0.0.3:80 -r 10.0.0.8:80 -g -w 1

帮助命令 

ipvsadm --help
ipvsadm v1.26 2008/5/15 (compiled with popt and IPVS v1.2.1)
Usage:
  ipvsadm -A|E -t|u|f service-address [-s scheduler] [-p [timeout]] [-M netmask] [--pe persistence_engine]
  ipvsadm -D -t|u|f service-address
  ipvsadm -C
  ipvsadm -R
  ipvsadm -S [-n]
  ipvsadm -a|e -t|u|f service-address -r server-address [options]
  ipvsadm -d -t|u|f service-address -r server-address
  ipvsadm -L|l [options]
  ipvsadm -Z [-t|u|f service-address]
  ipvsadm --set tcp tcpfin udp
  ipvsadm --start-daemon state [--mcast-interface interface] [--syncid sid]
  ipvsadm --stop-daemon state
  ipvsadm -h

Commands:
Either long or short options are allowed.
  --add-service     -A        add virtual service with options
  --edit-service    -E        edit virtual service with options
  --delete-service  -D        delete virtual service
  --clear           -C        clear the whole table
  --restore         -R        restore rules from stdin
  --save            -S        save rules to stdout
  --add-server      -a        add real server with options
  --edit-server     -e        edit real server with options
  --delete-server   -d        delete real server
  --list            -L|-l     list the table
  --zero            -Z        zero counters in a service or all services
  --set tcp tcpfin udp        set connection timeout values
  --start-daemon              start connection sync daemon
  --stop-daemon               stop connection sync daemon
  --help            -h        display this help message

Options:
  --tcp-service  -t service-address   service-address is host[:port]
  --udp-service  -u service-address   service-address is host[:port]
  --fwmark-service  -f fwmark         fwmark is an integer greater than zero
  --ipv6         -6                   fwmark entry uses IPv6
  --scheduler    -s scheduler         one of rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq,
                                      the default scheduler is wlc.
  --pe            engine              alternate persistence engine may be sip,
                                      not set by default.
  --persistent   -p [timeout]         persistent service
  --netmask      -M netmask           persistent granularity mask
  --real-server  -r server-address    server-address is host (and port)
  --gatewaying   -g                   gatewaying (direct routing) (default)
  --ipip         -i                   ipip encapsulation (tunneling)
  --masquerading -m                   masquerading (NAT)
  --weight       -w weight            capacity of real server
  --u-threshold  -x uthreshold        upper threshold of connections
  --l-threshold  -y lthreshold        lower threshold of connections
  --mcast-interface interface         multicast interface for connection sync
  --syncid sid                        syncid for connection sync (default=255)
  --connection   -c                   output of current IPVS connections
  --timeout                           output of timeout (tcp tcpfin udp)
  --daemon                            output of daemon information
  --stats                             output of statistics information
  --rate                              output of rate information
  --exact                             expand numbers (display exact values)
  --thresholds                        output of thresholds information
  --persistent-conn                   output of persistent connection info
  --nosort                            disable sorting output of service/server entries
  --sort                              does nothing, for backwards compatibility
  --ops          -o                   one-packet scheduling
  --numeric      -n                   numeric output of addresses and ports

---解释

--add-service     -A        add virtual service with option  
  在内核的虚拟服务器表中添加一条新的虚拟服务器记录。也就是增加一台新的虚拟服务器  
  --edit-service    -E        edit virtual service with options  
  编辑内核虚拟服务器表中的一条虚拟服务器记录  
  --delete-service  -D        delete virtual service  
  删除内核虚拟服务器表中的一条虚拟服务器记录  
  --clear           -C        clear the whole table  
  清除内核虚拟服务器表中的所有记录  
  --restore         -R        restore rules from stdin  
  恢复虚拟服务器规则  
  --save            -S        save rules to stdout  
  保存虚拟服务器规则,输出为-R 选项可读的格式  
  --add-server      -a        add real server with options  
  在内核虚拟服务器表的一条记录里添加一条新的真实服务器  
  --edit-server     -e        edit real server with options  
  编辑一条虚拟服务器记录中的某条真实服务器记录  
  --delete-server   -d        delete real server  
  删除一条虚拟服务器记录中的某条真实服务器记录  
  --list            -L|-l     list the table  
  显示内核虚拟服务器表  
  --zero            -Z        zero counters in a service or all services  
  虚拟服务表计数器清零  
  --set tcp tcpfin udp        set connection timeout values  
  设置连接超时值  
  --start-daemon              start connection sync daemon  
  启动同步守护进程。他后面可以是master 或backup,用来说明LVS Router 是master 或是backup。在这个功能上也可以采keepalived 的VRRP 功能。  
  --stop-daemon               stop connection sync daemon  
  停止同步守护进程  
  --help            -h        display this help message  
  显示帮助信息  
   
Options:  
   
  --tcp-service  -t service-address   service-address is host[:port]  
  说明虚拟服务器提供的是tcp 的服务[vip:port] or [real-server-ip:port]  
  --udp-service  -u service-address   service-address is host[:port]  
  说明虚拟服务器提供的是udp 的服务[vip:port] or [real-server-ip:port]  
  --fwmark-service  -f fwmark         fwmark is an integer greater than zero  
  说明是经过iptables 标记过的服务类型。  
  --scheduler    -s scheduler         one of rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq,the default scheduler is wlc.  
  使用的调度算法,有这样几个选项,默认的调度算法是: wlc.  
  --persistent   -p [timeout]         persistent service  
  持久稳固的服务。这个选项的意思是来自同一个客户的多次请求,将被同一台真实的服务器处理。timeout 的默认值为300 秒  
  --netmask      -M netmask           persistent granularity mask  
    
  --real-server  -r server-address    server-address is host (and port)  
  真实的服务器[Real-Server:port]  
  --gatewaying   -g                   gatewaying (direct routing) (default)  
  指定LVS 的工作模式为直接路由模式(也是LVS 默认的模式  
  --ipip         -i                   ipip encapsulation (tunneling)  
  指定LVS 的工作模式为隧道模式  
  --masquerading -m                   masquerading (NAT)  
  指定LVS 的工作模式为NAT 模式  
  --weight       -w weight            capacity of real server  
  真实服务器的权值  
  --u-threshold  -x uthreshold        upper threshold of connections  
    
  --l-threshold  -y lthreshold        lower threshold of connections  
   
  --mcast-interface interface         multicast interface for connection sync  
  指定组播的同步接口  
  --syncid sid                        syncid for connection sync (default=255)  
   
  --connection   -c                   output of current IPVS connections  
  显示LVS 目前的连接 如:ipvsadm -L -c  
  --timeout                           output of timeout (tcp tcpfin udp)  
  显示tcp tcpfin udp 的timeout 值 如:ipvsadm -L --timeout  
  --daemon                            output of daemon information  
  显示同步守护进程状态  
  --stats                             output of statistics information  
  显示统计信息  
  --rate                              output of rate information  
  显示速率信息  
  --thresholds                        output of thresholds information  
    
  --persistent-conn                   output of persistent connection info  
    
  --sort                              sorting output of service/server entries  
   对虚拟服务器和真实服务器排序输出  
  --ops          -O                   one-packet scheduling  
    
  --numeric      -n                   numeric output of addresses and ports  
  输出IP 地址和端口的数字形式  

---

--stat选项是统计自该条转发规则生效以来的包  
1. Conns    (connections scheduled)  已经转发过的连接数  
2. InPkts   (incoming packets)       入包个数  
3. OutPkts  (outgoing packets)       出包个数  
4. InBytes  (incoming bytes)         入流量(字节)    
5. OutBytes (outgoing bytes)         出流量(字节)  

--rate选项是显示速率信息  
1. CPS      (current connection rate)   每秒连接数  
2. InPPS    (current in packet rate)    每秒的入包个数  
3. OutPPS   (current out packet rate)   每秒的出包个数  
4. InBPS    (current in byte rate)      每秒入流量(字节)  
5. OutBPS   (current out byte rate)      每秒入流量(字节)

  

悠久之翼讲解的配置参数

  

  

posted @ 2017-04-14 09:52  reborn枪  阅读(341)  评论(0)    收藏  举报