首页 > 代码库 > Haproxy实现80端口复用

Haproxy实现80端口复用

版权声明:


本文作者为—陈鑫

本文的所有内容均来陈鑫总结,未经本人许可,禁止私自转发及使用。

QQ: 499741233

E-mail: 499741233@qq.com


第1章 安装环境

1.1 系统环境

[root@10 conf]# uname -r

2.6.32-642.4.2.el6.x86_64

[root@10 conf]# uname -m

x86_64

[root@10 conf]# cat /etc/re

readahead.conf    redhat-lsb/       redhat-release    request-key.conf  request-key.d/    resolv.conf

[root@10 conf]# cat /etc/redhat-release

CentOS release 6.8 (Final)

1.2 程序版本

1.2.1 Haproxy

[root@10 haproxy]# ./sbin/haproxy -v

HA-Proxy version 1.5.11 2015/01/31

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

1.2.2 Haproxy程序下载地址

 

第2章 Haproxy安装启动

2.1 Haproxy安装

tar xf haproxy-1.5.11.tar.gzcd haproxy-1.5.11make TARGET=linux26 PREFIX=/usr/local/haproxymake install PREFIX=/usr/local/haproxy备注:TARGET要指定的系统的内核版本。

2.2 Haproxy配置文件

cd /usr/local/haproxy/mkdir confcd confvim haproxy.cfg[root@10 conf]# cat haproxy.cfgglobal    log         127.0.0.1 local0    log         127.0.0.1 local1 notice     chroot      /var/lib/haproxy    pidfile     /var/run/haproxy.pid    maxconn     4000    user        haproxy    group       haproxy    daemon     # turn on stats unix socket    stats socket /var/lib/haproxy/stats defaults    mode                    http    log                     global    option                  httplog    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 frontend main    mode tcp    bind *:80    log global    option tcplog    log-format %ft\ %b/%s     tcp-request inspect-delay 3s    acl is_https req.payload(0,3) -m bin 160301#GET POS(T) PUT DEL(ETE) OPT(IONS) HEA(D) CON(NECT) TRA(CE)    acl is_http req.payload(0,3) -m bin 474554 504f53 505554 44454c 4f5054 484541 434f4e 545241#SSH    acl is_ssh req.payload(0,3) -m bin 535348    tcp-request content accept if is_http    tcp-request content accept if is_https    tcp-request content accept if is_ssh    tcp-request content accept    use_backend https if is_https    use_backend http if is_http    use_backend ssh if is_ssh    use_backend ssh backend ssh    mode tcp    timeout server 1h    server server-ssh 127.0.0.1:22 backend http    mode tcp    server ngx01 127.0.0.1:82 maxconn 10 check inter 3s backend https    mode tcp    server ngx02 127.0.0.1:433 maxconn 10 check inter 3s

2.3 启动Haproxy

useradd -s /sbin/nologin -M haproxymkdir /var/lib/haproxy/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg

第3章 测试

3.1 测试ssh服务

{17:05}~/login ? ssh root@10.63.101.52 -p80Last login: Thu Oct 13 17:05:27 2016 from localhost

3.2 测试http服务

技术分享

Haproxy实现80端口复用