码迷,mamicode.com
首页 > 其他好文 > 详细

linxu集群架设——LVS

时间:2014-06-06 15:31:00      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:des   c   a   http   tar   ext   

LVS框架:

三层结构:
     网络      (LVS--linux)      (WWW , FTP ,STML)     (GFS,OCFS2)
用户 -- >   Director Server  ---> Real Server1
      Real Server2    --> 集群文件系统
      Real Server3
软件:
 浏览器        ipvsadm              httpd
                 ↑
   heartbeat(ldirectord) (脚本:lvsrc)
   keepalived

 

Director Server :
LVS : Linux Virtual Server 虚拟服务器,章文嵩,高吞吐量,高稳定。

IPVS:IP负载均衡核心软件,虚拟一个IP,维持一个Real Server路由表。
 转发请求到Real Server,Real Server如何返回数据
 配置方法:1.ipvsadm命令
     2:第三方插件或工具如ldirectord
     3.:Redhat界面工具piranha

相关技术:
1、IP负载均衡技术:
VS/NAT :Virtual Server via Network Address Translation---网络地址转换
        每次必须经过DR服务器。
VS/TUN :Virtual Server via IP Tunneling--- IP隧道
VS/DR:Virtual Server via Direct Routing--直接路由

2、负载调度算法
轮叫调度:rr(Tound Robin):1:1调度
加权轮叫调度:wrr(Werghted Round Robin)
最少连接调度:Least Connections
加权最少连接调度:Weighted Least Connections


3.高可用
heartbeat主要模块:
  heartbeat负责检测director server节点是否存在 ,一般通过使用广播ping对方
       配置文件:/etc/ha.d/ha.cf
       资源文件:/etc/ha.d/haresource
       认证文件:/etc/ha.d/authkeys
  ldirectord  1.其配置文件能配置ipvs,并调用ipvsadm实现负载均衡
                2.检测real server看是否存在,维护ipvsadm的路由表。
      配置文件:/etc/ha.d/ldirectord.cf
      日志文件:/var/log/ldirectord.log
  stonith:(shut the other node in the head)不能检测到心跳时,通过串口连接的对方的stonith设备关断对方电源防止脑裂。(双方的服务都在开启同时使用资源)

 

keepalived
piranha:

 

----部署流程---

*************************安装IPVS**************************

1.modprobe -l |grep ipvs  查看内核是否支持LVS的IPVS模块
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_dh.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_ftp.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_lblc.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_lblcr.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_lc.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_nq.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_rr.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_sed.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_sh.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_wlc.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_wrr.ko
2.rpm -ivh ipvsadm-1.24-13.el5.x86_64.rpm
也可以通过源码安装。


3.使用ipvsadm命令查看当前状态:
ipvsadm

 

*************************heartbeart**************************

director server安装heeatbeat

rpm包:
下载地址:pkgs.org/centos-5/centos-extras-x86_64/
heartbeat-2.1.3-3.el5.centos.x86_64.rpm
heartbeat-devel-2.1.3-3.el5.centos.x86_64.rpm
heartbeat-gui-2.1.3-3.el5.centos.x86_64.rpm
heartbeat-ldirectord-2.1.3-3.el5.centos.x86_64.rpm
heartbeat-pils-2.1.3-3.el5.centos.x86_64.rpm
heartbeat-stonith-2.1.3-3.el5.centos.x86_64.rpm
依赖包:
下载地址:rpm.pbone.net
 

 

配置heartbeat:

vi /etc/ha.d/ldirectord.cf
# Global Directives
checktimeout=20
checkinterval=10
#fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
#logfile="local0"
#emailalert="admin@x.y.z"
#emailalertfreq=3600
#emailalertstatus=all
quiescent=no

# Sample for an http virtual service
virtual=192.168.12.200:80
 real=192.168.12.132:80 gate
 real=192.168.12.133:80 gate
  fallback=127.0.0.1:80 gate
 service=http
 request="index.html"
 receive="Test Page"
 scheduler=rr
 #persistent=600
 #netmask=255.255.255.255
 protocol=tcp
   checktype=negotiate
   checkport=80
  virtualhost=www.liaoyi.net


vi /etc/ha.d/ha.cf
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
bcast eth1  # Linux
auto_failback on
node DR1
node DR2
ping 192.168.12.1
respawn hacluster /usr/lib/heartbeat/ipfail


vi /etc/ha.d/haresources

DR1 IPaddr::192.168.12.200/24/eth0 ldirectord

vi /etc/ha.d/authkeys
auth 1
1 crc
#2 sha1 HI!
#3 md5 Hello!

 

---Real Server配置---

增加虚拟ip脚本:

#!/bin/bash
#description : Start Real Server
VIP=192.168.12.200
. /etc/rc.d/init.d/functions
case "$1" in
    start)
    echo "Start LVS of Real Server"
    /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
    echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
    echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce   
    echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
    echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
    ;;
    stop)
    /sbin/ifconfig lo:0 down
    echo "Close LVS Director Server"
    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 "Usage: $0 {start|stop}"
    exit 1
esac

 

*************************keepalived***************************
director server上安装keepalived
rpm -ivh e2fsprogs-devel-1.39-33.el5.x86_64.rpm
rpm -ivh keyutils-libs-devel-1.2-1.el5.x86_64.rpm
rpm -ivh libsepol-devel-1.15.2-3.el5.x86_64.rpm
rpm -ivh libselinux-devel-1.33.4-5.7.el5.x86_64.rpm
rpm -ivh krb5-devel-1.6.1-70.el5.x86_64.rpm
rpm -ivh zlib-devel-1.2.3-4.el5.x86_64.rpm
rpm -ivh openssl-devel-0.9.8e-22.el5.x86_64.rpm

 


*************************piranha***************************
安装piranha:

rpm -ivh php-common-5.3.3-3.el6_2.8.x86_64.rpm
rpm -ivh php-cli-5.3.3-3.el6_2.8.x86_64.rpm
rpm -ivh php-5.3.3-3.el6_2.8.x86_64.rpm
rpm -ivh piranha-0.8.5-19.el6.x86_64.rpm

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

linxu集群架设——LVS,布布扣,bubuko.com

linxu集群架设——LVS

标签:des   c   a   http   tar   ext   

原文地址:http://www.cnblogs.com/liaoyi425/p/3766495.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!