测试环境拓扑

LVS+KeepAlived搭配演示_第1张图片

LVS+Keepalived前端调度

Master

系统版本:CentOS release 5.9 (Final)

内核版本:2.6.18-348.3.1.el5

安装配置

1.安装ipvsadm组件

#yum install –y ipvsadm

2.安装编译环境:

#yuminstall -y kernel-devel gcc openssl-devel

3.解压、编译、安装

# tar -zxvf keepalived-1.2.7.tar.gz

#cd keepalived-1.2.7

#./configure--sysconf=/etc

#make && makeinstall

4.启动服务

#ln -s/usr/local/sbin/keepalived /sbin/

#cp/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak

#/etc/init.d/keepalivedstart

#ln -s/etc/init.d/keepalived /etc/rc.d/rc3.d/S99keepalived

#ln -s/etc/init.d/keepalived /etc/rc.d/rc5.d/S99keepalived

5.配置

# vim/etc/keepalived/keepalived.conf

编辑如下:

vrrp_instance VI_1 {

state MASTER

interface eth0

virtual_router_id 51

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.12.100

}

}


virtual_server192.168.12.100 80 {

delay_loop 6

lb_algo rr

lb_kind DR

nat_mask 255.255.255.0

persistence_timeout 50

protocol TCP


real_server 192.168.12.220 80 {

weight 1

connect_timeout 3

nb_get_retry 3

connect_port 80

delay_before_retry 3

}


real_server 192.168.12.221 80 {

weight 2

connect_timeout 3

nb_get_retry 3

connect_port 80

delay_before_retry 3

}

}

6.重启服务

#service keepalivedrestart

7.查看

#ipvsadm –L –n

结果如图:

LVS+KeepAlived搭配演示_第2张图片

Backup

系统版本:CentOS release 5.9 (Final)

内核版本:2.6.18-348.3.1.el5

安装配置

1.安装ipvsadm组件(Version: 1.24Release:13.el5)

#yum install –y ipvsadm

2.安装编译环境:

#yum install -y kernel-devel gcc openssl-devel

3.解压、编译、安装

# tar -zxvf keepalived-1.2.7.tar.gz

#cd keepalived-1.2.7

#./configure--sysconf=/etc

#make && makeinstall

4.启动服务

#ln -s /usr/local/sbin/keepalived /sbin/

#cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak

#/etc/init.d/keepalived start

#ln -s /etc/init.d/keepalived /etc/rc.d/rc3.d/S99keepalived

#ln -s /etc/init.d/keepalived /etc/rc.d/rc5.d/S99keepalived

5.配置

# vim /etc/keepalived/keepalived.conf

编辑如下:

vrrp_instance VI_1 {

state BACKUP

interface eth0

virtual_router_id 51

priority 80

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.12.100

}

}


virtual_server192.168.12.100 80 {

delay_loop 6

lb_algo rr

lb_kind DR

nat_mask 255.255.255.0

persistence_timeout 50

protocol TCP


real_server 192.168.12.220 80 {

weight 1

connect_timeout 3

nb_get_retry 3

connect_port 80

delay_before_retry 3

}


real_server 192.168.12.221 80 {

weight 2

connect_timeout 3

nb_get_retry 3

connect_port 80

delay_before_retry 3

}

}

6.重启服务

#service keepalived restart

7.查看

#ipvsadm –L –n

LVS+KeepAlived搭配演示_第3张图片

RealServer后端服务器

RealServer1

系统版本:CentOS release 5.9 (Final)

内核版本:2.6.18-348.3.1.el5

安装配置

1.安装PHP (Version : 5.1.6Release: 39.el5_8)、PHP-MySQL(Version: 5.1.6Release : 39.el5_8)、Apache(Version: 2.2.3Release: 76.el5.centos)

#yum install –y httpd php php-myql

2.开启服务

#service httpd start && chkconfig httpd on

3.创建测试网页

#vim /var/www/html/phpinfo.php

Phpinfo();

?>

4.本地测试

#firefox http://localhost/phpinfo.php


5.编写启动脚本realserver.sh

#!/bin/bash

VIP=192.168.12.100

./etc/rc.d/init.d/functions

case"$1" in

start)

ifconfig lo:0 $VIP netmask255.255.255.255 broadcast $VIP

/sbin/route add -host $VIP dev lo:0

echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore#不回应arp请求

echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce#使用Director Mac回应

echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

sysctl -p >/dev/null 2>&1

echo "realserver start OK!"

;;

stop)

ifconfig lo:0 down

/sbin/route del $VIP >/dev/null2>&1

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 "realserver stoped!"

;;

*)

echo "Usage: $0 {start|stop}"

exit 1

esac

exit 0

6.将脚本放入启动项,保证每次开机启动。

RealServer2

系统版本:CentOS release 5.9 (Final)

内核版本:2.6.18-348.3.1.el5

安装配置

1.安装PHP (Version : 5.1.6Release: 39.el5_8)、PHP-MySQL(Version: 5.1.6Release : 39.el5_8)、Apache(Version: 2.2.3Release: 76.el5.centos)

#yum install –y httpdphp php-myql

2.开启服务

#service httpd start && chkconfig httpd on

3.创建测试网页

#vim/var/www/html/phpinfo.php

Phpinfo();

?>

4.本地测试

#firefox http://localhost/phpinfo.php


5.编写启动脚本realserver.sh

#!/bin/bash

VIP=192.168.12.100

./etc/rc.d/init.d/functions

case"$1" in

start)

ifconfig lo:0 $VIP netmask255.255.255.255 broadcast $VIP

/sbin/route add -host $VIP dev lo:0

echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore#不回应arp请求

echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce#使用Director Mac回应

echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore

echo "2">/proc/sys/net/ipv4/conf/all/arp_announce

sysctl -p >/dev/null 2>&1

echo "realserver start OK!"

;;

stop)

ifconfig lo:0 down

/sbin/route del $VIP >/dev/null2>&1

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 "realserver stoped!"

;;

*)

echo "Usage: $0 {start|stop}"

exit 1

esac

exit 0

6.将脚本放入启动项,保证每次开机启动。


Data数据存储

iSCSI

系统版本:CentOS release 5.9 (Final)

内核版本:2.6.18-348.3.1.el5

安装配置

1.安装scsi-target-utils(Version : 1.0.14Release : 2.el5)

#yum install –y scsi-target-utils

2.创建磁盘

# lvcreate -L 5G -n iscsi01 /dev/VolGroup00

3.修改配置文件

#cp targets.conf targets.conf.bak

#vim targets.conf

backing-store /dev/VolGroup00/iscsi01# Becomes LUN 1

#backing-store /dev/LVM/somedevice2 #Becomes LUN 2

#backing-store /dev/LVM/somedevice3 #Becomes LUN 3

write-cache off

vendor_id MyCompany Inc.

4.开启服务

#service tgtd restart && chkconfig tgtd on

5.查看状态

#tgt-adm –show

6.Realserver1连接iSCSI

# iscsiadm -m discovery-t sendtargets -p 192.168.12.240:3260

# iscsiadm -m node -Tiqn.2013-03.com.mlloo:server.iscsi01 –login

查看磁盘如图:


7.分区格式化

#fdisl /dev/sdb -->n-->p—>w

#mkfs.ext3 /dev/sdb1

8.自动挂载

#vim /etc/fstab

/dev/sdb1 /var/www/html ext3 defaults 0 0

9.重启服务

#service httpd restart

10.Realserver2连接iSCSI

# iscsiadm -m discovery -t sendtargets -p 192.168.12.240:3260

# iscsiadm -m node -T iqn.2013-03.com.mlloo:server.iscsi01 –login

11.自动挂载

#vim /etc/fstab

/dev/sdb1/var/www/htmlext3defaults0 0

12.重启服务

#service httpd restart


MySQL

系统版本:CentOS release 5.9 (Final)

内核版本:2.6.18-348.3.1.el5

安装配置

1.安装MySQL(Version: 5.0.95Release: 5.el5_9)

#yum install –y mysql mysql-server

2.开启服务

#service mysqld restart && chkconfig mysqld on

3.设置root帐号密码

#mysqladm –u root password *******

4.配置同步

# cp /etc/my.cnf/etc/my.cnf.bak

# vim /etc/my.cnf

server-id=1

log-bin=mysql-bin

5.添加同步帐号

#useradd –r mysqlsyn

#passwd mysqlsyn

#mysql –u root –p

> grant replicationslave on *.* to 'mysqlsyn'@'192.168.12.231' identified by '********';

6.重启服务

#service mysqld restart

MySQL

系统版本:CentOS release 5.9 (Final)

内核版本:2.6.18-348.3.1.el5

安装配置

1.安装MySQL(Version: 5.0.95Release: 5.el5_9)

#yum install –y mysql mysql-server

2.开启服务

#service mysqld restart && chkconfig mysqld on

3.设置root帐号密码

#mysqladm –u root password *******

4.配置同步

# cp /etc/my.cnf/etc/my.cnf.bak

# vim /etc/my.cnf

server-id=2

master-host=192.168.12.230

master-user=mysqlsyn

master-password=××××××

master-port=3306

master-connect-retry=60

5.重启服务

#service mysqld restart

6.查看同步信息

#mysql –u root –p

mysql>start slave;
mysql>show slave status\G;

结果如图:

LVS+KeepAlived搭配演示_第4张图片