手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Haproxy+Keepalived搭建Weblogic高可用负载均衡集群

[日期:2013-09-06] 来源:CSDN  作者:sgx425021234 [字体:大 中 小]

Haproxy与keepalived 配置

Haproxy 配置

1、 下载haproxy

Haproxy.1wt.eu 下载最新稳定版haproxy

2、 安装环境

如果系统没有安装gcc的话需要安装gcc

yum install gcc

 

3、 Cd /opt

Tar –zxvf haproxy-1.4.24.tar.gz

Cd haproxy-1.4.24

make TARGET=linux26

make install

4、 Haproxy安装到/usr/local/haproxy

编辑配置文件 vi /usr/local/haproxy/conf/haproxy.cfg

 

 

global

log 127.0.0.1 local1 info

maxconn 20480

chroot /usr/share/haproxy

uid 99

gid 99

daemon

nbproc 1

pidfile /usr/share/haproxy/haproxy.pid

defaults

log global

mode http

option httplog

option dontlognull

retries 3

option redispatch

maxconn 20480

contimeout 5000

clitimeout 50000

srvtimeout 50000

 

listen admin_stats

bind *:9020

stats refresh 30s

stats uri /haweb

stats realm Haproxy Manager

stats auth test:test

#stats hide-version

 

frontend test

bind *:80

#

acl test_2013 path_beg -i /test_2013

acl test_2014 path_beg -i /test_2014

 

use_backend test_2013.server if test_2013

use_backend test_2014.server if test_2014

backend test2013.server

mode http

#fullconn 1000

balance roundrobin

cookie SERVERID insert indirect

option httpchk HEAD/test2013/skins/logo.gif

server test201331192.168.1.10:8080 cookie test1 check inter 2000 rise 3 fall 3 weight 3

server test201332192.168.1.20:8080 cookie test2 check inter 2000 rise 3 fall 3 weight 3

server test201333192.168.1.30:8080 cookie test3 check inter 2000 rise 3 fall 3 weight 3

server test201334192.168.1.40:8080 cookie test4 check inter 2000 rise 3 fall 3 weight 3

 

backend test_2014.server

mode http

#fullconn 1000

balance roundrobin

cookie SERVERID insert indirect

option httpchk HEAD/test_2014/skins/logo.gif

server test_201431 192.168.1.10:8080cookie test5 check inter 2000 rise 3 fall 3 weight 3

server test_201432192.168.1.20:8080 cookie test6 check inter 2000 rise 3 fall 3 weight 3

server test_201433192.168.1.30:8080 cookie test7 check inter 2000 rise 3 fall 3 weight 3

server test_201434192.168.1.40:8080 cookie test8 check inter 2000 rise 3 fall 3 weight 3

 

 

这是haproxy 的基本配置,2台haproxy 配置保持一致即可。

这里可以在/etc/init.d/ 下建立一个haproxy脚本文件,方便执行service haproxy start/stop/restart

内容如下:

#!/bin/bash

BASE_DIR="/usr/local/haproxy"

ARGV="$@"

 

start()

{

echo "START HAPoxy SERVERS"

$BASE_DIR/haproxy -f$BASE_DIR/conf/haproxy.cfg

}

 

stop()

{

echo "STOP HAPoxy Listen"

kill -TTOU $(cat/usr/share/haproxy/haproxy.pid)

echo "STOP HAPoxy process"

kill -USR1 $(cat /usr/share/haproxy/haproxy.pid)

}

case $ARGV in

 

start)

start

ERROR=$?

;;

 

stop)

stop

ERROR=$?

;;

 

restart)

stop

start

ERROR=$?

;;

 

*)

echo "hactl.sh[start|restart|stop]"

esac

exit $ERROR

 

之后可以在/etc/rc3.d 建立连接,实现开机自动启动

 

Keepalived 配置

1、 下载keepalived软件

官网下载keepalived-1.2.7.tar.gz

2、 安装软件环境

yum install openssl-devel popt-devel

3、 tar –zxvf keepalived-1.2.7.tar.gz

cd /root/keepalived-1.2.7

./configure --prefix=/usr/local/keepalived/

Make & make install

4、 cp /usr/local/keepalived/etc/keepalived/samples/keepalived.conf.vrrp/etc/keepalived/ keepalived.conf ##拷贝配置文件

cp /usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/keepalived ##拷贝执行文件

cp /usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/keepalived ##拷贝执行文件

cp /usr/local/keepalived/sbin/keepalived/usr/sbin/keepalived #拷贝执行文件

5、 示例配置文件

本配置为双主keepalived配置,即有个虚拟IP,双主机互为主备,可以更高效的利用服务器资源,如果是一主一备方式,只配置一个虚拟IP即可。

!Configuration File for keepalived

 

global_defs{

notification_email {

acassen@firewall.loc

failover@firewall.loc

sysadmin@firewall.loc

}

notification_email_fromAlexandre.Cassen@firewall.loc

smtp_server 192.168.200.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

 

vrrp_instanceVI_1 {

state MASTER

interface eth1

virtual_router_id 51

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.1.30

}

}

 

vrrp_instanceVI_2 {

state BACKUP

interface eth1

virtual_router_id 52

priority 90

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.1.40

}

}

 

同样的在/etc/rc3.d下建立链接即可实现开机自动启动,至此Haproxy+keepalived 搭建weblogic高可用负载均衡集群已经配置完毕,但这只是开始,这只是基础配置,系统的整体优化是重点,包括haproxy weblogic等,都需要根据实际情况进行调优,希望这篇文章可以帮助到你,谢谢!

linux
相关资讯       weblogic  keepalived  HAProxy 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款