ubuntu 12.04下编译安装nginx-1.9.3之后 tomcat集群

   一、tomcat安装

  1.安装nginx 请查看http://blog.csdn.net/liangzi4454/article/details/47023447

   2. jdk安装不在赘述,不会的同学,可以网上查找教程;

   3. tomcat下载

       本人tomcat版本为 tomcat-6.0.44,请自行到官网下载对应的版本或是在终端输入 wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-6/v6.0.44/bin/apache-tomcat-6.0.44.tar.gz 下载。

   4.tomcat安装

      创建/usr/local/tomcat-6.0.44_1和/usr/local/tomcat-6.0.44_2目录,并将tomcat解压两份到这两个目录中。

   5.修改/usr/local/tomcat-6.0.44_2/conf/server.xml 中的三个端口8005为8015,8080为8090,8009为8019。

   6.在以上两个tomcat目录的webapps下创建ROOT/a/index.jsp,启动tomcat ,浏览器输入http://localhost:8080/a/index.jsp和http://localhost:8090/a/index.jsp 见到index页面,说明安装成功。

  6.增加tomcat内存

     打开/bin/catalina.sh 顶部加入JAVA_OPTS="-server -Xms800m -Xmx800m -XX:PermSize=64M -XX:MaxNewSize=256m -XX:MaxPermSize=128m -Djava.awt.headless=true"

   二、nginx与单个tomcat集群

   1. 在/usr/local/nginx/conf/目录下创建proxy.conf文件,加入内容保存退出:

   #!nginx (-)
   # proxy.conf
   proxy_redirect          off;
   proxy_set_header        Host $host;
   proxy_set_header        X-Real-IP $remote_addr;  #获取真实ip
   # proxy_set_header       X-Forwarded-For   $proxy_add_x_forwarded_for; #获取代理者的真实ip
   client_max_body_size    10m;
   client_body_buffer_size 128k;
   proxy_connect_timeout   90;
   proxy_send_timeout      90;
   proxy_read_timeout      90;
   proxy_buffer_size       4k;
   proxy_buffers           4 32k;
   proxy_busy_buffers_size 64k;
   proxy_temp_file_write_size 64k;

    2.在根目录下创建/home/www/root1/ROOT和/home/www/root1/ROOT目录,并将刚才tomcat中创建的index.jsp放到该目录下

    3.修改两个tomcat的server.xml如下,将第2不创建的两个目录加入到appBase中:

      <Host name="localhost"  appBase="/home/www/root1"
            xmlValidation="false" xmlNamespaceAware="false">

    4.打开/usr/local/nginx/nginx.conf 文件,修改内容并退出:

     # 运行nginx所在的用户名和用户组
    user nginx nginx; #新增
    #user  nobody;
    worker_processes  1;
# 全局错误日志及PID文件
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
error_log   /usr/local/nginx/logs/error.log; #新增


# pid        logs/nginx.pid;
pid         /usr/local/nginx/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;
    access_log  /usr/local/nginx/logs/access.log; #新增
    sendfile        on;
    #tcp_nopush     on;


    #keepalive_timeout  0;
    keepalive_timeout  65;


    #gzip  on;


    server {
        listen       80;
        server_name  localhost;


        root   /home/www/root1/ROOT; #新增 网站根目录        


        #charset koi8-r;
        access_log  /usr/local/nginx/logs/host.access.log; #新增
        #access_log  logs/host.access.log  main;


        location / {
           # 下边两行暂时注掉
           # root   html;
           # index  index.html index.htm;
           # 新增 将index.jsp 加入到默认的访问首页地址
           index  index.html index.htm index.jsp;
           #转向tomcat处理
           proxy_pass http://localhost:8080;
        }
        #新增 所有jsp的页面均交由tomcat处理
        location ~ .*.jsp$ {
            index index.jsp;
            proxy_pass http://localhost:8080;
        }
        #新增 设定访问静态文件直接读取不经过tomcat
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
            expires 30d;
        }
        #新增
        location ~ .*\.(js|css)?$ {
            expires 1h;
        }


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


}

   5.测试nginx配置

终端执行如下命令:

/usr/local/nginx/sbin/nginx-t

出现如下信息表示失败:

nginx: [emerg] getpwnam("nginx") failed in /usr/local/nginx/conf/nginx.conf:2
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

解决办法: 添加用户组

  终端执行如下命令:

sudo adduser --system --no-create-home --disabled-password --group nginx

再次测试nginx 出现如下信息表示成功:

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

6.启动nginx后启动tomcat

终端执行如下两条命令:

/etc/init.d/nginx start

/usr/local/tomcat-6.0.44_1/bin/catalina.sh start

7. 测试

浏览器中输入http://localhost:8080看到index.jsp信息表示nginx和单个tomcat集群建立成功


三、建立nginx和多个tomcat集群

未完待续。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值