Skip to content

一些常用软件的安装

一、haproxy

安装

docker 安装

6001 管理端口, 6000 业务端口

shell
docker rm -f haproxy
sudo docker run -d  --name haproxy  \
-v /data/app/haproxy:/usr/local/etc/haproxy:ro  \
-p 6001:6001 -p 6000:6000  -p 6043:6043   -p 443:6043   -p 80:80    -p 8080:80  haproxytech/haproxy-alpine:2.4
docker rm -f haproxy
sudo docker run -d  --name haproxy  \
-v /data/app/haproxy:/usr/local/etc/haproxy:ro  \
-p 6001:6001 -p 6000:6000  -p 6043:6043   -p 443:6043   -p 80:80    -p 8080:80  haproxytech/haproxy-alpine:2.4

配置文件

文件 /data/app/haproxy/haproxy.cfg

yml
global
  stats socket /var/run/api.sock user haproxy group haproxy mode 660 level admin expose-fd listeners
  log stdout format raw local0 info

defaults
  mode http
  timeout client 120s
  timeout connect 120s
  timeout server 120s
  timeout http-request 120s
  log global

frontend stats
  bind *:6001
  stats enable
  stats uri /
  stats auth 账号:你的密码
  stats refresh 10s

frontend myfrontend
  bind :6000
  default_backend webservers
  http-response set-header Access-Control-Allow-Origin *
  http-response set-header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
  http-response set-header Access-Control-Allow-Headers "Content-Type, Authorization"

backend webservers
  mode http
  cookie SERVER-COOKIE insert indirect nocache
  option httpchk GET /api/status HTTP/1.1\r\nHost:\ aidutu.cn
  server s5001 172.17.0.1:5001 cookie s5001  check
  server s5002 172.17.0.1:5002 cookie s5002  check
  server s5003 172.17.0.1:5003 cookie s5003  check
  server s5004 172.17.0.1:5004 cookie s5004  check
global
  stats socket /var/run/api.sock user haproxy group haproxy mode 660 level admin expose-fd listeners
  log stdout format raw local0 info

defaults
  mode http
  timeout client 120s
  timeout connect 120s
  timeout server 120s
  timeout http-request 120s
  log global

frontend stats
  bind *:6001
  stats enable
  stats uri /
  stats auth 账号:你的密码
  stats refresh 10s

frontend myfrontend
  bind :6000
  default_backend webservers
  http-response set-header Access-Control-Allow-Origin *
  http-response set-header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
  http-response set-header Access-Control-Allow-Headers "Content-Type, Authorization"

backend webservers
  mode http
  cookie SERVER-COOKIE insert indirect nocache
  option httpchk GET /api/status HTTP/1.1\r\nHost:\ aidutu.cn
  server s5001 172.17.0.1:5001 cookie s5001  check
  server s5002 172.17.0.1:5002 cookie s5002  check
  server s5003 172.17.0.1:5003 cookie s5003  check
  server s5004 172.17.0.1:5004 cookie s5004  check

转发端口

  • 6043 443转发到 新ip的443端口
  • 80转发到 新ip的80端口
yml
frontend sh2gz
  bind *:6043,*443
  mode tcp
  default_backend  gz443

frontend sh2gz80
  bind *:80
  mode tcp
  default_backend  gz80

backend gz443
  mode tcp
  server gz 116.205.233.112:443
backend gz80
  mode tcp
  server gz80 116.205.233.112:80
frontend sh2gz
  bind *:6043,*443
  mode tcp
  default_backend  gz443

frontend sh2gz80
  bind *:80
  mode tcp
  default_backend  gz80

backend gz443
  mode tcp
  server gz 116.205.233.112:443
backend gz80
  mode tcp
  server gz80 116.205.233.112:80