Haproxy示例之访问内网mongoDB
请参考官方doc
/usr/share/doc/haproxy-1.4.24/
环境:
CentOS6.5 x64+haproxy-1.4.24
一.安装haproxy
#yum -y install haproxy
二.配置haproxy
#vim /etc/haproxy/haproxy.cfg
global
log
127.0.0.1 local2
chroot
/var/lib/haproxy
pidfile
/var/run/haproxy.pid
maxconn
4000
user
haproxy
group
haproxy
daemon
stats socket
/var/lib/haproxy/stats
defaults
log
global
option
dontlognull
option
http-server-close
option
redispatch
retries
3
timeout http-request
10s
timeout queue
1m
timeout connect
10s
timeout client
1m
timeout server
1m
timeout
http-keep-alive 10s
timeout check
10s
maxconn
3000
stats enable
stats uri
/haproxy-stats
stats refresh
10s
stats realm
Haproxy statistic
stats auth
hadmin:foo.123
listen mongod
bind
172.16.0.100:27017
mode tcp
balance
roundrobin
server mongo1
192.168.8.200:27017
listen mongo-web
bind
172.16.0.100:28017
mode http
balance
roundrobin
server mongo1
192.168.8.200:28017
说明:
172.16.0.100 #Haproxy IP
192.168.8.200 #MongoDB IP
三.重启haproxy
# service haproxy restart
# chkconfig haproxy on
通过haproxy映射连接MongoDB
# mongo 172.16.0.100:27017/admin -u root -p
通过公网访问MongoDB WEB控制台
浏览器输入 http://172.16.0.100:28017
四.haproxy-status
stats
enable
stats uri
/haproxy-stats
stats refresh
10s
stats realm
Haproxy statistic
stats auth
hadmin:foo.123
在配置文件defaults章节加入如上配置信息即可启用haproxy-status的dashboard,可以启用auth-basic认证,看到负载状态