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

lvs+keepalived+nginx

时间:2017-05-16 23:31:49      阅读:336      评论:0      收藏:0      [点我收藏+]

标签:interface   esc   .gz   负载均衡集群   tail   安装   art   address   主机   

安装过程

查看是否有ipvsadm软件

1. 检查ipvsadm是否安装成功.可以直接输入
[root@localhost ~]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port Forward Weight ActiveConn InActConn
 
2. 检查模版是否加入内核
[root@localhost ~]# lsmod |grep ip_vs
 ip_vs 78081 0 

安装keepalived

1. keepalived-1.2.1.tar.gz     # 解压这个文件并且安装 (tar -zxvf keepalived-1.2.1.tar.gz)
2. ./configure --prefix=/hnisi/keepalived/ --with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686
3.make
4.make install
5.配置文件的路径
cp /hnisi/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /hnisi/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /hnisi/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /hnisi/keepalived/sbin/keepalived /sbin/

配置主keepalived

vim /etc/keepalived/keepalived.conf

#global define  
global_defs {  
router_id LVS_T1  
}  
  
  
vrrp_sync_group bl_group {  
group {  
  bl_one  
}  
}  
  
vrrp_instance bl_one {  
    state MASTER  
    interface eth0  
    lvs_sync_daemon_interface eth0  
    virtual_router_id 38  
    priority 150  
    advert_int 3  
    authentication {  
        auth_type PASS  
        auth_pass 1111  
    }  
    virtual_ipaddress {  
      192.168.96.100  
    }  
}  
  
  
virtual_server 192.168.96.100 8099 {  
    delay_loop 3  
    lb_algo rr  
    lb_kind DR  
    persistence_timeout 1  
    protocol TCP  
  
  
    real_server 192.168.96.33 8099 {  
        weight 1                                                                                                                                        
        TCP_CHECK {                                                                                                                                     
            connect_timeout 10                                                                                                                          
            nb_get_retry 3                                                                                                                              
            delay_before_retry 3                                                                                                                        
            connect_port 8099                                                                                                                           
        }                                                                                                                                               
                                                                                                                                                        
    }                                                                                                                                                   
                                                                                                                                                        
    real_server 192.168.96.4 8099 {                                                                                                                     
        weight 1                                                                                                                                        
        TCP_CHECK {                                                                                                                                     
            connect_timeout 10                                                                                                                          
            nb_get_retry 3                                                                                                                              
            delay_before_retry 3                                                                                                                        
            connect_port 8099                                                                                                                           
        }                                                                                                                                               
    }                                                                                                                                                   
}                

配置备keepalived

分别在主备上启动keepalived

[root@ip_lb home]# /etc/init.d/keepalived start
Starting keepalived: [  OK  ]

[root@ip_lb home]# tail -f /var/log/message

# PS:这里说的LVS,并不是用ipvsadm软件配置,而是直接用keepalived的virtual_server配置项控制的。
# 安装ipvsadm只是可以看到负载状况,其实只需要keepalived也可以实现负载均衡集群。

在web1服务器配置LVS-DR

vim /etc/init.d/lvsDR_node(web1主机)

#! /bin/sh   
# descript : start real server DR  
VIP=192.168.96.100  
. /etc/rc.d/init.d/functions  
case "$1" in  
       start)  
             echo "start LVS of RealServer DR"  
             /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up  
             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 of RealServer DR"  
             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  

把这个文件复制到web2主机上

在web1和web2上分别启动这个脚本:

/etc/init.d/lvsDR_node start

测试是否可以负载均衡

#! /bin/sh  
for((i=1;i<=100;i++));do   
curl http://192.168.96.100:8099 >> /tmp/q;  
done  

官方文档:http://www.keepalived.org/pdf/sery-lvs-cluster.pdf

lvs+keepalived+nginx

标签:interface   esc   .gz   负载均衡集群   tail   安装   art   address   主机   

原文地址:http://www.cnblogs.com/liluredhat/p/6863190.html

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