歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習Linux

Haproxy實現80端口復用,haproxy80復用

Haproxy實現80端口復用,haproxy80復用

Haproxy實現80端口復用,haproxy80復用


版權聲明:


本文作者為—陳鑫

本文的所有內容均來陳鑫總結,未經本人許可,禁止私自轉發及使用。

QQ: 499741233

E-mail: [email protected]


第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 <[email protected]>

1.2.2 Haproxy程序下載地址

 

第2章 Haproxy安裝啟動

2.1 Haproxy安裝

tar xf haproxy-1.5.11.tar.gz

cd haproxy-1.5.11

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

make install PREFIX=/usr/local/haproxy

備注:TARGET要指定的系統的內核版本。

2.2 Haproxy配置文件

cd /usr/local/haproxy/

mkdir conf

cd conf

vim haproxy.cfg

[root@10 conf]# cat haproxy.cfg

global

    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 haproxy

mkdir /var/lib/haproxy

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

第3章 測試

3.1 測試ssh服務

{17:05}~/login ➭ ssh [email protected] -p80

Last login: Thu Oct 13 17:05:27 2016 from localhost

3.2 測試http服務

http://xxxxxx/Linuxjc/1164655.html TechArticle

Copyright © Linux教程網 All Rights Reserved