使用nginx進行負載均衡 mysql mq
阿新 • • 發佈:2022-03-15
配置檔案:
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #單個ip的併發數 limit_conn_zone $binary_remote_addr zone=addr:10M; #服務的總併發數 limit_conn_zone $server_name zone=persever:10M; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream cms { server 127.0.0.1:8082; } upstream c3m { server 127.0.0.1:8084; } upstream vgs { server127.0.0.1:8083; } upstream alarm { server 127.0.0.1:8085; } upstream video { server 127.0.0.1:8086; } upstream api { server 127.0.0.1:8088; } upstream deploy { server 127.0.0.1:8098; } upstream website { server 127.0.0.1:8090; } server { listen 8080; server_name localhost; location / { root D:/temp/dist; index index.html; } location /download { proxy_set_header Host $host:$server_port; proxy_pass http://website/health_website/fsuinfo/download3000; } # 2000系列主機216版本之後,採用的下載安裝的方法 location ^~ /FSU { proxy_set_header Host $host:$server_port; proxy_pass http://website/health_website/fsuinfo/download2160/; } location /api/c3m { proxy_set_header X-real-ip $remote_addr; proxy_pass http://c3m/services-c3m; } location /services/ { proxy_set_header Host $host:$server_port; proxy_pass http://c3m/services/; } location /services/recordingReplenish/ { proxy_pass http://vgs/services-vgs/recordingReplenish/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 7200s; proxy_send_timeout 8s; } location /services/disk/ { proxy_pass http://vgs/services-vgs/disk/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 600s; proxy_send_timeout 8s; } location /services/recordConfig/ { proxy_pass http://vgs/services-vgs/recordConfig/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 1800s; proxy_send_timeout 8s; } location /services/dataSync/ { proxy_pass http://cms/services-cms/dataSync/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 1800s; proxy_send_timeout 8s; } location /services/videoDignoseMission/ { proxy_pass http://video/services-video/videoDignoseMission/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 300s; proxy_send_timeout 8s; } location /services/videoDignoseBackup/ { proxy_pass http://video/services-video/videoDignoseBackup/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 7200s; proxy_send_timeout 8s; } location /services/videoRest/ { proxy_pass http://video/services-video/videoRest/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 120s; proxy_send_timeout 8s; } location /services/filterData/ { proxy_pass http://alarm/services-alarm/filterData/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 1800s; proxy_send_timeout 8s; } location /services/alarmForward/ { proxy_pass http://alarm/services-alarm/alarmForward/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 1800s; proxy_send_timeout 8s; } location /services/syncConditionRedis/ { proxy_pass http://alarm/services-alarm/syncConditionRedis/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 120s; proxy_send_timeout 8s; } location /services/api/ { proxy_pass http://api/services-api/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 120s; proxy_send_timeout 8s; } location /services/networkEquipment/ { proxy_pass http://cms/services-cms/networkEquipment/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 1800s; proxy_send_timeout 8s; } location /auto/deploy/ { proxy_pass http://localhost:2122/auto/deploy/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 1800s; proxy_send_timeout 8s; } location /api/deploy/package/download/ { proxy_pass http://deploy/api/deploy/package/download/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 1800s; proxy_send_timeout 8s; proxy_max_temp_file_size 2000m; limit_conn addr 10; ##每個ip能發起的併發連線數 limit_conn persever 50; ##併發數量 limit_rate 200k; ##單個執行緒最大下載速度,單位kb/s } location /api/deploy/ { #配置當前ip 程式裡面獲取 proxy_set_header X-Local-Ip $host; #配置當前port 程式裡面獲取 proxy_set_header X-Local-Port $server_port; proxy_pass http://deploy/api/deploy/; proxy_redirect off; proxy_connect_timeout 4s; proxy_read_timeout 1800s; proxy_send_timeout 8s; } } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} } stream{ upstream mysql{ server 192.168.51.115:3306 weight=1; server 192.168.51.116:3306 weight=1; } server{ listen 3308; proxy_pass mysql; } upstream mq{ server 192.168.51.115:15672 weight=1; server 192.168.51.117:15672 weight=1; } server{ listen 15671; proxy_pass mq; } }
直接在 http 模組下面新增 stream模組即可
stream{ upstream mysql{ server 192.168.51.115:3306 weight=1; server 192.168.51.116:3306 weight=1; } server{ listen 3308; proxy_pass mysql; } upstream mq{ server 192.168.51.115:15672 weight=1; server 192.168.51.117:15672 weight=1; } server{ listen 15671; proxy_pass mq; } }