一:安装keepalived
(redis和redis-slave两台服务器都安装)
1. 安装操作系统的 ipvsadm
yum -y install ipvsadm
否则出现如下错误:
如果这个不安装 make 会有如下错误
make
make -C lib || exit 1;
make[1]: Entering directory `/httx/download/keepalived-1.2.10/lib'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/httx/download/keepalived-1.2.10/lib'
make -C keepalived
make[1]: Entering directory `/httx/download/keepalived-1.2.10/keepalived'
make[2]: Entering directory `/httx/download/keepalived-1.2.10/keepalived/core'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/httx/download/keepalived-1.2.10/keepalived/core'
make[2]: Entering directory `/httx/download/keepalived-1.2.10/keepalived/check'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/httx/download/keepalived-1.2.10/keepalived/check'
make[2]: Entering directory `/httx/download/keepalived-1.2.10/keepalived/vrrp'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/httx/download/keepalived-1.2.10/keepalived/vrrp'
make[2]: Entering directory `/httx/download/keepalived-1.2.10/keepalived/libipvs-2.6'
gcc -g -O2 -I/usr/src/linux/include -I/usr/src/linux/include -DLIBIPVS_DONTUSE_NL -Wall -Wunused -c -o libipvs.o libipvs.c
libipvs.c: In function ‘nlerr2syserr’:
libipvs.c:61: error: ‘NLE_BAD_SOCK’ undeclared (first use in this function)
libipvs.c:61: error: (Each undeclared identifier is reported only once
libipvs.c:61: error: for each function it appears in.)
libipvs.c:62: error: ‘NLE_EXIST’ undeclared (first use in this function)
libipvs.c:63: error: ‘NLE_NOADDR’ undeclared (first use in this function)
libipvs.c:64: error: ‘NLE_OBJ_NOTFOUND’ undeclared (first use in this function)
libipvs.c:65: error: ‘NLE_INTR’ undeclared (first use in this function)
libipvs.c:66: error: ‘NLE_AGAIN’ undeclared (first use in this function)
libipvs.c:67: error: ‘NLE_INVAL’ undeclared (first use in this function)
libipvs.c:68: error: ‘NLE_NOACCESS’ undeclared (first use in this function)
libipvs.c:69: error: ‘NLE_NOMEM’ undeclared (first use in this function)
libipvs.c:70: error: ‘NLE_AF_NOSUPPORT’ undeclared (first use in this function)
libipvs.c:71: error: ‘NLE_PROTO_MISMATCH’ undeclared (first use in this function)
libipvs.c:72: error: ‘NLE_OPNOTSUPP’ undeclared (first use in this function)
libipvs.c:73: error: ‘NLE_PERM’ undeclared (first use in this function)
libipvs.c:74: error: ‘NLE_BUSY’ undeclared (first use in this function)
libipvs.c:75: error: ‘NLE_RANGE’ undeclared (first use in this function)
libipvs.c:76: error: ‘NLE_NODEV’ undeclared (first use in this function)
make[2]: *** [libipvs.o] Error 1
make[2]: Leaving directory `/httx/download/keepalived-1.2.10/keepalived/libipvs-2.6'
make[1]: *** [all] Error 1
make[1]: Leaving directory `/httx/download/keepalived-1.2.10/keepalived'
make: *** [all] Error 2
1.wget http://www.keepalived.org/software/keepalived-1.2.10.tar.gz
2.安装操作系统组件 openssl-devel
yum -y install openssl-devel
否则出现如下错误:
configure: error:
!!! OpenSSL is not properly installed on your system. !!!
!!! Can not include OpenSSL headers files.
2.安装 tar zxvf keepalived-1.2.10.tar.gz
cd keepalived-1.2.10
3. ./configure --prefix=/httx/run/keepalived
4. yum -y install ipvsadm
如果这个不安装 make 会有如下错误
make
make -C lib || exit 1;
make[1]: Entering directory `/httx/download/keepalived-1.2.10/lib'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/httx/download/keepalived-1.2.10/lib'
make -C keepalived
make[1]: Entering directory `/httx/download/keepalived-1.2.10/keepalived'
make[2]: Entering directory `/httx/download/keepalived-1.2.10/keepalived/core'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/httx/download/keepalived-1.2.10/keepalived/core'
make[2]: Entering directory `/httx/download/keepalived-1.2.10/keepalived/check'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/httx/download/keepalived-1.2.10/keepalived/check'
make[2]: Entering directory `/httx/download/keepalived-1.2.10/keepalived/vrrp'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/httx/download/keepalived-1.2.10/keepalived/vrrp'
make[2]: Entering directory `/httx/download/keepalived-1.2.10/keepalived/libipvs-2.6'
gcc -g -O2 -I/usr/src/linux/include -I/usr/src/linux/include -DLIBIPVS_DONTUSE_NL -Wall -Wunused -c -o libipvs.o libipvs.c
libipvs.c: In function ‘nlerr2syserr’:
libipvs.c:61: error: ‘NLE_BAD_SOCK’ undeclared (first use in this function)
libipvs.c:61: error: (Each undeclared identifier is reported only once
libipvs.c:61: error: for each function it appears in.)
libipvs.c:62: error: ‘NLE_EXIST’ undeclared (first use in this function)
libipvs.c:63: error: ‘NLE_NOADDR’ undeclared (first use in this function)
libipvs.c:64: error: ‘NLE_OBJ_NOTFOUND’ undeclared (first use in this function)
libipvs.c:65: error: ‘NLE_INTR’ undeclared (first use in this function)
libipvs.c:66: error: ‘NLE_AGAIN’ undeclared (first use in this function)
libipvs.c:67: error: ‘NLE_INVAL’ undeclared (first use in this function)
libipvs.c:68: error: ‘NLE_NOACCESS’ undeclared (first use in this function)
libipvs.c:69: error: ‘NLE_NOMEM’ undeclared (first use in this function)
libipvs.c:70: error: ‘NLE_AF_NOSUPPORT’ undeclared (first use in this function)
libipvs.c:71: error: ‘NLE_PROTO_MISMATCH’ undeclared (first use in this function)
libipvs.c:72: error: ‘NLE_OPNOTSUPP’ undeclared (first use in this function)
libipvs.c:73: error: ‘NLE_PERM’ undeclared (first use in this function)
libipvs.c:74: error: ‘NLE_BUSY’ undeclared (first use in this function)
libipvs.c:75: error: ‘NLE_RANGE’ undeclared (first use in this function)
libipvs.c:76: error: ‘NLE_NODEV’ undeclared (first use in this function)
make[2]: *** [libipvs.o] Error 1
make[2]: Leaving directory `/httx/download/keepalived-1.2.10/keepalived/libipvs-2.6'
make[1]: *** [all] Error 1
make[1]: Leaving directory `/httx/download/keepalived-1.2.10/keepalived'
make: *** [all] Error 2
同时Slave上的日志显示:
[iyunv@redis-slave scripts]# tail /var/log/keepalived-redis-state.log
[master]
Thu Nov 15 12:06:04 CST 2012
Being master....
Run SLAVEOF cmd ...
OK
Run SLAVEOF NO ONE cmd ...
OK
然后我们可以发现,Slave已经接管服务,并且担任Master的角色了。
./redis-cli -h 192.168.1.237 info
./redis-cli -h 192.168.1.236 info
role:master