`

lvs+keepalive

 
阅读更多
1.安装LVS和Keepalived
#modprobe ip_vs    //内核加载ip_vs模块
#lsmod |grep ip_vs //看看加载是否成功
ip_vs                  78081  0
 #uname -r
 
 2.6.18-53.el5PAE
 
#ln -s /usr/src/kernels/2.6.18-53.el5PAE-i686/  /usr/src/linux //生成一个链接文件

如果/usr/src/kernels没有2.6.18-194.el5,则需要编译

#yum -y install kernel-devel
#yum -y update kernel
#cp /usr/src/kernels/2.6.18-274.el5/include/net/ip_vs.h        /usr/inclide/net/  //这个很重要,否则在安装ipvsadm的时候会提示缺少*.h文件

lvs安装
tar -xzvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24


make 
出错
make[1]: *** [libipvs.o] 错误 1
make[1]: Leaving directory `/root/ipvsadm-1.24/libipvs'
make: *** [libs] 错误 2
解决
yum install libnl* popt*
make install
出现一些字样
install -m 0755 -s ipvsadm /sbin
install -m 0755 ipvsadm-save /sbin
install -m 0755 ipvsadm-restore /sbin
[ -d /usr/man/man8 ] || mkdir -p /usr/man/man8
install -m 0644 ipvsadm.8 /usr/man/man8
install -m 0644 ipvsadm-save.8 /usr/man/man8
install -m 0644 ipvsadm-restore.8 /usr/man/man8
if [ -d /etc/rc.d/init.d ]; then \
                  install -m 0755 ipvsadm.sh /etc/rc.d/init.d/ipvsadm; \
                fi
表示成功

keepalived安装
#yum -y install openssl openssl-devel //安装keepalived需要
tar -xzvf keepalived-1.1.20.tar.gz 

出现以下信息表示成
Keepalived configuration 
------------------------ 
Keepalived version : 1.1.20 
Compiler : gcc 
Compiler flags : -g -O2 
Extra Lib : -lpopt -lssl -lcrypto    
Use IPVS Framework : Yes 
IPVS sync daemon support : Yes 
Use VRRP Framework : Yes 
Use Debug flags : No


 #find / -name keepalived  # 查看keepalived位置                

 
#cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
#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/
#service keepalived start|stop     #做成系统启动服务方便管理.


需要自己编辑

 配置LVS
在LVS机上配置(两台都要配置)
  1. LVS-DR,配置LVS脚本实现负载均衡
      #vi /usr/local/sbin/lvs-dr.sh
 
      #!/bin/bash
 
        # description: start LVS of DirectorServer
 
        #Written by :NetSeek http://www.linuxtone.org
 
        
 
        GW=61.164.122.1
 
        # website director vip.
 
        SNS_VIP=192.168.1.120
 
        SNS_RIP1=192.168.1.110
 
        SNS_RIP2=192.168.1.113
 

     /etc/rc.d/init.d/functions
 

        logger $0 called with $1
 

        case "$1" in
 

        start)
 
        # set squid vip
 
        /sbin/ipvsadm --set 30 5 60
 
        /sbin/ifconfig eth0:0 $SNS_VIP broadcast $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP up
 
        /sbin/route add -host $SNS_VIP dev eth0:0
 
        /sbin/ipvsadm -A -t $SNS_VIP:80 -s wrr -p 3
 
        /sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP1:80 -g -w 1
 
        /sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP2:80 -g -w 1
 
        touch /var/lock/subsys/ipvsadm >/dev/null 2>&1
 

       ;;
 
stop)
 
        /sbin/ipvsadm -C
 
        /sbin/ipvsadm -Z
 
        ifconfig eth0:0 down
 
        route del $SNS_VIP
 
        rm -rf /var/lock/subsys/ipvsadm >/dev/null 2>&1
 
        echo "ipvsadm stoped"
 
       ;;
 

status)
 

        if [ ! -e /var/lock/subsys/ipvsadm ];then
 
                echo "ipvsadm stoped"
 
                exit 1
 
        else
 
                echo "ipvsadm OK"
 
        fi
 
      ;;
 

*)
 
        echo "Usage: $0 {start|stop|status}"
 
        exit 1
 
esac
 

exit 0
 
      
配置Realserver脚本


       #vi /usr/local/sbin/realserver.sh
 
        #!/bin/bash
 
        # description: Config realserver lo and apply noarp 
        #Written by :NetSeek http://www.linuxtone.org
 
        
 
        SNS_VIP=192.168.1.120
 
         
 
        /etc/rc.d/init.d/functions
 
         
 
        case "$1" in
 
        start)
 
               ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
 
               /sbin/route add -host $SNS_VIP dev lo:0
 
               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
 
               sysctl -p >/dev/null 2>&1
 
               echo "RealServer Start OK"
 
         
 
               ;;
 
        stop)
 
               ifconfig lo:0 down
 
               route del $SNS_VIP >/dev/null 2>&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
 
     
     或者采用secondary ip address方式配置
           # vi /etc/sysctl.conf

          net.ipv4.conf.lo.arp_ignore = 1
 
          net.ipv4.conf.lo.arp_announce = 2
 
          net.ipv4.conf.all.arp_ignore = 1
 
          net.ipv4.conf.all.arp_announce = 2
 
       
 
          #sysctl -p
 
          #ip addr add 192.168.1.120/32 dev lo
 
          #ip add list 查看是否绑定
 
  3. 启动lvs-dr脚本和realserver启本,在DR上可以查看LVS当前状态:
 
        #watch ipvsadm -ln


配置keeplive

vi /etc/keepalived/keepalived.conf
  ! Configuration File for keepalived
 

global_defs {
 
   notification_email {
 
         cnseek@gmail.com
 
   }
 
   notification_email_from sns-lvs@gmail.com
 
   smtp_server 127.0.0.1
 
  # smtp_connect_timeout 30
 
   router_id LVS_DEVEL
 
}
 

# 20081013 written by :netseek
 
# VIP1
 
vrrp_instance VI_1 {
 
    state MASTER             #备份服务器上将MASTER改为BACKUP   
 
    interface eth0
 
    virtual_router_id 51
 
    priority 100    # 备份服务上将100改为99
 
    advert_int 1
 
    authentication {
 
        auth_type PASS
 
        auth_pass 1111
 
    }
 
    virtual_ipaddress {
 
        61.164.122.8   
 
        #(如果有多个VIP,继续换行填写.)
 
    }
 
}
 

virtual_server 61.164.122.8 80 {
 
    delay_loop 6                  #(每隔10秒查询realserver状态)
 
    lb_algo wrr                  #(lvs 算法)
 
    lb_kind DR                  #(Direct Route)
 
    persistence_timeout 60        #(同一IP的连接60秒内被分配到同一台realserver)
 
    protocol TCP                #(用TCP协议检查realserver状态)
 

    real_server 61.164.122.9 80 {
 
        weight 3               #(权重)
 
        TCP_CHECK {
 
        connect_timeout 10       #(10秒无响应超时)
 
        nb_get_retry 3
 
        delay_before_retry 3
 
        connect_port 80
 
        }
 
    }
 
    real_server 61.164.122.10 80 {
 
        weight 3
 
        TCP_CHECK {
 
        connect_timeout 10
 
        nb_get_retry 3
 
        delay_before_retry 3
 
        connect_port 80
 
        }
 
     }
 
}
 
# /usr/local/sbin/lvsdr.sh start (把这条语句写到/etc/rc.local中,开机启动)
#/etc/init.d/keepalived start  启动keepalived 服务,keepalived就能利用keepalived.conf 配置文件,实现负载均衡和高可用.
 #watch ipvsadm –ln


参考文章
http://bbs.linuxtone.org/thread-1077-1-1.html
http://31543.blog.51cto.com/21543/110472/
http://nhylovezyh.blog.51cto.com/1444948/666446
分享到:
评论

相关推荐

    centos7-lvs+keepalive部署

    ### CentOS 7 上 LVS+Keepalived 部署详解 #### 一、环境准备与软件安装 根据提供的部分内容可以看出,本教程旨在演示如何在 CentOS 7 系统上安装配置 LVS(Linux Virtual Server)及 Keepalived 服务,以实现...

    lvs+keepalive 比较详细的安装配置文档

    LVS+Keepalived 详细安装配置文档 LVS(Linux Virtual Server)是一种开源的负载均衡解决方案,通过 Keepalived 实现高可用性的虚拟服务器。下面将详细介绍 LVS+Keepalived 的安装配置过程和技术实现原理。 LVS ...

    mysql+lvs+keepalive+mha高可用

    在本教程中,我们将探讨一种基于`mysql`、`lvs`(Linux Virtual Server)、`keepalived`以及`MHA`(Master High Availability)的解决方案,这种方案可以实现VIP(Virtual IP)漂移,有效防止因单点故障导致的服务...

    LVS+Keepalive for centos7-可实施文档.docx

    ### LVS+Keepalived 在 CentOS 7 中的部署与应用 #### 一、概述 在高可用性和高性能计算环境中,LVS (Linux Virtual Server) 和 Keepalived 的结合使用是一种常见的架构设计方法。该组合旨在通过负载均衡和故障...

    LVS+KeepAlive基于CentOS6安装配置1

    3. **Keepalive与LVS高可用** - **Keepalive**:一种用于监控和恢复LVS服务的工具,确保DR的高可用性。 - **Keepalive安装**:安装必要的依赖,编译并安装Keepalived。 - **Keepalived配置**:配置主备DR,当...

    lvs+keepalived+mha+mysql架构最佳部署手册

    ### lvs+keepalived+mha+mysql高可用架构配置说明 #### 第一部分 MHA介绍 **MHA**(Master High Availability)作为一种成熟的MySQL高可用性解决方案,它由日本开发者Youshimaton创建,旨在为MySQL环境提供故障...

    lvs+keepalived+vsftp配置FTP服务器负载均衡

    在构建大型、高可用性的FTP(File Transfer Protocol)服务时,使用LVS(Linux Virtual Server)、Keepalived和VSFTPd的组合是一个常见的解决方案。LVS提供负载均衡,Keepalived确保服务高可用,而VSFTPd是常用的FTP...

    lvs+keeplive完整配置文档[参考].pdf

    《LVS+Keepalive配置详解》 LVS(Linux Virtual Server)是一种开源的负载均衡解决方案,结合Keepalive工具,能够构建高效、稳定的集群系统。LVS提供了三种IP负载均衡技术,分别是VS/NAT、VS/TUN和VS/DR,以及八种...

    HAProxy+Keepalived+LVS实现负载平衡高可用集群最佳实践

    HAProxy+Keepalived+LVS实现负载平衡高可用集群最佳实践

    Lvs dr+keepalive

    ### LVS DR+Keepalived 关键知识点解析 #### 一、LVS 架构概述 **LVS** (Linux Virtual Server) 是一种基于 Linux 内核的负载均衡解决方案,它可以构建高性能、高可用的服务器集群。LVS 主要有三种工作模式:VS/...

    LVS-DR+keepalive+ldirectord构建高可用负载均衡群集试验手册

    ### LVS-DR+Keepalived+Ldirectord构建高可用负载均衡群集知识点解析 #### 1. LVS-DR (Linux Virtual Server - Direct Routing) 概述 - **定义**:LVS-DR是一种基于Linux内核的负载均衡技术,通过直接路由的方式将...

    LVS+keepalived群集教程(原创)

    【LVS+Keepalived群集教程】 LVS(Linux Virtual Server)是基于Linux操作系统的一套高性能、高可用的负载均衡技术,它能够将网络流量分发到多个服务器上,提高系统的并发处理能力和稳定性。Keepalived是一款用于...

    使用LVS+heartbeat构建高可用web集群

    keepalive 2 deadtime 10 warntime 5 initdead 30 udpport 694 bcast eth1 auto_failback on node master node backup ping_group group1 192.168.1.103 192.168.1.104 respawn hacluster /usr/lib/...

    nginx+keepalive主从 双机热备 + 自动切换解决方案

    router_id LVS_DEVEL } vrrp_script chk_nginx { script "/home/check_nginx.sh" interval 2 weight 2 } vrrp_instance VI_1 { state BACKUP # MASTER interface eth2 virtual_router_id 51 mcast_src_ip ...

    高性能业务架构解决方案(HAproxy+Keepalive)

    Nginx/LVS/HAProxy的基于Linux的开源免费的负载均衡软件。对于大型的,需要进行高并发的网站或者对网络不太严格的场景,可以使用Nginx;对于大型的Web服务器的时候可以使用Haproxy;对性能有严格要求的时候可以使用...

    MySQL LVS+Keepalived+MHA 高可用群集 应用部署操作手册

    MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本人youshimaton开发,是一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件。在MySQL故障切换过程中,MHA能...

Global site tag (gtag.js) - Google Analytics