一、實驗規划
haproxy
通過8080端口轉到192.168.200.113的22端口,通過xshell登錄
通過8090端口轉到192.168.200.114的22端口,通過xshell登錄
nginx
通過8001端口轉到192.168.200.113的22端口,通過xshell登錄
通過8002端口轉到192.168.200.114的22端口,通過xshell登錄
二、nginx配置(nginx使用9以上的版本)
#直接使用yum安裝,如果使用源碼安裝編譯時加上 --with-stream yum -y instsll nginx #配置nginx vim /etc/nginx/nginx.conf stream { server { listen 8001; proxy_connect_timeout 10s; proxy_timeout 5s; #連接保持5秒 proxy_pass 192.168.200.113:22; } server { listen 8002; proxy_connect_timeout 10s; proxy_timeout 5s; #連接保持5秒 proxy_pass 192.168.200.114:22; } } http 段上面配置
三、haproxy配置
#安裝haproxy yum -y instsll haproxy #配置haproxy vim /etc/haproxy/haproxy.cfg global #全局參數 log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon stats socket /var/lib/haproxy/stats defaults #默認的配置 mode tcp #采用tcp四層的協議 log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch 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 3000 ########113配置################# listen ssh113 bind 0.0.0.0:8080 mode tcp balance roundrobin server s1 192.168.200.113:22 weight 1 maxconn 10000 check inter 10s ########114配置################# listen ssh114 bind 0.0.0.0:8090 mode tcp balance roundrobin server s2 192.168.200.114:22 weight 1 maxconn 10000 check inter 10s
四、測試
haproxy
nginx