keepalived简单安装

时间:2024-11-16 07:32:21

一、Keepalived简介

     Keepalived是Linux下一个轻量级别的高可用解决方案,部署和使用简单,主要用途是对其他服务和本身状态监控。

二、keepalived 特点

  1. 服务故障转移,主备容灾
  2. 可实现ip漂移,简单的集群高可用
  3. 心跳检测,监控nginx,mysql, redis等服务挂掉后,尝试重启

三、keepalived 安装部署

  1. yum -y install openssl openssl-devel    # 待找依赖包下载
  2. wget /software/keepalived-0.
  3. tar -zxvf ......
  4. cd keepalived-2.0.20
  5. ./configure --prefix=/usr/local/keepalived-2.0.20
  6. make && make install
  7. mkdir -p /etc/keepalived
  8. cp /usr/local/keepalived-2.0.20/etc/keepalived/ /etc/keepalived/
  9. ln -s /usr/local/keepalived-2.0.20/sbin/keepalived /usr/bin/
  10. 配置
  11. systemctl restart keepalived
  12. systemctl enable keepalived

四、Keepalived配置及说明

! Configuration File for keepalived

#global_defs {

#notification_email {

#root@localhost

#}

#notification_email_from keepalived@localhost #定义来信人

#smtp_server 127.0.0.1

#smtp_connect_timeout 30

#router_id node-00

#vrrp_mcast_group4 224.0.38.12

#}

vrrp_script check_nginx {

  script "/data/sh/check_nginx.sh"

  interval 2

  weight -20

}

vrrp_instance VI_1 {

state MASTER # 其余服务器配置BACKUP

interface eth0 # 需要通信的ip所在的网卡

virtual_router_id 38 # 当前虚拟路由器的惟一标识,范围是0-255;同一虚拟ip下该值要一致。

priority 100 # 当前主机在此虚拟路径器中的优先级;范围1-254;该值用于多服务器选主。

nopreempt # 定义工作模式为非抢占模式 ;如果想使用非抢占模式,主从节点的state 都要设置为BACKUP;

advert_int 1 # vrrp通告的时间间隔;

authentication {

auth_type PASS

auth_pass x1er44q

}

track_script {

  check_nginx

#check_redis

}

virtual_ipaddress {

     172.16.104.69 dev eth1      # v-ip, 把vip绑定到指定网卡上。

}

virtual_routes {
     default via 172.16.1.1       # 指定网关。

}

#smtp_alert #状态切换,使用邮件通知

}