免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2739 | 回复: 3
打印 上一主题 下一主题

LVS + heartbeat [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-01-13 14:22 |只看该作者 |倒序浏览
lvs1 lvs2配置信息
LVS主配置信息:
1、安装依赖包
yum -y install libxslt libxslt-devel libgcrypt-devel autoconf automake pkgconfig libgpg-error-devel libtool sgml-common opensp openjade xml-common docbook-dtds docbook-style perl libtool-ltdl-devel perl-MailTools ipvsadm

修改主机名:
vi /etc/hosts
192.168.107.134                lvs1
192.168.107.135                lvs2
192.168.107.136                rs1
192.168.107.137                rs2

修改VIP:ifcfg-eth0:0
[root@lvs2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.107.200
NETMASK=255.255.255.255
GATEWAY=192.168.107.2

2、安装libnet
        #tar -zxvf libnet-1.1.4.tar.gz
        #cd libnet-1.1.4
        #./configure && make && make install

3、安装hearbeat
        #tar -jxvf hearbeat-3.0.4.tar.gz
        #cd hearbeat-3.0.4
        #./ConfigureMe configure --disable-swig --disable-snmp-subagent
        #make && make install
             #cp doc/ha.cf doc/haresources doc/authkeys /etc/ha.d/
        #cp ldirectord/ldirectord.cf /etc/ha.d
        #groupadd -g 694 haclient
        #useradd -u 694 -g haclient hacluster -s /sbin/nologin

修改        #vim lib/plugins/HBcomm/ucast.c
注释掉        #466 /*      int i = 1; */
删除配置文件 Makefile中的    -Werror

4、主备配置LVS1修改ldirectord.cf
checktimeout=20
checkinterval=10
autoreload=yes
quiescent=yes

virtual=192.168.107.200:80
        real=192.168.107.136:80 gate
        real=192.168.107.137:80 gate
        fallback=127.0.0.1:80 gate
        service=http
        request="index.html"
        receive="Test Page"
        virtualhost=some.domain.com.au
        scheduler=rr
        protocol=tcp
          checktype=negotiate
          checkport=80

5、修改heartbeat 通过Eth1进行心跳监控
logfile        /var/log/ha-log
logfacility        local0
bcast                eth1
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport        694
baud        19200
auto_failback on
node        lvs1
node        lvs2
ping 192.168.107.2

6、修改heartbeat的资源文件(/etc/ha.d/haresources)
#新增
lvs1    IPaddr::192.168.107.200/24/eth0 lddirectord

7、修改heartbeart的认证文件(/etc/ha.d/authkeys)
auth 1
1 crc
#2 sha1 HI!
#3 md5 Hello!

8、启动服务
[root@Lvs1?~]#?/etc/init.d/ldirectord start
[root@Lvs1?~]#?/etc/init.d/heartbeat start

rs配置信息
1、RS1配置

修改主机名:
vi /etc/hosts
192.168.107.134                lvs1
192.168.107.135                lvs2
192.168.107.136                rs1
192.168.107.137                rs2

2、搭建nginx服务
安装依赖包
yum -y install gcc* openssl* libjpeg-devel freetype-devel libpng-devel bison ncurses-devel cmake ncurses-devel openldap openldap-devel openssl openssl-devel pcre*

解压文件
tar zxvf nginx-1.4.1.tar.gz
cd nginx-1.4.1

编译安装
./configure --user=nobody --group=nobody  --prefix=/app/nginx --with-http_stub_status_module --with-http_ssl_module

make && make install

nginx修改
groupadd www
useradd -g www www -s /sbin/nologin

vi  /app/nginx/conf/nginx.conf
修改
user www
root html —> root /app/www
    location ~ \.php$ {
    root           /app/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_indexindex.php;
        fastcgi_param  SCRIPT_FILENAME  /app/www$fastcgi_script_name;(此处需要修改成 /app/www)
    include        fastcgi_params;
}

启动nginx
/data/nginx/sbin/nginx

3、创建lvsrs脚本
#!/bin/bash
#description: Start Real Server
VIP=192.168.107.200
./etc/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 of Real 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
[root@rs1~]#chmod 755  /etc/init.d/lvsrs
[root@rs2~]#service vsrs start

问题:无法通过VIP 访问网站? 求大师解决

日志信息:
[root@lvs1 ~]# tail -f /var/log/ha-log
ipfail[2032]: 2016/01/13_13:58:11 info: No giveup timer to abort.
heartbeat[2022]: 2016/01/13_13:58:16 info: lvs2 wants to go standby [foreign]
heartbeat[2022]: 2016/01/13_13:58:16 info: standby: acquire [foreign] resources from lvs2
heartbeat[2735]: 2016/01/13_13:58:16 info: acquire local HA resources (standby).
ResourceManager[2748]:        2016/01/13_13:58:17 info: Acquiring resource group: lvs1 IPaddr::192.168.107.200/32/eth0:0 ldirectord
IPaddr[2775]:        2016/01/13_13:58:17 INFO:  Running OK
ResourceManager[2748]:        2016/01/13_13:58:17 info: Running /etc/ha.d/resource.d/ldirectord  start
heartbeat[2735]: 2016/01/13_13:58:17 info: local HA resource acquisition completed (standby).
heartbeat[2022]: 2016/01/13_13:58:17 info: Standby resource acquisition done [foreign].
heartbeat[2022]: 2016/01/13_13:58:17 info: remote resource transition completed.

[root@lvs1 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddressort Scheduler Flags
  -> RemoteAddressort           Forward Weight ActiveConn InActConn
TCP  192.168.107.200:80 rr
  -> 127.0.0.1:80                 Local   1      0          0         
  -> 192.168.107.136:80           Route   0      0          0         
  -> 192.168.107.137:80           Route   0      0          0         
[root@lvs1 ~]#

论坛徽章:
0
2 [报告]
发表于 2016-01-13 14:24 |只看该作者
求大神帮忙看看,感激不尽  

论坛徽章:
0
3 [报告]
发表于 2016-01-15 02:56 |只看该作者
能用lvs + keepalived吗? ldrecord好像都没有维护那, 还有trouble shooting的时候,可以用tcpdump看看网络包是在哪儿drop掉那,我估计是lvs因为heartbeat或ldrecord原因没有forward网络包. 你可以先只用一个LVS, 先不要active/standby redundance, 确信一个lvs能正常工作以后再启用hearbeat.

论坛徽章:
1
IT运维版块每日发帖之星
日期:2016-01-13 06:20:00
4 [报告]
发表于 2016-01-16 08:08 |只看该作者
我记得rs上面要添加一条直接路由让lo:0收到的数据包通过eth的端口出去的。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP