haproxy

1yum 直接安装

2 编译安装(参数根据系统调整,参考README)
make TARGET=linux26 ARCH=x86_64
make install

/////////////开启日志功能//////////////
/etc/rsyslog.conf 文件添加如下
local0.* /var/log/haproxy.log
$ModLoad imudp
$UDPServerRun 514
/etc/sysconfig/rsyslog 文件修改如下
SYSLOGD_OPTIONS="-r -m 0 -c 2"
/////重启服务
/etc/init.d/rsyslog restart
/////////////haproxy.conf 配置文件添加/////////////
log 127.0.0.1 local0 info (warning)
//////////////////////配置例子//////////////////////
global
chroot /opt
daemon
group root
user root
log 127.0.0.1:514 local0 info
pidfile /var/run/haproxy.pid

 maxconn 20480

spread-checks 3

tune.maxaccept 100

tune.maxpollevents 180

nbproc 8

defaults
log global
mode http

option httplog

option dontlognull

retries 3
option redispatch
timeout connect 5000
timeout client 50000
timeout server 50000

listen www
bind 192.168.43.46:80
option forwardfor #记录真实机器ip
mode http

no option splice-response

    stats enable

stats hide-version
stats uri /admin?stats
stats auth proxy:oldboy
balance roundrobin
option httpclose
option forwardfor
option httpchk HEAD /index.html HTTP/1.0

option httpchk GET /index.html HTTP/1.0

option httpchk GET /index.html HTTP/1.0 \r\nHost:baidu.com

服务器多的时候频率快点,少的时候频道慢点 默认每2秒一次共三次

    server www08 192.168.43.44:80  maxconn 2048 weight 8    cookie www08 check port 80 inter 5000 fail 5 
    server www21 127.0.0.1:8080 check   cookie www21 check port 80 inter 5000 fail 5 

listen 8080
bind 192.168.43.49:8081
option forwardfor
mode tcp

no option splice-response

    stats enable
stats uri /admin?stats
    stats auth proxy:oldboy
    balance roundrobin
    server www8080 127.0.0.1:22 check

///////////为记录真是机器ip/////////////
apache 对应修改的log格式
LogFormat ""%{X-Forwarded-For}i" %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
nginx 记录远程主机ip日志格式添加如下
'"$http_user_agent" "$http_x_forwarded_for"';

//////////////////////sysctl.conf//////////配置

Kernel sysctl configuration file for Red Hat Linux

For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and

sysctl.conf(5) for more details.

Use '/sbin/sysctl -a' to list all possible parameters.

Controls IP packet forwarding

net.ipv4.ip_forward = 1

Controls source route verification

net.ipv4.conf.default.rp_filter = 1

Do not accept source routing

net.ipv4.conf.default.accept_source_route = 0

Controls the System Request debugging functionality of the kernel

kernel.sysrq = 0

Controls whether core dumps will append the PID to the core filename.

Useful for debugging multi-threaded applications.

kernel.core_uses_pid = 1

Controls the use of TCP syncookies

net.ipv4.tcp_syncookies = 1

Controls the default maxmimum size of a mesage queue

kernel.msgmnb = 65536

Controls the maximum size of a message, in bytes

kernel.msgmax = 65536

Controls the maximum shared segment size, in bytes

kernel.shmmax = 68719476736

Controls the maximum number of shared memory segments, in pages

kernel.shmall = 4294967296
#######created by oldboy for ipsec 2011-11-9###########

net.ipv4.conf.tun0.send_redirects = 0

net.ipv4.conf.tun0.accept_redirects = 0

net.ipv4.conf.eth1.send_redirects = 0
net.ipv4.conf.eth1.accept_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
net.ipv4.conf.lo.send_redirects = 0
net.ipv4.conf.lo.accept_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
#######created by oldboy for ipsec 2011-11-9###########
net.ipv4.ip_nonlocal_bind=1

你可能感兴趣的:(haproxy)