1.基础配置文件
[root@node04 haproxy]# pwd
/etc/haproxy
[root@node04 haproxy]# vim haproxy.cfg
global
maxconn 100000
chroot /usr/local/haproxy
#stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
uid 99
gid 99
daemon
nbproc 2
cpu-map 1 0 haproxy第一个进程绑定到第0个CPU上
cpu-map 2 1 haproxy第二个进程绑定到第1个CPU上
#cpu-map 3 2
#cpu-map 4 3
pidfile /usr/local/haproxy/run/haproxy.pid
log 127.0.0.1 local3 info
defaults
option http-keep-alive
option forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
listen stats
mode http
bind 0.0.0.0:9999
stats enable
log global
stats uri /haproxy-status
stats auth haadmin:q1w2e3r4ys
listen web_port
bind 0.0.0.0:80
mode http
log global
server web1 127.0.0.1:8080 check inter 3000 fall 2 rise 5
2.独立的haproxy日志配置
[root@node04 haproxy-1.8.20]# vim /etc/rsyslog.conf
# Save boot messages also to boot.log
local7.* /var/log/boot.log
local3.* /var/log/haproxy_linux43.log
$ModLoad imudp
$UDPServerRun 514
[root@node04 haproxy-1.8.20]# ll /var/log/ha*
ls: cannot access /var/log/ha*: No such file or directory
[root@node04 haproxy-1.8.20]# systemctl restart rsyslog
[root@node04 haproxy-1.8.20]# ll /var/log/ha*
ls: cannot access /var/log/ha*: No such file or directory
[root@node04 haproxy-1.8.20]# systemctl restart haproxy
[root@node04 haproxy-1.8.20]# systemctl restart rsyslog
[root@node04 haproxy-1.8.20]# ll /var/log/ha*
-rw-------. 1 root root 129 Jul 15 01:22 /var/log/haproxy_linux43.log
listen web
mode tcp
bind 192.168.177.154:80,192.168.177.154:81 两个地址,一个外部防火墙调用,一个内部使用,可以使用不同IP地址,走不同网卡,走eth0和eth1,不会把流量压在一个网卡上
server web1 192.168.177.155:80
server web2 192.168.177.156:80
标准错误示范
一定要写具体的IP地址加端口
frontend web
bind *:80
use_backend web_host
backend web_host
server web1 192.168.177.155:80
#server web2 192.168.177.156:80
listen web
mode tcp
bind 192.168.177.154:80,192.168.177.154:81
#server web1 192.168.177.155:80
server web2 192.168.177.156:80
官方配置文件
#官网业务访问入口======================================
frontend WEB_PORT_80
bind 192.168.7.248:80
mode tcp
use_backend web_prot_http_nodes
backend web_prot_http_nodes
mode tcp
option forwardfor
server 192.168.7.101 192.168.7.101:80 check inter 3000 fall 3 rise 5
server 192.168.7.102 192.168.7.102:80 check inter 3000 fall 3 rise 5
#官网业务访问入口======================================
frontend WEB_PORT_443
bind 192.168.7.248:443
mode tcp
use_backend web_prot_https_nodes
backend web_prot_https_nodes
mode tcp
option forwardfor
server 192.168.7.101 192.168.7.101:443 check inter 3000 fall 3 rise 5
server 192.168.7.102 192.168.7.102:443 check inter 3000 fall 3 rise 5
使用listen替换frontend和backend的配置方式:
#官网业务访问入口=====================================
listen WEB_PORT_80
bind 192.168.7.102:80
mode http
option forwardfor
server web1 192.168.7.101:8080 check inter 3000 fall 3 rise 5
server web2 192.168.7.101:8080 check inter 3000 fall 3 rise 5
程序环境:
主程序: /usr/sbin/haproxy
配置文件: /etc/haproxy/haproxy.cfg
Unit file: /usr/lib/systemd/system/haproxy.service
配置段:
• global:全局配置段
进程及安全配置相关的参数
性能调整相关参数
Debug参数
• proxies:代理配置段
defaults:为frontend, backend, listen提供默认配置
frontend:前端,相当于nginx中的server {}
backend:后端,相当于nginx中的upstream {}
listen:同时拥有前端和后端配置::
网友评论