lvs 实现负载均衡
linux virtual server
/var /www/html/rhel6.5
[root@server1 haproxy]
[yum]
name = yum
baseurl=http :// 172.25 .200 .250 /rhel6.5
gpgcheck=0
[HighAvailability]
name = HighAvailability
baseurl=http :// 172.25 .200 .250 /rhel6.5 /HighAvailability
gpgcheck=0
[LoadBalancer]
name = LoadBalancer
baseurl=http :// 172.25 .200 .250 /rhel6.5 /LoadBalancer
gpgcheck=0
[ResilientStorage]
name = ResilientStorage
baseurl=http :// 172.25 .200 .250 /rhel6.5 /ResilientStorage
gpgcheck=0
[ScalableFileSystem]
name = ScalableFileSystem
baseurl=http :// 172.25 .200 .250 /rhel6.5 /ScalableFileSystem
gpgcheck=0
HighAvailability HighAvailability 56
LoadBalancer LoadBalancer 4
ResilientStorage ResilientStorage 62
ScalableFileSystem ScalableFileSystem 7
yum yum 3 ,690
repolist : 3 ,819
yum install -y ipvsadm
ipvsadm -A -t 172.25.200.100:80 -s rr
ipvsadm -a -t 172.25.200.100:80 -r 172.25.200.2:80 -g
ipvsadm -a -t 172.25.200.100:80 -r 172.25.200.3:80 -g
ipvsadm -ln
/etc/init.d/ipvsadm save
/etc/init.d/ipvsadm stop
/etc/init.d/ipvsadm start
server1
ip addr add 172.25 .200 .100 /24 dev eth0
server*
ip addr add 172.25 .200 .100 /24 dev eth0
做vip掩饰,不对外宣布
yum install -y arptables_jf
arptables -A IN -d 172.25 .200 .100 -j DROP #对input进行拒绝
arptables -A OUT -s 172.25 .200 .100 -j mangle --mangle-ip-s 172.25 .200 .* #output伪装
/etc/init.d /arptables_jf save
curl 172.25 .200 .100
arp -an | grep 100 查看mac地址
arp -d 172.25 .200 .100 清空缓存
arp -a
ldirectord + lvs
yum install -y ldirectord-3.9 .5 -3.1 .x 86_64.rpm
rpm -ql ldirectord #查找配置文件
mv /usr/share/doc/ldirectord-3.9 .5 /ldirectord.cf /etc/ha.d /
#移动到这里的原因是/etc/init.d/ldirectord中配置文件指向为这里
vim ldirectord.cf
24
25 virtual=172.25.200.100:80
26 real=172.25.200.2:80 gate
27 real=172.25.200.3:80 gate
28 fallback=127.0.0.1:80 gate
29 service=http
30 scheduler=rr
31
32
33 protocol=tcp
34 checktype=negotiate
35 checkport=80
36 request="index.html"
37
38
/etc/init.d /ipvsadm stop
ipvsadm -L
/etc/init.d /ldirectord start
这个需要在server2和server3上新建vip,但是server1vip由ldirectord配置文件创建
keepalived + lvs
#keepalived 源码安装
tar zxf keepalived- 1.4 .0 . tar. gz
cd keepalived- 1.4 .0 /
yum install -y openssl-devel libnl3-devel ipset-devel iptables-devel libnfnetlink-devel
yum install -y libnfnetlink-devel - 1.0 .0 - 1. el6. x86_64. rpm
yum install -y libnl-devel
. /configure -- prefix= /usr/local /keepalived -- with -init = SYSV
make && make install
ln -s /usr/local /keepalived/etc/keepalived/ /etc/
ln -s /usr/local /keepalived/etc/sysconfig/keepalived /etc/sysconfig/
ln -s /usr/local /keepalived/etc/rc. d/init. d/keepalived /etc/init. d/
ln -s /usr/local /keepalived/sbin/keepalived /sbin/
chmod + x /etc/init. d/keepalived
[root@foundation1 day02]
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0 .0 .1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER /SLAVE 高可用另一台配置
interface eth0
virtual_router_id 200
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.25 .200.100 /24
}
}
virtual_server 172.25 .200.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
real_server 172.25 .200.2 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 172.25 .200.3 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}
virtual_server 172.25 .200.100 21 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 172.25 .200.2 21 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 172.25 .200.3 21 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}
yum install -y vsftpd httpd #两个服务进行测试
/var /www/html
/var /ftp