您的位置:首页 > 运维架构 > 网站架构

[跟我学中小企业架构部署]之二:负载均衡部署

2011-10-11 09:19 211 查看
LB1 LB2 部署

——————————-

所需要软件:

ipvsadm-1.24.tar.gz

keepalived-1.1.18.tar.gz

mkdir –p /home/elain
cd /home/elain/

rz 上传软件
注:下面所有服务器配置,安装的源码包都用此路径,下文不再强调。
此次LB的VIP,设为:10.0.0.80
ipvsadm-1.24安装

lsmod |grep ip_vs #检查是否存在ip_vs模块
uname –r #查看内核版本
tar zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
ln -s /usr/src/kernels/2.6.18-164.el5-x86_64/ /usr/src/linux
make
make install
cd ..
find / -name ipvsadm #查看安装后路径,可选
/sbin/ipvsadm  #加载ip_vs模块
lsmod |grep ip_vs





若看到上面信息,则ip_vs模块加载成功

——————————————

keepalived-1.1.18安装

————————–

tar zxvf keepalived-1.1.18.tar.gz
cd keepalived-1.1.18
./configure
make
make install
cd ..

cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/   #设置为service方式启动
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/
/etc/init.d/keepalived start   #启动keepalived
echo “/etc/init.d/keepalived start” >>/etc/rc.local  #添加为开机自启动
sed -i 's#net.ipv4.ip_forward = 0#net.ipv4.ip_forward = 1#' /etc/sysctl.conf  #开启内核转发功能
sysctl –p    #查看是否开启内核转发

注:以上操作在master backup两服务器上相同
Keepalived 配置
————————————

mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.ori  #备份原始配置文件
vi /etc/keepalived/keepalived.conf   #分别在LB1,LB2上建立配置文件

#!/bin/bash
Configuration File for keepalived
global_defs {
notification_email {
elain2012@hotmail.com     #填写自己的邮箱出现故障接收报警邮件用
}
notification_email_from Alexandre.Cassen@firewall.loc
#smtp_server 192.168.200.1
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_01 #备份服务器改为LVS_02
}

vrrp_instance VI_1 {
state MASTER #备份服务器上MASTER为BACKUP

interface eth0
lvs_sync_daemon_inteface eth1
virtual_router_id 81
priority 100 #备份服务上优先级要低于100,如改为90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}

virtual_ipaddress {
#192.168.200.16
10.0.0.80   #这里填写VIP地址,也可添加多个VIP
}
}

virtual_server 10.0.0.80 80 {   #这里填写VIP地址
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP

real_server 10.0.0.83 80 { #这里是LAMP服务器对外的IP
weight 1
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}

real_server 10.0.0.84 80 { #这里是LEMP对外的IP
weight 1
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}


注:以上keepalived.conf文件在LB1,LB2上都需建立;红色标记处,是在LB2使用该配置文件需修改的地方

/etc/init.d/keepalived restart

配置完毕!





使用 ip add 命令查看LB1的IP,若出现上图红圈标记的IP,即配置成功!

在LB2上还需配置LAMP测试环境:

此处参考下面要配置的LAMP环境即可!

转载请注明: 转载自http://www.elain.org

本文链接地址:[跟我学中小企业架构部署]之二:负载均衡部署
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息