/ 中存储网

使用ha和lvs部署负载均衡环境

2014-04-07 10:22:01 来源:kejihao
公司发展的需求,先在本地做测试,把测试步骤贴出来。

------------------------------------------------

环境说明:

VirtualBOX 

ubuntu-real1  192.168.1.201

ubuntu-real2  192.168.1.202

Centos        192.168.1.202

VIP           192.168.1.200

-----------------------------------------------------

# 安装Ubuntu 10 Server  Centos 

# 克隆Ubuntu     ubuntu-real1   ---ubuntu-real2

# 克隆完后 会出现网络无法启动

sudo mv /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules.old

Reboot

#设置静态IP

vim /etc/network/interfaces

auto eth0

iface eth0 inet static    

address 192.168.1.201

netmask 255.255.255.0

gateway 192.168.1.1

/etc/init.d/networking restart

#结束个用户 

pkill -9 -t pts/0

# 更换源  (不一定需要操作 )

apt-key adv --keyserver keyserver.Ubuntu.com --recv-keys C300EE8C

echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main" >> /etc/apt/sources.list

apt-get update

# 源安装 

apt-get install  ipvsadm  keepalived 

cd /etc/keepalived

vim  keepalived.conf

---------------Master配置----------------

global_defs {

   notification_email {

[email protected]

   }

notification_email_from [email protected]    

   smtp_server 127.0.0.1

   smtp_connect_timeout 30

   router_id LVS_DEVEL

}

vrrp_instance VI_1 {

state MASTER    # keepalived2 机器为 BAUCK

interface eth0   

virtual_router_id 50   #VRID标示

priority 102        # 优先级

advert_int 1        #检测间隔

authentication {

auth_type PASS

auth_pass 1987

}

virtual_ipaddress {

192.168.1.200

}

}

virtual_server 192.168.1.200 80 {

delay_loop 10   #每10秒检测次RealServer

lb_algo rr      #轮训 rr|wrr|lc|lblc|sh|dh

lb_kind DR      ##lvs使用Direct Route NAT|DR|TUN

persistence_timeout 50   # 默认50秒钟都访问同一台机器(会话保持)

protocol TCP

  real_server 192.168.1.201 80 {

weight 1

TCP_CHECK {

connect_port 80

connect_timeout 30

}

}

real_server 192.168.1.202 80 {

weight 1

TCP_CHECK {

connect_port 80

connect_timeout 30

}

}

real_server 192.168.1.203 80 {

weight 1

TCP_CHECK {

connect_port 80

connect_timeout 30

}

}

}

-----------------------------------------------------

/etc/init.d/keepalived start 

# 查看状态

ip a

---------------BACKUP配置----------------

global_defs {

   notification_email {

[email protected]

   }

notification_email_from [email protected]    

   smtp_server 127.0.0.1

   smtp_connect_timeout 30

   router_id LVS_DEVEL

}

vrrp_instance VI_1 {

state BACKUP     # BACKUP

interface eth0   

virtual_router_id 50   #VRID标示

priority 101        # 优先级

advert_int 1        #检测间隔

authentication {

auth_type PASS

auth_pass 1987

}

virtual_ipaddress {

192.168.1.200

}

}

virtual_server 192.168.1.200 80 {

delay_loop 10   #每10秒检测次RealServer

lb_algo rr      #轮训 rr|wrr|lc|lblc|sh|dh

lb_kind DR      ##lvs使用Direct Route NAT|DR|TUN

persistence_timeout 50   # 默认50秒钟都访问同一台机器(会话保持)

protocol TCP

  real_server 192.168.1.201 80 {

weight 1

TCP_CHECK {

connect_port 80

connect_timeout 30

}

}

real_server 192.168.1.202 80 {

weight 1

TCP_CHECK {

connect_port 80

connect_timeout 30

}

}

real_server 192.168.1.203 80 {

weight 1

TCP_CHECK {

connect_port 80

connect_timeout 30

}

}

}