虚拟化容器,大数据,DBA,中间件,监控。

haproxy—TCP负载均衡

12 03月
作者:admin|分类:应用管理

1.下载haproxy最新版本 http://www.haproxy.org/download/1.5/src/haproxy-1.5.12.tar.gz

2.haproxy的安装

mkdir –p /usr/local/haproxy/logs/ 也就是创建这个文件夹/usr/local/haproxy/logs/

make TARGET=linux26 PREFIX=/usr/local/haproxy make install PREFIX=/usr/local/haproxy

3.执行下面的命令

[root@Template-Redhat54 haproxy-1.4.20]# install -d /usr/local/sbin

[root@Template-Redhat54 haproxy-1.4.20]# install haproxy /usr/local/sbin

[root@Template-Redhat54 haproxy-1.4.20]# install -d /usr/local/share/man/man1

[root@Template-Redhat54 haproxy-1.4.20]# install -m 644 doc/haproxy.1 /usr/local/share/man/man1

[root@Template-Redhat54 haproxy-1.4.20]# install -d /usr/local/doc/haproxy

[root@Template-Redhat54 haproxy-1.4.20]# for x in configuration architecture haproxy-en haproxy-fr; do \ > install -m 644 doc/$x.txt /usr/local/doc/haproxy ; \ > done

4.检查安装结果:

[root@Template-Redhat54 haproxy-1.4.20]# haproxy

看到类似下面的内容证明安装好了

HA-Proxy version 1.4.20 2012/03/10

Copyright 2000-2012 Willy Tarreau <w@1wt.eu>

Usage : haproxy [-f <cfgfile>]* [ -vdVD ] [ -n <maxconn> ] [ -N <maxpconn> ] [ -p <pidfile> ] [ -m <max megs> ]

-v displays version ; -vv shows known build options. -d enters debug mode ; -db only disables background mode.

-V enters verbose mode (disables quiet mode) -D goes daemon -q quiet mode : don't display messages

-c check mode : only check config files and exit -n sets the maximum total# of connections (2000) -m limits the usable amount of memory (in MB)

-N sets the default, per-proxy maximum # of connections (2000) -p writes pids of all children to this file

-de disables epoll() usage even when available -ds disables speculative epoll() usage even when available -dp disables poll() usage even when available

-sf/-st [pid ]* finishes/terminates old pids. Must be last arguments.

5.拷贝haproxy.cfg文件到usr/local/haproxy下。

haproxy.cfg内容如下:

==============================================================

global

maxconn 51200

chroot /usr/local/haproxy

uid 99

gid 99

daemon

#quiet

nbproc 1

pidfile /usr/local/haproxy/logs/haproxy.pid

defaults

mode http

#retries 2

option redispatch

option abortonclose

timeout connect 5000ms

timeout client 30000ms

timeout server 30000ms

#timeout check 2000

log 127.0.0.1 local0 err#[err warning info debug]

balance roundrobin

# option httplog

# option httpclose

# option dontlognull

# option forwardfor

listen admin_stats

bind 0.0.0.0:7777

option httplog

stats refresh 30s

stats uri /stats

stats realm Haproxy Manager

stats auth admin:admin

#stats hide-version

listen test1

bind :63005

mode tcp

server t1 127.0.0.1:9797

server t2 10.30.90.111:9797

==============================================================

开启haproxy命令

/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg

停止haproxy

# killall haproxy

浏览431 评论0
返回
目录
返回
首页
用 Keepalived+HAProxy 实现高可用负载均衡的配置方法 haproxy 支持ssl安装