当前位置:   article > 正文

nginx+springboot项目的集群部署_springboot集群部署

springboot集群部署

(问题总结:

1.使用docker的nginx在配置vue 的dist包时与正常的路径不一样所以下面的路径要修改为:

location / {

#这个是docker中nginx的路径,因为我们是做的配置文件映射,所以我们这里面配置的地址都要基于docker中的真实路径
            root   /usr/share/nginx/html/dist;
            try_files $uri $uri/ =404;
            index  index.html ;
        }

2.集群部署时遇到了一个文件服务器的问题,因为当前项目文件的上传是与服务代码同体的,所以集群部署的话会出现无法下载文件的情况。

  解:解决这个问题可以使用集群部署后台程序所在的服务器,实现磁盘共享,这样就可以实现文件的统一(可以在不同后台服务获取到公共的文件资源)

)

 

本次集群部署的方案:

1.为了提高信息集成平台的并发能力,

2.为了提高平台高可用性

 

集群方案:

https://www.cnblogs.com/royal6/p/12149852.html

 

实现记录:

(压力测试优化)

本次负载均衡的策略是:

ip_hash

指定负载均衡器按照基于客户端IP的分配方式,这个方法确保了相同的客户端的请求一直发送到相同的服务器,以保证session会话。这样每个访客都固定访问一个后端服务器,可以解决session不能跨服务器的问题。

(使用该策略可以水平服务并发处理的能力,并保证原有websocket长连接的正确使用)

原配置文件:

 

  1. user root;
  2. #user nobody;
  3. worker_processes 1;
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7. #pid logs/nginx.pid;
  8. events {
  9. worker_connections 1024;
  10. }
  11. http {
  12. include mime.types;
  13. default_type application/octet-stream;
  14. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. # '$status $body_bytes_sent "$http_referer" '
  16. # '"$http_user_agent" "$http_x_forwarded_for"';
  17. #access_log logs/access.log main;
  18. sendfile on;
  19. #tcp_nopush on;
  20. #keepalive_timeout 0;
  21. keepalive_timeout 200;
  22. client_header_timeout 120s; #调大点
  23. client_body_timeout 120s; #调大点
  24. client_max_body_size 100m; #主要是这个参数,限制了上传文件大大小
  25. map $http_upgrade $connection_upgrade {
  26. default upgrade;
  27. '' close;
  28. }
  29. gzip on;
  30. gzip_buffers 4 16k;
  31. gzip_comp_level 5;
  32. gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
  33. server {
  34. listen 80;
  35. server_name 106.54.140.88;
  36. #charset koi8-r;
  37. #access_log logs/host.access.log main;
  38. location / {
  39. root html/dist;
  40. try_files $uri $uri/ /index.html;
  41. index index.html ;
  42. }
  43. location /websocket {
  44. proxy_pass http://106.54.140.88:8899/websocket;
  45. proxy_http_version 1.1;
  46. proxy_set_header Upgrade $http_upgrade;
  47. proxy_set_header Connection "upgrade";
  48. }
  49. location /ssoLogin {
  50. proxy_redirect off;
  51. proxy_set_header Host $host;
  52. proxy_set_header X-Real-IP $remote_addr;
  53. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  54. proxy_pass http://106.54.140.88:8899/ssoLogin;
  55. }
  56. location /xboot {
  57. proxy_redirect off;
  58. proxy_set_header Host $host;
  59. proxy_set_header X-Real-IP $remote_addr;
  60. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  61. proxy_pass http://106.54.140.88:8899/xboot;
  62. }
  63. location /loginTest {
  64. proxy_redirect off;
  65. proxy_set_header Host $host;
  66. proxy_set_header X-Real-IP $remote_addr;
  67. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  68. proxy_pass http://106.54.140.88:8899/loginTest;
  69. }
  70. location /hnPortalApp {
  71. proxy_redirect off;
  72. proxy_set_header Host $host;
  73. proxy_set_header X-Real-IP $remote_addr;
  74. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  75. proxy_pass http://106.54.140.88:8899/hnPortalApp;
  76. }
  77. location /qrcode {
  78. proxy_redirect off;
  79. proxy_set_header Host $host;
  80. proxy_set_header X-Real-IP $remote_addr;
  81. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  82. proxy_pass http://106.54.140.88:8899/qrcode;
  83. }
  84. #error_page 404 /404.html;
  85. # redirect server error pages to the static page /50x.html
  86. #
  87. error_page 500 502 503 504 /50x.html;
  88. location = /50x.html {
  89. root html;
  90. }
  91. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  92. #
  93. #location ~ \.php$ {
  94. # proxy_pass http://127.0.0.1;
  95. #}
  96. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  97. #
  98. #location ~ \.php$ {
  99. # root html;
  100. # fastcgi_pass 127.0.0.1:9000;
  101. # fastcgi_index index.php;
  102. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  103. # include fastcgi_params;
  104. #}
  105. # deny access to .htaccess files, if Apache's document root
  106. # concurs with nginx's one
  107. #
  108. #location ~ /\.ht {
  109. # deny all;
  110. #}
  111. }
  112. #测试转发单点接口
  113. server {
  114. listen 9797;
  115. server_name 10.39.5.120;
  116. location /portal/sso {
  117. proxy_redirect off;
  118. proxy_set_header Host $host;
  119. proxy_set_header X-Real-IP $remote_addr;
  120. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  121. proxy_pass http://10.39.5.120:9797/portal/sso;
  122. }
  123. }
  124. # another virtual host using mix of IP-, name-, and port-based configuration
  125. #
  126. #server {
  127. # listen 8000;
  128. # listen somename:8080;
  129. # server_name somename alias another.alias;
  130. # location / {
  131. # root html;
  132. # index index.html index.htm;
  133. # }
  134. #}
  135. # HTTPS server
  136. #
  137. #server {
  138. # listen 443 ssl;
  139. # server_name localhost;
  140. # ssl_certificate cert.pem;
  141. # ssl_certificate_key cert.key;
  142. # ssl_session_cache shared:SSL:1m;
  143. # ssl_session_timeout 5m;
  144. # ssl_ciphers HIGH:!aNULL:!MD5;
  145. # ssl_prefer_server_ciphers on;
  146. # location / {
  147. # root html;
  148. # index index.html index.htm;
  149. # }
  150. #}
  151. }

 

实现集群后的配置文件:

  1. user root;
  2. #user nobody;
  3. worker_processes 1;
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7. #pid logs/nginx.pid;
  8. events {
  9. worker_connections 1024;
  10. }
  11. http {
  12. include mime.types;
  13. default_type application/octet-stream;
  14. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. # '$status $body_bytes_sent "$http_referer" '
  16. # '"$http_user_agent" "$http_x_forwarded_for"';
  17. #access_log logs/access.log main;
  18. sendfile on;
  19. #tcp_nopush on;
  20. #keepalive_timeout 0;
  21. keepalive_timeout 200;
  22. client_header_timeout 120s; #调大点
  23. client_body_timeout 120s; #调大点
  24. client_max_body_size 100m; #主要是这个参数,限制了上传文件大大小
  25. map $http_upgrade $connection_upgrade {
  26. default upgrade;
  27. '' close;
  28. }
  29. gzip on;
  30. gzip_buffers 4 16k;
  31. gzip_comp_level 5;
  32. gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
  33. server {
  34. listen 80;
  35. server_name localhost;
  36. #charset koi8-r;
  37. #access_log logs/host.access.log main;
  38. location / {
  39. root html/dist;
  40. try_files $uri $uri/ /index.html;
  41. index index.html ;
  42. }
  43. location /websocket {
  44. proxy_pass http://server_list/websocket;
  45. proxy_http_version 1.1;
  46. proxy_set_header Upgrade $http_upgrade;
  47. proxy_set_header Connection "upgrade";
  48. }
  49. location /ssoLogin {
  50. proxy_redirect off;
  51. proxy_set_header Host $host;
  52. proxy_set_header X-Real-IP $remote_addr;
  53. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  54. proxy_pass http://server_list/ssoLogin;
  55. }
  56. location /xboot {
  57. proxy_redirect off;
  58. proxy_set_header Host $host;
  59. proxy_set_header X-Real-IP $remote_addr;
  60. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  61. proxy_pass http://server_list/xboot;
  62. }
  63. location /loginTest {
  64. proxy_redirect off;
  65. proxy_set_header Host $host;
  66. proxy_set_header X-Real-IP $remote_addr;
  67. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  68. proxy_pass http://server_list/loginTest;
  69. }
  70. location /hnPortalApp {
  71. proxy_redirect off;
  72. proxy_set_header Host $host;
  73. proxy_set_header X-Real-IP $remote_addr;
  74. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  75. proxy_pass http://server_list;
  76. }
  77. location /qrcode {
  78. proxy_redirect off;
  79. proxy_set_header Host $host;
  80. proxy_set_header X-Real-IP $remote_addr;
  81. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  82. proxy_pass http://server_list;
  83. }
  84. error_page 500 502 503 504 /50x.html;
  85. location = /50x.html {
  86. root html;
  87. }
  88. }
  89. upstream server_list{
  90. ip_hash;
  91. server 106.54.140.88:8899 weight=5;
  92. server 47.92.27.141:8899 weight=5;
  93. }
  94. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/57775
推荐阅读
相关标签
  

闽ICP备14008679号