温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nginx+Tomcat怎么搭建高性能负载均衡集群

发布时间:2021-11-09 10:31:45 来源:亿速云 阅读:142 作者:柒染 栏目:建站服务器

这篇文章给大家介绍Nginx+Tomcat怎么搭建高性能负载均衡集群,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

小编准备将两套Tomcat 和一套nginx服务搭建在同一台服务器上。

二、    目标

  实现高性能负载均衡的Tomcat集群:

  Nginx+Tomcat怎么搭建高性能负载均衡集群



1、安装nginx

编译源码需要的组件


1.zlib   ngix 需要的lib库


2.pcre  nginx rewrite重写使用,支持正则表达式


3.openssl  支持安全协议的站点使用


1)介质下载
库下载地址:


源码下载地址 zlib 


http://www.zlib.net/


PCRE --支持正则表达式 


http://www.pcre.org/


opensll安装(可选), 支持安全协议的站点


http://www.openssl.org/


nginx 下载


http://nginx.org/en/download.html




2)上传介质到linux平台、并且解压
3)编译安装
4)修改配置文件




1.编译zlib


tar xvf zlib-1.2.8.tar.gz
./configure --static --prefix=/usr/local/libs/zlib
make
make install
2.编译openssl


tar xvf openssl-1.0.le.tar.gz
./config --prefix=/usr/local/openssl 
make
make install
3.编译pcre


tar xvf pcre-8.33.tar.gz
./configure --prefix=/usr/local/pcre 
make 
make install
4.编译ngnix


useradd nginx 


tar xvf nginx-1.5.4.tar.gz
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-debug --with-openssl=/soft/openssl-1.0.le --with-zlib=/soft/zlib-1.2.8 --with-pcre=/soft/pcre-8.33 --with-http_stub_status_module --with-http_gzip_static_module  --with-http_ssl_module
make 
make install


备注:--with-openssl --with-zlib --with-pcre这3个路径是他们对应的源码路径.




启动nginx服务
cd /usr/local/nginx
./nginx
查看nginx进程是否正常
ps -ef|grep nginx



2、安装tomcat

在tomcat官网下载tomcat介质

上传Linux服务器上解压并修改配置文件
[root@mysql tomcat]# pwd
/usr/local/tomcat

[root@mysql tomcat1]# pwd
/usr/local/tomcat1


修改tomcat配置文件


第一套tomcat

Nginx+Tomcat怎么搭建高性能负载均衡集群


第二套tomcat修改:

Nginx+Tomcat怎么搭建高性能负载均衡集群

启动两套tomcat

修改nginx配置文件

配置如下(这里只进行了简单的配置,实际生产环境可以进行更详细完善配置):

vi tomcat_fzjh.conf

[html] view plain copy

  1. worker_processes  1;#工作进程的个数,一般与计算机的cpu核数一致  

  2.   

  3. events {  

  4.     worker_connections  1024;#单个进程最大连接数(最大连接数=连接数*进程数)  

  5. }  

  6.   

  7. http {  

  8.     include       mime.types; #文件扩展名与文件类型映射表  

  9.     default_type  application/octet-stream;#默认文件类型  

  10.   

  11.     sendfile        on;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。  

  12.       

  13.     keepalive_timeout  65; #长连接超时时间,单位是秒  

  14.   

  15.     gzip  on;#启用Gizp压缩  

  16.       

  17.     #服务器的集群  

  18.     upstream  netitcast.com {  #服务器集群名字   

  19.         server    127.0.0.1:18080  weight=1;#服务器配置   weight是权重的意思,权重越大,分配的概率越大。  

  20.         server    127.0.0.1:28080  weight=2;  

  21.     }     

  22.   

  23.     #当前的Nginx的配置  

  24.     server {  

  25.         listen       80;#监听80端口,可以改成其他端口  

  26.         server_name  localhost;##############   当前服务的域名  

  27.   

  28.     location / {  

  29.             proxy_pass http://netitcast.com;  

  30.             proxy_redirect default;  

  31.         }  

  32.           

  33.   

  34.         error_page   500 502 503 504  /50x.html;  

  35.         location = /50x.html {  

  36.             root   html;  

  37.         }  

  38.     }  

  39. }  




启动nginx服务

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/config/tomcat_fzjh.conf

关于Nginx+Tomcat怎么搭建高性能负载均衡集群就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI