系统环境
操作系统:CentOS 6.5 Kernel 2.6.32-431 el6.x86_64
Keepalived版本:Keepalived for Linux - Version 1.2.13
注意:Version 1.2.13 增加了SO_MARK的编译选项,这个选项只支持系统内核2.6.25以上,如果系统内核是2.6.25以下,则换version 1.2.12版本;
Keepalived安装
下载keepalived :wget http://www.keepalived.org/software/keepalived-1.2.13.tar.gz
解压keepalived :tar -xvf keepalived-1.2.13.tar.gz
1、进行安装:
(1)脚本配置./configure
[root@centos-server-01 keepalived-1.2.13]# ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for a BSD-compatible install... /usr/bin/install -c
checking for strip... strip
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking syslog.h usability... yes
checking syslog.h presence... yes
checking for syslog.h... yes
checking for unistd.h... (cached) yes
checking sys/ioctl.h usability... yes
checking sys/ioctl.h presence... yes
checking for sys/ioctl.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking openssl/ssl.h usability... no
checking openssl/ssl.h presence... no
checking for openssl/ssl.h... no
configure: error:
!!! OpenSSL is not properly installed on your system. !!!
!!! Can not include OpenSSL headers files. !!!
注:OpenSSL没有安装,需要安装libssl
yum install openssl
yum install openssl-devel
configure: creating ./config.status
config.status: creating Makefile
config.status: creating genhash/Makefile
config.status: creating keepalived/core/Makefile
config.status: creating lib/config.h
config.status: creating keepalived.spec
config.status: creating keepalived/Makefile
config.status: creating lib/Makefile
config.status: creating keepalived/vrrp/Makefile
config.status: creating keepalived/check/Makefile
config.status: creating keepalived/libipvs-2.6/Makefile
Keepalived configuration
------------------------
Keepalived version : 1.2.13
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lssl -lcrypto -lcrypt
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
IPVS use libnl : No
fwmark socket support : Yes
Use VRRP Framework : Yes
Use VRRP VMAC : Yes
SNMP support : No
SHA1 support : No
Use Debug flags : No
(2)编译安装,./configure执行成功后,基本上编译安装就不会有问题了,执行make和make install命令
[root@centos-server-01 keepalived-1.2.13]# make; make install
[root@centos-server-01 keepalived-1.2.13]# whereis keepalived
keepalived: /usr/local/sbin/keepalived /usr/local/etc/keepalived
keepalived 安装在/usr/local/etc/keepalived下了
(3)查看安装内容
进入/usr/local/etc目录,查看文件件内容:
[root@centos-server-01 /]# cd /usr/local/etc/
[root@centos-server-01 etc]# ll -a
总用量 20
drwxr-xr-x. 5 root root 4096 7月 19 16:48 .
drwxr-xr-x. 13 root root 4096 5月 24 08:56 ..
drwxr-xr-x. 3 root root 4096 7月 19 16:48 keepalived
drwxr-xr-x. 3 root root 4096 7月 19 16:48 rc.d
drwxr-xr-x. 2 root root 4096 7月 19 16:48 sysconfig
其中keepalived文件夹里是配置文件,rc.d中存放的是系统启动服务,sysconfig是keepalived的option配置:
[root@centos-server-01 keepalived]# pwd
/usr/local/etc/keepalived
[root@centos-server-01 keepalived]# ll -a
总用量 16
drwxr-xr-x. 3 root root 4096 7月 19 16:48 .
drwxr-xr-x. 5 root root 4096 7月 19 16:48 ..
-rw-r--r--. 1 root root 3562 7月 19 16:48 keepalived.conf
drwxr-xr-x. 2 root root 4096 7月 19 16:48 samples
/usr/local/etc/keepalived/samples文件夹是一些样例配置
-rw-r--r--. 1 root root 1745 7月 19 16:48 client.pem
-rw-r--r--. 1 root root 245 7月 19 16:48 dh1024.pem
-rw-r--r--. 1 root root 433 7月 19 16:48 keepalived.conf.fwmark
-rw-r--r--. 1 root root 684 7月 19 16:48 keepalived.conf.HTTP_GET.port
-rw-r--r--. 1 root root 746 7月 19 16:48 keepalived.conf.inhibit
-rw-r--r--. 1 root root 895 7月 19 16:48 keepalived.conf.IPv6
-rw-r--r--. 1 root root 550 7月 19 16:48 keepalived.conf.misc_check
-rw-r--r--. 1 root root 538 7月 19 16:48 keepalived.conf.misc_check_arg
-rw-r--r--. 1 root root 2467 7月 19 16:48 keepalived.conf.quorum
-rw-r--r--. 1 root root 919 7月 19 16:48 keepalived.conf.sample
-rw-r--r--. 1 root root 2760 7月 19 16:48 keepalived.conf.SMTP_CHECK
-rw-r--r--. 1 root root 1587 7月 19 16:48 keepalived.conf.SSL_GET
-rw-r--r--. 1 root root 842 7月 19 16:48 keepalived.conf.status_code
-rw-r--r--. 1 root root 735 7月 19 16:48 keepalived.conf.track_interface
-rw-r--r--. 1 root root 887 7月 19 16:48 keepalived.conf.virtualhost
-rw-r--r--. 1 root root 1087 7月 19 16:48 keepalived.conf.virtual_server_group
-rw-r--r--. 1 root root 1425 7月 19 16:48 keepalived.conf.vrrp
-rw-r--r--. 1 root root 3019 7月 19 16:48 keepalived.conf.vrrp.localcheck
-rw-r--r--. 1 root root 1083 7月 19 16:48 keepalived.conf.vrrp.lvs_syncd
-rw-r--r--. 1 root root 888 7月 19 16:48 keepalived.conf.vrrp.routes
-rw-r--r--. 1 root root 1146 7月 19 16:48 keepalived.conf.vrrp.scripts
-rw-r--r--. 1 root root 591 7月 19 16:48 keepalived.conf.vrrp.static_ipaddress
-rw-r--r--. 1 root root 1742 7月 19 16:48 keepalived.conf.vrrp.sync
-rw-r--r--. 1 root root 802 7月 19 16:48 root.pem
-rw-r--r--. 1 root root 323 7月 19 16:48 sample.misccheck.smbcheck.sh
Keepalived启动服务配置
修改配置文件路径、设置启动服务:
<pre name="code" class="plain">[root@centos-server-01 /]# mkdir /etc/keepalived
[root@centos-server-01 /]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
[root@centos-server-01 /]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/
[root@centos-server-01 /]# cp /usr/local/etc/sysconfig/keepalived /etc/sys
[root@centos-server-01 /]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
[root@centos-server-01 rc.d]# cp /usr/local/sbin/keepalived /usr/sbin/
修改/etc/init.d/keepalived文件,找到# chkconfig: - 21 79这一行,修改成 # chkconfig: 2345 80 90,是修改chkconfig运行级别
然后把keepalived加入到系统启动服务:
chkconfig --add keepalived
#查看是否成功加入开机启动
chkconfig --list keepalived
注意:如果keepalived 没有成功加入开机启动服务,查看/etc/rc2.d目录下不存在keepalived启动服务,通过手动方式创建:
[root@centos-server-01 rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc2.d/S80keepalived
[root@centos-server-01 rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc2.d/K90keepalived
[root@centos-server-01 rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc3.d/S80keepalived
[root@centos-server-01 rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc3.d/K90keepalived
[root@centos-server-01 rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc4.d/S80keepalived
[root@centos-server-01 rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc4.d/K90keepalived
[root@centos-server-01 rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc5.d/S80keepalived
[root@centos-server-01 rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc5.d/K90keepalived