Keepalived安装与配置

一、简介

Keepalived是一个免费开源的,用C编写的类似于layer3, 4 & 7交换机制软件,具备我们平时说的第3层、第4层和第7层交换机的功能。主要提供loadbalancing(负载均衡)和 high-availability(高可用)功能,负载均衡实现需要依赖Linux的虚拟服务内核模块(ipvs),而高可用是通过VRRP协议实现多台机器之间的故障转移服务。

上图是Keepalived的功能体系结构,大致分两层:用户空间(user space)和内核空间(kernel space)。
内核空间:主要包括IPVS(IP虚拟服务器,用于实现网络服务的负载均衡)和NETLINK(提供高级路由及其他相关的网络功能)两个部份。
用户空间

  • WatchDog:负载监控checkers和VRRP进程的状况
  • VRRP Stack:负载负载均衡器之间的失败切换FailOver,如果只用一个负载均稀器,则VRRP不是必须的。
  • Checkers:负责真实服务器的健康检查healthchecking,是keepalived最主要的功能。换言之,可以没有VRRP Stack,但健康检查healthchecking是一定要有的。
  • IPVS wrapper:用户发送设定的规则到内核ipvs代码
  • Netlink Reflector:用来设定vrrp的vip地址等。

Keepalived的所有功能是配置keepalived.conf文件来实现的。

二、安装与配置

从官网下载keepalived,本文以版本1.2.24为例。

2.1 安装

[root@keepalived-nginx1 ~]# wget http://www.keepalived.org/software/keepalived-1.2.24.tar.gz
[root@keepalived-nginx1 ~]# tar -xzvf keepalived-1.2.24.tar.gz
[root@keepalived-nginx1 ~]# cd keepalived-1.2.24

 

[root@keepalived-nginx1 keepalived-1.2.24]# ./configure --prefix=/usr/local/keepalived
[root@keepalived-nginx1 keepalived-1.2.24]# make && make install

 

 

2.2 配置

安装完成后,进入安装目录的etc目录下,将keepalived相应的配置文件拷贝到系统相应的目录当中。keepalived启动时会从/etc/keepalived目录下查找keepalived.conf配置文件,如果没有找到则使用默认的配置。/etc/keepalived目录安装时默认是没有安装的,需要手动创建。配置文件目录结构如下所示:

 

[root@keepalived-nginx1 ~]# tree -l /usr/local/keepalived/etc/
/usr/local/keepalived/etc/
├── keepalived
│   ├── keepalived.conf
│   └── samples
│       ├── client.pem
│       ├── dh1024.pem
│       ├── keepalived.conf.fwmark
│       ├── keepalived.conf.HTTP_GET.port
│       ├── keepalived.conf.inhibit
│       ├── keepalived.conf.IPv6
│       ├── keepalived.conf.misc_check
│       ├── keepalived.conf.misc_check_arg
│       ├── keepalived.conf.quorum
│       ├── keepalived.conf.sample
│       ├── keepalived.conf.SMTP_CHECK
│       ├── keepalived.conf.SSL_GET
│       ├── keepalived.conf.status_code
│       ├── keepalived.conf.track_interface
│       ├── keepalived.conf.virtualhost
│       ├── keepalived.conf.virtual_server_group
│       ├── keepalived.conf.vrrp
│       ├── keepalived.conf.vrrp.localcheck
│       ├── keepalived.conf.vrrp.lvs_syncd
│       ├── keepalived.conf.vrrp.routes
│       ├── keepalived.conf.vrrp.rules
│       ├── keepalived.conf.vrrp.scripts
│       ├── keepalived.conf.vrrp.static_ipaddress
│       ├── keepalived.conf.vrrp.sync
│       ├── root.pem
│       └── sample.misccheck.smbcheck.sh
├── rc.d
│   └── init.d
│       └── keepalived
└── sysconfig
    └── keepalived

 

 分别对应系统目录(忽略samples目录):

/etc/keepalived/keepalived.conf
/etc/rc.d/init.d/keepalived
/etc/sysconfig/keepalived

 

将配置文件拷贝到系统对应的目录下

[root@keepalived-nginx1 ~]# mkdir /etc/keepalived
[root@keepalived-nginx1 ~]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
[root@keepalived-nginx1 ~]# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/keepalived
[root@keepalived-nginx1 ~]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived

 

 

[root@keepalived-nginx1 ~]# cd /etc/init.d/
[root@keepalived-nginx1 init.d]# chmod +x keepalived
[root@keepalived-nginx1 init.d]# service keepalived start
Starting keepalived: /bin/bash: keepalived: command not found
                                                           [FAILED]
[root@keepalived-nginx1 init.d]# ln -s /usr/local/keepalived/sbin/keepalived /usr/bin/
[root@keepalived-nginx1 init.d]# service keepalived start
Starting keepalived:                                       [  OK  ]

 

 

 http://www.mamicode.com/info-detail-1181951.html

http://blog.csdn.net/xyang81/article/details/52554398

 

posted @ 2017-10-20 15:32  Peter_Owen  阅读(5730)  评论(0编辑  收藏  举报