1、SELS 11 SP3负载均衡LVS+keepalivedSUSE 11 SP3负载均衡部署方法把开发包gcc C+ 选上,编译安装软件时需用上。到了网络配置要把防火墙关掉,点击“disable”按默认配置全部配置完成。中途会要求设置root用户密码和创建一个新用户密码。二LVS MASTER 机器安装配置更改网卡IP地址cd /etc/sysconfig/networkvi ifcfg-eth0以下是参考内容:BOOTPROTO=static把原来的dhcp改成 staticBROADCAST=ETHTOOL_OPTIONS=IPADDR=192.168.168.10MTU=NAME=VMX
2、NET3 Ethernet ControllerNETMASK=255.255.255.0NETWORK=REMOTE_IPADDR=STARTMODE=autoUSERCONTROL=no增加网关:在同一目录/etc/sysconfig/network新增一个名为 routes 的文件,直接命令Vi routes 内容为 default 192.168.168.254重启网卡服务Service network restart用ifconfiga 命令查看ip地址配置是否正确。用netstatrn命令查看路由是否正确启用。使用远程工具SecureCRT登录。并使用工具自带的Sftp功能把需要安
3、装的软件包上传到服务器上放软件包的本地电脑以下是sftp的操作过程:sftplcd E:softwarelinux_opensftpcd /tmpsftpput cluster-network-kmp-default-1.4_3.0.76_0.9-2.23.24.x86_64.rpmUploading cluster-network-kmp-default-1.4_3.0.76_0.9-2.23.24.x86_64.rpm to /tmp/cluster-network-kmp-default-1.4_3.0.76_0.9-2.23.24.x86_64.rpm 100% 86KB 86KB/s
4、 00:00:00 E:/software/linux_open/cluster-network-kmp-default-1.4_3.0.76_0.9-2.23.24.x86_64.rpm: 88709 bytes transferred in 0 seconds (86 KB/s)sftpput ipvsadm-1.26-5.9.1.x86_64.rpmUploading ipvsadm-1.26-5.9.1.x86_64.rpm to /tmp/ipvsadm-1.26-5.9.1.x86_64.rpm 100% 37KB 37KB/s 00:00:00 E:/software/linux
5、_open/ipvsadm-1.26-5.9.1.x86_64.rpm: 38828 bytes transferred in 0 seconds (37 KB/s)sftpput openssl-devel-0.9.8j-2.1.x86_64.rpmUploading openssl-devel-0.9.8j-2.1.x86_64.rpm to /tmp/openssl-devel-0.9.8j-2.1.x86_64.rpm 100% 995KB 995KB/s 00:00:00 E:/software/linux_open/openssl-devel-0.9.8j-2.1.x86_64.r
6、pm: 1018912 bytes transferred in 0 seconds (995 KB/s)sftpput keepalived-1.2.15.tar.gzUploading keepalived-1.2.15.tar.gz to /tmp/keepalived-1.2.15.tar.gz 100% 337KB 337KB/s 00:00:00 E:/software/linux_open/keepalived-1.2.15.tar.gz: 345471 bytes transferred in 0 seconds (337 KB/s)sftp已经上传到/tmp目录上。安装查看i
7、p_vs模块是否在核心里susetest:/tmp # lsmod|grepip_vs没有,需要安装下面这个包才有susetest:/tmp # rpm -ivh cluster-network-kmp-default-1.4_3.0.76_0.9-2.23.24.x86_64.rpmPreparing. # 100%package cluster-network-kmp-default-1.4_3.0.76_0.9-2.23.24.x86_64 is already installedsusetest:/tmp # modprobeip_vs再查看,已经有了,表示支持LVS.susetest
8、:/tmp # lsmod|grepip_vsip_vs_wlc12519 1ip_vs154322 3ip_vs_wlcnf_conntrack87119 1ip_vsip6_tables 27524 1ip_vslibcrc32c 12644 1ip_vsipv6_lib 344914 30 ip_vs,ipv6接下来安装下面的包susetest:/tmp # rpm -ivh ipvsadm-1.26-5.9.1.x86_64.rpmPreparing. # 100%package ipvsadm-1.26-5.9.1.x86_64 is already installedsusetes
9、t:/tmp # rpm -ivh openssl-devel-0.9.8j-2.1.x86_64.rpmwarning: openssl-devel-0.9.8j-2.1.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 3e34cec9Preparing. # 100%package openssl-devel-0.9.8j-2.1.x86_64 is already installedsusetest:/tmp # 解压keepalivedsusetest:/tmp # tar -zxvf keepalived-1.2.15.tar.g
10、zsusetest:/tmp # cd keepalived-1.2.15/编译安装susetest:/tmp/keepalived-1.2.15 # ./configuresusetest:/tmp/keepalived-1.2.15 #echo $?这句验证上一句执行返回码,如果为0则正常,1或2为不正常。0susetest:/tmp/keepalived-1.2.15 #makesusetest:/tmp/keepalived-1.2.15 #echo $?0susetest:/tmp/keepalived-1.2.15 #make installsusetest:/tmp/keepal
11、ived-1.2.15 #echo $?0新建目录keepalived在/etc下susetest:/usr/local/etc/keepalived # mkdir -p /etc/keepalivedsusetest:/usr/local/etc # cd /etc/keepalived/创建keepalived.conf配置文件susetest:/etc/keepalived # vi keepalived.conf! Configuration File for keepalivedglobal_defs router_id LVS_DEVELvrrp_instance VI_1 st
12、ateBACKUPinterface eth0virtual_router_id 51priority 100advert_int 1nopreepmt #此句作用为防止强制接管服务authentication auth_type PASSauth_pass 1111 virtual_ipaddress 192.168.168.100 virtual_server 192.168.168.100 80 delay_loop 6lb_algowlclb_kind DRpersistence_timeout 300 protocol TCPreal_server 192.168.168.111 8
13、0 weight 1 HTTP_GET url path /status_code 200 connect_timeout 3nb_get_retry 3delay_before_retry 1 real_server 192.168.168.112 80 weight 1 HTTP_GET url path /status_code 200 connect_timeout 3nb_get_retry 3delay_before_retry 1 保存退出。把启动脚本写入系统自启动susetest:/etc/rc.d # vi /etc/rc.d/boot.local#! /bin/sh# Co
14、pyright (c) 2002 SuSE Linux AG Nuernberg, Germany. All rights reserved.# Author: Werner Fink , 1996# BurchardSteinbild, 1996# /etc/init.d/boot.local# script with local commands to be executed from init on system startup# Here you should add things, that should happen directly after booting# before w
15、ere going to the first run level.#启动加入下面这句/usr/local/sbin/keepalived启动时直接执行/usr/local/sbin/keepalived更改了配置以后,直接使用kill HUP 进程号进行更新,此方法不中断进程运行。susetest:/etc/keepalived # ps -ef|grepkeepalivedroot 4185 1 0 10:14 ? 00:00:00 /usr/local/sbin/keepalivedroot 4186 4185 0 10:14 ? 00:00:00 /usr/local/sbin/keep
16、alivedroot 4187 4185 0 10:14 ? 00:00:00 /usr/local/sbin/keepalivedroot 4282 3988 0 10:17 pts/2 00:00:00 grepkeepalivedsusetest:/etc/keepalived # kill -HUP 4185停止时使用kill的方式来杀进程,使用psef|grepkeepalived查看进程号。三LVS BACKUP 机器安装配置安装软件包及方法与MASTER一样,只有/etc/keepalived/keepalived.conf的配置把以下两句修改成:为了防止让主LVS在重新onli
17、ne的时候把服务接管,则主备都把 state 改成 BACKUP priority 100改为90(比主LVS的小一点)其他一样。四app服务器上的LVS部署无论有多少台应用服务器,配置都一致。只需运行一个脚本就可以实现,运行前请修改脚本内容IP地址为实际IP。在系统启动脚本中加入以下红色内容:susetest:/etc/rc.d # vi/etc/rc.d/boot.local#! /bin/sh# Copyright (c) 2002 SuSE Linux AG Nuernberg, Germany. All rights reserved.# Author: Werner Fink ,
18、1996# BurchardSteinbild, 1996# /etc/init.d/boot.local# script with local commands to be executed from init on system startup# Here you should add things, that should happen directly after booting# before were going to the first run level.#下面的IP地址请改为实际IP,不要改掩码。ifconfig lo:0 192.168.168.100 netmask 25
19、5.255.255.255 broadcast 192.168.168.100echo 1 /proc/sys/net/ipv4/conf/lo/arp_ignoreecho 2 /proc/sys/net/ipv4/conf/lo/arp_announceecho 1 /proc/sys/net/ipv4/conf/all/arp_ignoreecho 2 /proc/sys/net/ipv4/conf/all/arp_announce五压力测试51冗余功能测试测试的方法可以使用拔网线、停止keepalived进程服务。可以使用apra 的方法来查看切换是否成功。判断的方法为,如果MAC地址改变了,则切换成功,如以下例子:Windows测试端持续ping测试连续性你会发现,在切换的时候ping是持续的,没有中断。六小结以上例子是以tcp 80端口服务作为LVS负载均衡例子,如需其他端口请修改配置。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1