实验环境:
HAProxy节点:192.168.199.200
Harbor1节点:192.168.199.200
Harbor2节点:192.168.199.201
1.在192.168.199.200,192.168.199.201两个节点上搭建Harbor,并做MYSQL分离
见:https://blog.csdn.net/s812289480/article/details/83302284
2.在192.168.199.200,192.168.199.201上搭建双主热备的MYSQL:
见:https://blog.csdn.net/s812289480/article/details/83310368
3.在192.168.199.200搭建HAProxy:
3.1 APT安装HAProxy
$ sudo apt install haproxy
3.2 配置/etc/haproxy/haproxy.cfg
$ vi /etc/haproxy/haproxy.cfg
----------------------------------
global
log 127.0.0.1 local2
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
defaults
log global
mode tcp
option httplog
option dontlognull
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 600
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
listen stats
mode http
bind :8888
stats enable
stats hide-version
stats uri /haproxyadmin?stats
stats realm Haproxy\ Statistics
stats auth admin:admin
frontend main
bind 0.0.0.0:80
default_backend harbor
backend harbor
balance leastconn
server harbor1 192.168.199.200:8080 check port 80 maxconn 300
server harbor2 192.168.199.201:8080 check port 80 maxconn 300
3.3 配置启动日志
$ vi /etc/rsyslog.conf
------------------------------------------
...
# provides TCP syslog reception
#module(load="imtcp")
#input(type="imtcp" port="514")
local2.* /var/log/haproxy.log
# Enable non-kernel facility klog messages
...
3.4 重启rsyslog和haproxy
$ sudo systemctl restart rsyslog
$ sudo systemctl restart haproxy
3.5 测试haproxy是否正确开启
打开浏览器输入:192.168.199.200:8888/haproxyadmin?stats 如果可以正常登录并且harbor1和harbor2都正常工作则配置正确。
3.6 测试harbor是否正常工作
打开浏览器输入:192.168.199.201登录harbor