阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

LVS+KeepAlived搭配演示

100次阅读
没有评论

共计 8198 个字符,预计需要花费 21 分钟才能阅读完成。

测试环境拓扑

LVS+KeepAlived 搭配演示

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 搭配演示

Keepalived 的详细介绍:请点这里
Keepalived 的下载地址:请点这里

推荐阅读:

CentOS 6.3 下 Haproxy+Keepalived+Apache 配置笔记 http://www.linuxidc.com/Linux/2013-06/85598.htm

Haproxy + KeepAlived 实现 WEB 群集 on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm

Keepalived+Haproxy 配置高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/56748.htm

Haproxy+Keepalived 构建高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/55880.htm

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 搭配演示

测试环境拓扑

LVS+KeepAlived 搭配演示

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 搭配演示

Keepalived 的详细介绍:请点这里
Keepalived 的下载地址:请点这里

推荐阅读:

CentOS 6.3 下 Haproxy+Keepalived+Apache 配置笔记 http://www.linuxidc.com/Linux/2013-06/85598.htm

Haproxy + KeepAlived 实现 WEB 群集 on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm

Keepalived+Haproxy 配置高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/56748.htm

Haproxy+Keepalived 构建高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/55880.htm

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
<?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
<?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
<target iqn.2013-03.com.mlloo:server.iscsi01>
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.
</target>
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 搭配演示

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计8198字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中