基于https的负载均衡配置
一. 拓扑
二.证书生成
openssl genrsa -des3 -out hdm.key 2048openssl req -new -key hdm.key -out hdm.csropenssl x509 -req -days 365 -in hdm.csr -signkey hdm.key -out hdm.crtcat hdm.crt hdm.key > hdm.pemopenssl rsa -in hdm.key -out hdm.key.unsecure-rw-r----- 1 root root 1298 Feb 21 17:35 approbe.crt-rw-r----- 1 root root 1115 Feb 21 17:34 approbe.csr-rw-r----- 1 root root 1751 Feb 21 17:30 approbe.key-rw-r----- 1 root root 1679 Feb 22 11:05 approbe.key.unsecure-rw-r----- 1 root root 3049 Feb 21 17:36 approbe.pem
三.nginx配置
# 配置反向代理upstream routerzhouqishangbao {# ip_hash;# least_conn ;# fair ;server 10.0.1.129:8001 weight=2 max_fails=3 fail_timeout=30s;server 10.0.1.129:8002 weight=1 max_fails=1 fail_timeout=20;server 10.0.1.129:8003 backup ;}# 配置基于ip的虚拟主机server {listen 8552 ssl ;server_name 11.xx.18.xx;ssl_certificate /usr/local/nginx/conf/ssl/approbe.pem;ssl_certificate_key /usr/local/nginx/conf/ssl/approbe.key.unsecure;keepalive_timeout 70;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;ssl_session_cache shared:SSL:10m;ssl_session_timeout 10m;location /rest/softprobe {proxy_pass http://routerzhouqishangbao;#proxy_set_header Host $host;#proxy_set_header X-Real-IP $remote_addr;#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#proxy_set_header X-Forwarded-Proto $scheme;#proxy_set_header Host $host:$server_port;#proxy_intercept_errors on;#index index.html index.htm index.jsp default.jsp index.do default.do;#root /usr/local/nginx/html/;#index index.html;}}
四.测试
# 注意访问权限curl -k --tlsv1 "https://10.21.xx.10:8552/"# 查看QPS状态awk -F "- -" '{print $2}' access.log|cut -c 3-23|sort|uniq -c|sort -n -r|head -2001399 22/Feb/2022:15:35:551397 22/Feb/2022:14:21:031367 22/Feb/2022:16:07:161315 22/Feb/2022:17:03:101290 22/Feb/2022:16:43:501279 22/Feb/2022:15:32:251252 22/Feb/2022:15:06:121251 22/Feb/2022:14:21:041234 22/Feb/2022:16:16:411220 22/Feb/2022:14:21:051218 22/Feb/2022:16:11:111170 22/Feb/2022:14:59:261160 22/Feb/2022:16:44:521158 22/Feb/2022:15:53:001125 22/Feb/2022:14:15:47
