赞
踩
制作pem证书
#生产2048位的私钥文件
openssl genrsa -out haproxy.key 2048
openssl req -new -key haproxy.key -out haproxy.csr -passin pass:123456789 -subj "/C=CN/ST=SH/L=Chengdu/O=organization/OU=saicmotor/CN=192.168.1.200"
#正确--生产CA证书
openssl x509 -req -days 3650 -in haproxy.csr -signkey haproxy.key -out haproxy.crt
#将服务端证书和私钥打包成一个pem文件(haproxy使用)
cat haproxy.key haproxy.crt | tee server_ca.pem
配置haproxy的ssl之前请确认你的haproxy支持SSL
使用如下命令检查
[root@localhost haproxy]# haproxy -vv
如果没有支持SSL需要重新编译安装haproxy,如下命令重新编译安装
make TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 PREFIX=/var/local/haproxy
make install PREFIX=/var/local/haproxy
将server_ca.pem用于haproxy配置ssl连接
配置文件参考
global daemon maxconn 60000 #ulimit -n至少为60018最大连接并发数 #user /var/sbin/haproxy #user haproxy #运行haproxy的用户 #chroot /usr/local/haproxy #安裝根目錄 pidfile /var/run/haproxy.pid log 127.0.0.1 local2 tune.ssl.default-dh-param 2048 #因为我们的SSL密钥使用的是2048bit加密,所以在此进行声明。 defaults mode http log global #option http-keep-alive #使用keepAlive连接 option forwardfor #如果后端服务器需要获得客户端的真实ip,需要配置的参数,记录客户端IP在X-Forwarded-For头域中 option http-server-close # 后端为动态应用程序建议使用http-server-close,后端为静态建议使用http-keep-alive option httplog #开启httplog,HAProxy会记录更丰富的请求信息 option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接 #option httpchk GET /healthCheck.html #定义默认的健康检查策略 option redispatch #当serverid对应的服务器挂掉后,强制定向到其他健康的服务器 balance roundrobin #设置默认负载均衡方式,轮询方式 #balance source 设置默认负载均衡方式,类似于nginx的ip_hash #balance leastconn 设置默认负载均衡方式,请求转发到具有最少连接数目的后端服务器,在会话时间较长的场景中推荐使用此算法。例如数据库负载均衡等 timeout connect 2000ms #haproxy和服务端建立连接的最大时长,设置为1秒就足够了。局域网内建立连接一般都是瞬间的 timeout client 10000ms #和客户端保持空闲连接的超时时长,在高并发下可稍微短一点,可设置为10秒以尽快释放连接 timeout server 8000ms #和服务端保持空闲连接的超时时长,局域网内建立连接很快,所以尽量设置短一些,特别是并发时,如设置为1-3秒 timeout http-request 12000ms #从连接创建开始到从客户端读取完整HTTP请求的超时时间,用于避免类DoS攻击 timeout queue 5000ms #请求在队列中排隊的最大时长 #http请求重定向到https #frontend weblb # bind *:80 # acl is_http hdr_beg(host) file.minio.org #包含域名file.minio.org才走https # redirect scheme https if !{ ssl_fc } # bind *:443 ssl crt /var/local/haproxy/server_ca.pem # use_backend minio_image_video if is_http #http所有请求重定向到https frontend web01 bind *:80 bind *:443 ssl crt /var/local/haproxy/server_ca.pem redirect scheme https if !{ ssl_fc } mode http default_backend minio_image_video backend minio_image_video mode http balance roundrobin server minio01 192.168.1.200:9000 check server minio02 192.168.1.141:9000 check #backend imgserver # mode http # option httpchk /index.php # balance roundrobin # server img01 192.168.137.101:80 check inter 2000 fall 3 # server img02 192.168.137.102:80 check inter 2000 fall 3 ########统计页面配置######## listen stats #定义监控页面 bind *:2000 #绑定端口1080 maxconn 10 #默认的最大连接数 stats refresh 30s #每30秒更新监控数据 stats uri /stats #访问监控页面的uri #stats realm HAProxy\ Stats #监控页面的认证提示 #stats auth admin:admin #设置监控页面的用户和密码:admin,可以设置多个用户名 #stats auth Frank:Frank #设置监控页面的用户和密码:Frank #stats hide-version #隐藏统计页面上HAProxy的版本信息
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。