欢迎来到云服务器

系统配置

CentOS系统下布署LVS+keepalived负载平衡高可用情况

#!/bin/bash
# BY kerryhu
# Please manual operation yum of before Operation.....
系统情况`:CentOS 5.5(定制安装)
组件:
Base
Development Libraries
Development Tools
Editors
Text-based Internet

lvs-master:192.168.9.201
lvs-backup:192.168.9.202
vip:192.168.9.200
web1:192.168.9.203
web2:192.168.9.204
netmask:255.255.255.0
gateway:192.168.9.1

网络拓扑:

CentOS系统下布署LVS+keepalived负载平衡高可用情况

echo "============================ 更新系统时间 ======================"
yum install -y ntp
ntpdate time.nist.gov
echo "00 01 * * * /usr/sbin/ntpdate time.nist.gov" /etc/crontab

echo “============================ 封锁不消处事 =======================”
/root/del_servcie.sh           # 附件中自界说剧本

echo “========================= 安装ipvsadm、keepalived ==================”
[[email protected] ~]# cd /usr/local/src
[[email protected] ~]# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
[[email protected] ~]# wget http://www.keepalived.org/software/keepalived-1.1.17.tar.gz
[[email protected] ~]# ln -sv /usr/src/kernels/2.6.18-194.el5-i686/ /usr/src/linux
[[email protected] ~]# tar -zxvf ipvsadm-1.24.tar.gz
[[email protected] ~]# cd ipvsadm-1.24
[[email protected] ~]# make;make install
[[email protected] ~]# cd ..
[[email protected] ~]# tar -zxvf keepalived-1.1.17.tar.gz
[[email protected] ~]# cd keepalived-1.1.17
[[email protected] ~]# ./configure
configure: error:
  !!! OpenSSL is not properly installed on your system. !!!
  !!! Can not include OpenSSL headers files.
办理步伐:
[[email protected] ~]# yum -y install openssl-devel
[[email protected] ~]# ./configure
[[email protected] ~]# make;make install
编译的时候呈现这个提示,说明keepalived和内核团结了,假如不是这样的,需要加上这个参数./configure --with-kernel-

dir=/kernel/path
Keepalived configuration
------------------------
Keepalived version       : 1.1.17
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 LinkWatch            : No
Use Debug flags          : No

echo “======================= 设置keepalived ===========================”
[[email protected] ~]#  cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
[[email protected] ~]#  cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
[[email protected] ~]#  mkdir /etc/keepalived
[[email protected] ~]#  cp /usr/local/sbin/keepalived /usr/sbin/
[[email protected] ~]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
      [email protected]
   }
   notification_email_from [email protected]
   smtp_server smtp.163.com
  # smtp_connect_timeout 30
   router_id LVS_DEVEL
}
# VIP1
vrrp_instance VI_1 {
    state MASTER             #备份处事器大将MASTER改为BACKUP  
    interface eth0
    lvs_sync_daemon_inteface eth0
    virtual_router_id 51
    priority 100    # 备份处事大将100改为90
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
192.168.9.200  
        #(假如有多个VIP,继承换行填写.)
    }
}
virtual_server 192.168.9.200 80 {
    delay_loop 6                  #(每隔10秒查询realserver状态)
    lb_algo wlc                  #(lvs 算法)
    lb_kind DR                  #(Direct Route)
    persistence_timeout 60        #(同一IP的毗连60秒内被分派到同一台realserver)
    protocol TCP                #(用TCP协议查抄realserver状态)
    real_server 192.168.9.203 80 {
        weight 100               #(权重)
        TCP_CHECK {
        connect_timeout 10       #(10秒无响应超时)
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.9.204 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
}
[[email protected] ~]#  service keepalived start|stop
[[email protected] ~]# chkconfig –level 2345 keepalived on

腾讯云代理

Copyright © 2003-2021 MFISP.COM. 国外vps服务器租用 梦飞云服务器租用 版权所有 粤ICP备11019662号