xiamn 发表于 2013-6-8 09:09:46

keepalived 安装和配置

一,keepalived安装# wgethttp://www.keepalived.org/software/keepalived-1.2.1.tar.gz
# tar zxvf keepalived-1.2.1.tar.gz
# cd keepalived-1.2.1
# ./configure --prefix=/usr/local/keepalived# make && make install

安装排错:1,
configure: error:
!!! OpenSSL is not properly installed on your system. !!!
!!! Can not include OpenSSL headers files.            !!!
解决方法: # yum install -y openssl-devel
2,Use IPVS Framework       : No
IPVS sync daemon support : No

这里不是必须的,但是还是建议大家安装上# cd /usr/src/kernels/# yum install -y kernel-devel ipvsadm
# ln -s /usr/src/kernels/2.6.18-194.el5-x86_64/   /usr/src/linux

二、keepalived安装验证1,检查目录及相应的文件信息# cd /usr/local/keepalived/
bin/   etc/   sbin/share/

2,启动设置# cp /usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/
# mkdir/etc/keepalived         
# cp/usr/local/keepalived/etc/keepalived/keepalived.conf/etc/keepalived/
# cp/usr/local/keepalived/sbin/keepalived/usr/sbin/# service keepalived start
Starting keepalived:                                       
# ps aux|grep keepalived
root   188460.00.135832   620 ?      Ss   04:33   0:00 keepalived -D
root   188470.20.3379241556 ?      S    04:33   0:00 keepalived -D
root   188480.00.2379241028 ?      S    04:33   0:00 keepalived -D
Keepalived正常运行时,共启动3个进程,其中一个进程时父进程,负责监控其子       进程,一个是vrrp子进程;另外一个是checkers子进程。   


三,keepalived.conf的配置global_defs {
   notification_email {#指定keepalived在发生切换时需要发送email到的对象,一行一个

   }
    notification_email_from#指定发件人
    smtp_server localhost #指定smtp服务器地址
    smtp_connect_timeout 30 #指定smtp连接超时时间
    router_id LVS_DEVEL #运行keepalived机器的一个标识
}
vrrp_sync_group VG_1{ #监控多个网段的实例
       group {
inside_network   #实例名
outside_network
}
notify_master /path/xx.sh #指定当切换到master时,执行的脚本
netify_backup /path/xx.sh #指定当切换到backup时,执行的脚本
notify_fault "path/xx.sh VG_1" #故障时执行的脚本
notify /path/xx.sh
smtp_alert   #使用global_defs中提供的邮件地址和smtp服务器发送邮件通知
}
vrrp_instance inside_network {
   state BACKUP #指定那个为master,那个为backup,如果设置了nopreempt这个值不起作用,主备靠priority决定
   interface eth0 #设置实例绑定的网卡
   dont_track_primary #忽略vrrp的interface错误(默认不设置)
   track_interface{ #设置额外的监控,里面那个网卡出现问题都会切换
    eth0
    eth1
   }
   mcast_src_ip #发送多播包的地址,如果不设置默认使用绑定网卡的primary ip
   garp_master_delay #在切换到master状态后,延迟进行gratuitous ARP请求
   virtual_router_id 50 #VPID标记
   priority 99 #优先级,高优先级竞选为master
   advert_int 1 #检查间隔,默认1秒
   nopreempt #设置为不抢占 注:这个配置只能设置在backup主机上,而且这个主机优先级要比另外一台高
   preempt_delay #抢占延时,默认5分钟
   debug #debug级别
   authentication { #设置认证
       auth_type PASS #认证方式
       auth_pass 111111 #认证密码
   }
   virtual_ipaddress { #设置vip
       192.168.202.200
   }
}

virtual_server 192.168.202.200 23 {
   delay_loop 6#健康检查时间间隔
   lb_algo rr    #lvs调度算法rr|wrr|lc|wlc|lblc|sh|dh
   lb_kind DR    #负载均衡转发规则NAT|DR|RUN
   persistence_timeout 5   #会话保持时间
   protocol TCP            #使用的协议
   persistence_granularity <NETMASK>      #lvs会话保持粒度
   virtualhost <string>                   #检查的web服务器的虚拟主机(host:头)   
   sorry_server<IPADDR> <port>            #   备用机,所有realserver失效后启用
   real_server 192.168.200.5 23 {
weight 1                                  #默认为1,0为失效
inhibit_on_failure #在服务器健康检查失效时,将其设为0,而不是直接从ipvs中删除
notify_up <string> | <quoted-string> #在检测到server up后执行脚本
notify_down <string> | <quoted-string> #在检测到server down后执行脚本

TCP_CHECK {
   connect_timeout 3 #连接超时时间
   nb_get_retry 3 #重连次数
   delay_before_retry 3 #重连间隔时间
   connect_port 23健康检查的端口的端口
   bindto <ip>   
   }
HTTP_GET | SSL_GET{
    url{ #检查url,可以指定多个
path /
digest <string> #检查后的摘要信息
status_code 200 #检查的返回状态码
    }
    connect_port <port>
    bindto <IPADD>
    connect_timeout 5
    nb_get_retry 3
    delay_before_retry 2
}SMTP_CHECK{
    host{
    connect_ip <IP ADDRESS>
    connect_port <port> #默认检查25端口
    bindto <IP ADDRESS>
}
    connect_timeout 5
    retry 3
    delay_before_retry 2
    helo_name <string> | <quoted-string> #smtp helo请求命令参数,可选
}
MISC_CHECK{
misc_path <string> | <quoted-string> #外部脚本路径
misc_timeout #脚本执行超时时间
misc_dynamic #如设置该项,则退出状态码会用来动态调整服务器的权重,返回0 正常,不修改;返回1,       检查失败,权重改为0;返回2-255,正常,权重设置为:返回状态码-2
}
   }}

   real_server 192.168.0.20 80 {//真实IP web的IP       weight 1//默认为1,0为失效       HTTP_GET {          connect_port 80//健康检查端口          connect_timeout 3//链接超时时间          nb_get_retry 3//重链次数          delay_before_retry 3//重连讲时间(秒)       }   }}


yanghongjun 发表于 2013-6-8 09:23:25

修养的艺术,其实就是说谎的艺术。

新风花雪月 发表于 2013-6-8 10:12:25

老天,你让夏天和冬天同房了吧?生出这鬼天气!

q989 发表于 2013-6-8 11:02:49

佛曰,色即是空,空即是色!今晚,偶想空一下

midea2 发表于 2013-6-8 12:09:15

勿以坑小而不灌,勿以坑大而灌之。

zidong 发表于 2013-6-8 13:19:49

学海无涯,回头是岸!

李斯特 发表于 2013-6-8 14:48:23

读书读到抽筋处,文思方能如尿崩!
页: [1]
查看完整版本: keepalived 安装和配置