发布时间:2014-09-05 17:19:05作者:知识屋
http://antsw.blog.51cto.com/936097/214975 本文出自 “山捻子” 博客
Node1: 192.168.1.253
Node2: 192.168.1.254
VIP: 192.168.1.250
环境 centos5.2(我这里是用两台机实现的)
1、安装ipvsadm
yum -y install ipvsadm
2、安装keepalived
[root@node1 ~]# wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
[root@node1 ~]# tar zxvf keepalived-1.1.15.tar.gz
[root@node1 ~]# cd keepalived-1.1.15
[root@node1 keepalived-1.1.15]# ./configure --prefix=/ --mandir=/usr/local/share/man/ --with-kernel-dir=/usr/src/kernels/2.6.18-92.el5-i686/
configure后会输入这结果为正确
Keepalived configuration
------------------------
Keepalived version : 1.1.15
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : Yes #支持lvs
IPVS sync daemon support : Yes
Use VRRP Framework : Yes
Use LinkWatch : No
Use Debug flags : No
[root@node1 keepalived-1.1.15]# make && make install
到此,lvs+keepalived安装完成。但是还不能使用lvs功能,接下来以dr模式配置lvs+keepalived
3、[root@node1 ~]# cd /etc/keepalived/
[root@node1 keepalived]# vim keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
shanswei@gmail.com
}
notification_email_from shanswei@gmail.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER ##主lvs设置成master
interface eth0
virtual_router_id 51
priority 102 ##从lvs设置成 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.250 ## 如多个vip,继续换行填写。
}
}
virtual_server 192.168.1.250 80 {
delay_loop 6
lb_algo wlc
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.1.253 80 {
weight 3
TCP_CHECK {
connect_port 80
connect_timeout 30
}
}
real_server 192.168.1.254 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 30
}
}
好了,keepalived配置完成了。
启动keepalived
[root@node1 ~]# /etc/init.d/keepalived start
如果要随系统启动,执行chkconfig --add keepalived
chkconfig keepalived on
4、接着配置真实服务器,这里通过脚本来实现吧(这个脚本只在WEB机上执行,我现在是用两台机。服务器既充当lvs、也充当web机)
[root@node1 keepalived]# vim realserver
#!/bin/bash
#description : start realserver
VIP=192.168.1.250
/etc/rc.d/init.d/functions
case "$1" in
start)
echo " start LVS of REALServer"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig lo:0 down
echo "close LVS Directorserver"
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
[root@node1 keepalived]# chmod +x realserver
[root@node1 keepalived]# ./realserver start
5、启动keepalived (附启动日志)
[root@node1 ~]# /etc/init.d/keepalived start (主LVS)
Oct 15 13:59:36 vmtest Keepalived: Starting Keepalived v1.1.15 (10/15,2009)
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Using MII-BMSR NIC polling thread...
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Netlink reflector reports IP 192.168.1.253 added
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Netlink reflector reports IP 10.0.0.253 added
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Registering Kernel netlink reflector
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Registering Kernel netlink command channel
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Opening file /etc/keepalived/keepalived.conf.
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Configuration is using : 11891 Bytes
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Activating healtchecker for service [192.168.1.253:80]
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Activating healtchecker for service [192.168.1.254:80]
Oct 15 13:59:36 vmtest Keepalived: Starting Healthcheck child process, pid=28419
Oct 15 13:59:36 vmtest Keepalived_vrrp: Using MII-BMSR NIC polling thread...
Oct 15 13:59:36 vmtest Keepalived_vrrp: Netlink reflector reports IP 192.168.1.253 added
Oct 15 13:59:36 vmtest Keepalived: Starting VRRP child process, pid=28420
Oct 15 13:59:36 vmtest Keepalived_vrrp: Netlink reflector reports IP 10.0.0.253 added
Oct 15 13:59:36 vmtest Keepalived_vrrp: Registering Kernel netlink reflector
Oct 15 13:59:36 vmtest Keepalived_vrrp: Registering Kernel netlink command channel
Oct 15 13:59:36 vmtest Keepalived_vrrp: Registering gratutious ARP shared channel
Oct 15 13:59:36 vmtest Keepalived_vrrp: Opening file /etc/keepalived/keepalived.conf.
Oct 15 13:59:36 vmtest Keepalived_vrrp: Configuration is using : 36278 Bytes
Oct 15 13:59:36 vmtest Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(8,9)]
Oct 15 13:59:37 vmtest Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Oct 15 13:59:38 vmtest Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Oct 15 13:59:38 vmtest Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Oct 15 13:59:38 vmtest Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.250
Oct 15 13:59:38 vmtest Keepalived_healthcheckers: Netl
linux一键安装web环境全攻略 在linux系统中怎么一键安装web环境方法
Linux网络基本网络配置方法介绍 如何配置Linux系统的网络方法
Linux下DNS服务器搭建详解 Linux下搭建DNS服务器和配置文件
对Linux进行详细的性能监控的方法 Linux 系统性能监控命令详解
linux系统root密码忘了怎么办 linux忘记root密码后找回密码的方法
Linux基本命令有哪些 Linux系统常用操作命令有哪些
Linux必学的网络操作命令 linux网络操作相关命令汇总
linux系统从入侵到提权的详细过程 linux入侵提权服务器方法技巧
linux系统怎么用命令切换用户登录 Linux切换用户的命令是什么
在linux中添加普通新用户登录 如何在Linux中添加一个新的用户
2012-07-10
CentOS 6.3安装(详细图解教程)
Linux怎么查看网卡驱动?Linux下查看网卡的驱动程序
centos修改主机名命令
Ubuntu或UbuntuKyKin14.04Unity桌面风格与Gnome桌面风格的切换
FEDORA 17中设置TIGERVNC远程访问
StartOS 5.0相关介绍,新型的Linux系统!
解决vSphere Client登录linux版vCenter失败
LINUX最新提权 Exploits Linux Kernel <= 2.6.37
nginx在网站中的7层转发功能