系統環境
作業系統: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
[[email protected] 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,執行成功後,會看到如下内容:
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指令
[[email protected] keepalived-1.2.13]# make; make install
[[email protected] keepalived-1.2.13]# whereis keepalived
keepalived: /usr/local/sbin/keepalived /usr/local/etc/keepalived
keepalived 安裝在/usr/local/etc/keepalived下了
(3)檢視安裝内容
進入/usr/local/etc目錄,檢視檔案件内容:
[[email protected] /]# cd /usr/local/etc/
[[email protected] 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配置:
[[email protected] keepalived]# pwd
/usr/local/etc/keepalived
[[email protected] 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">[[email protected] /]# mkdir /etc/keepalived
[[email protected] /]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
[[email protected] /]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/
[[email protected] /]# cp /usr/local/etc/sysconfig/keepalived /etc/sys
[[email protected] /]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
[[email protected] 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啟動服務,通過手動方式建立:
[[email protected] rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc2.d/S80keepalived
[[email protected] rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc2.d/K90keepalived
[root[email protected] rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc3.d/S80keepalived
[[email protected] rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc3.d/K90keepalived
[[email protected] rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc4.d/S80keepalived
[[email protected] rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc4.d/K90keepalived
[[email protected] rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc5.d/S80keepalived
[[email protected] rc2.d]# ln -sf /etc/rc.d/init.d/keepalived /etc/rc5.d/K90keepalived