nginx与tomcat的简单集群

本文详细介绍了如何配置多个tomcat服务器并利用nginx实现负载均衡的集群。首先,调整各tomcat的端口以避免冲突,然后配置nginx,设置upstream进行负载分配。重点在于nginx的配置,包括worker_processes、events、http模块以及location等关键部分。此外,还提到了nginx的启动、关闭和重启命令,以及注意事项,如pid文件的设置和避免直接双击nginx.exe启动。最后讨论了当一台tomcat宕机时,如何通过max_fails和fail_timeout参数提高nginx的响应和处理能力。
摘要由CSDN通过智能技术生成

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

工具:nginx-1.13.9和多个apache-tomcat-9.0.0.M9(解压版)nginx下载地址:https://nginx.org/en/download.html

 

一.多个tomcat的配置

先看安装版的界面:

从这可以看出需要免安装版的tomcat里面需要设置的主要是server  shutdown port(8005)  和 http/1.1  Connector Port (8080)和AJP/1.3 Connector Port(8009)等三个参数及windows  Service Name tomcat服务器名称(对应免安装版的D:\nginx\tomcat\apache-tomcat-9.0.0.M91目录里的名字apache-tomcat-9.0.0.M91),主要是这四个参数。上面截图参数是默认参数。

 

故看看下面免安装版的注意点:

解压多个tomcat名字命名不一样。tomcat里面的设置点:

 

A.修改Tomcat的conf目录下的server.xml,修改这多个Tomcat的启动端口,分别为18080和28080等。

 

需要修改的是下面三处:蓝色的端口号(关闭,启动,?)

<Server port="28005" shutdown="SHUTDOWN">

    <Connector port="28080" protocol="HTTP/1.1"
               connectionTimeout="20000"

               redirectPort="8443" />

<Connector port="28009" protocol="AJP/1.3" redirectPort="8443" />

 

B.在startup.bat里面开头部分设置JAVA_HOME和CATALINA_HOME

SET JAVA_HOME=D:\software\jdk1.8

SET CATALINA_HOME=D:\nginx\tomcat\apache-tomcat-9.0.0.M91
@echo off

然后启动并访问tomcat首页,看是不是能正常启动,

三个tomcat启动后截图:

这样三个tomcat能正常启动了。

注意点:tomcat启动报错:1.端口号问题2.配置环境问题

The JRE_HOME environment variable is not defined correctly(报错了)原因:Set JAVA_HOME or JRE_HOME if not already set and ensure any provided(设置了多个JAVA_HOME)

二,nginx的简单配置

nginxconf的原始代码:



#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;


    #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;


    server {
        listen       80;
        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {
            root   html;
            index  index.html index.htm;
        }


        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}


        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }




    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值