nginx+多tomcat 集成 二(nginx tomcat jdk 软件安装)

[size=medium]
 
1 安装 jdk
首先卸载默认的jdk1.42
rpm -qa | grep gcj                                           
libgcj-devel-3.4.6-3
java-1.4.2-gcj-compat-1.4.2.0-27jpp              
libgcj-3.4.6-3


# yum -y remove java-1.4.2-gcj-compat


2 下载jdk
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

或者
wget http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.tar.gz

赋予可执行权限
[root@localhost soft]# chmod +x jdk-6u11-linux-i586.bin

解压
[root@localhost soft]# ./jdk-6u11-linux-i586.bin

Java(TM) SE Development Kit 6 successfully installed.
.........
Press Enter to continue.....
Done.


编辑环境变量文件
[root@localhost jdk1.6.0_11]# vi /etc/profile

设置生效
[root@localhost local]# source /etc/profile


[root@localhost local]# java -version
java version “1.6.0_11″
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)



3:安装tomcat
   Tomcat:
 apache-tomcat-6.0.35.tar.gz
   安装命令:
tar xvzf apache-tomcat-6.0.35.tar.gz (解压到了当前目录)
             mv tomcat(源)  /usr/local/tomcat(目) ---移到目标目录
   常用命令:
     起动:bin/startup.sh
      关闭:bin/shutdown.sh
   测试:
127.0.0.1:8080是否出现tomcat信息页面



安装完成tomcat之后 新建一个web站点,
配置过程如下

cd apache-tomcat-6.035
mkdir www
cp -r /webapps/ROOT www
vim /conf/server.xml


修改 其站点设置
<Host name="localhost" appBase="www" unpackWARs="true" autoDeploy="true"
   xmlValidation="false" xmlNamespaceAware="false">

修改 www/ROOT/index.html 内容



4 修改nginx.conf

#user  www www;
worker_processes  1;
pid     /usr/local/nginx/logs/nginx.pid;
events {
    use epoll;
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    include     proxy.conf;  #一定要指向代理文件
    sendfile        on;
    tcp_nopush      on;
    keepalive_timeout  65;
    upstream tomcats{
       server 127.0.0.1:8080;
    }

    server{
     listen   80;
     server_name   localhost;
     location /{
       proxy_pass  http://tomcats; # 反向到tomcat
     }
   }
    server {
        listen       8081;
        server_name  localhost;
        charset gb2312;
        location / {
             root test_space;
             index  index.html index.htm;
        }
        location ~ .*.jsp$ {     #匹配以jsp结尾的,tomcat的网页文件是以jsp结尾         
                index   index.jsp;
                proxy_pass  http://tomcats; #主要在这里,设置一个代理 proxy to tomcat prot
        }
        location /nginxstatus {
#                stub_status on;
                access_log on;
                auth_basic "nginxstatus";
                auth_basic_user_file /usr/local/nagois/etc/htpasswd.users;
        }
        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}




在nginx.conf文件路径下 新建代理文件域 proxy.conf,这个代理文件域被引入nginx.conf
proxy_connect_timeout 300s;
proxy_send_timeout   900;
proxy_read_timeout   900;
proxy_buffer_size    32k;
proxy_buffers     4 32k;
proxy_busy_buffers_size 64k;
proxy_redirect     off;
proxy_hide_header  Vary;
proxy_set_header   Accept-Encoding '';
proxy_set_header   Host   $host;
proxy_set_header   Referer $http_referer;
proxy_set_header   Cookie $http_cookie;
proxy_set_header   X-Real-IP  $remote_addr;
proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
#后端的Web服务器可以通过X-Forwarded-For获取用户真实IP



之后访问 http://127.0.0.1/   和  http://127.0.0.1/ 是同一页面

明天的计划是配置 多个tomcat


5 配置多个tomcat

copy 第一个tomcat 到 第二个tomcat

cp -r apache-tomcat-6.0.35 apache-tomcat-6.0.36

在/etc/profile 文件末尾添加 如下内容

CATALINA_2_BASE=/usr/local/apache-tomcat-6.0.36
CATALINA_2_HOME=/usr/local/apache-tomcat-6.0.36
TOMCAT_2_HOME=/usr/local/apache-tomcat-6.0.36
export CATALINA_2_BASE CATALINA_2_HOME TOMCAT_2_HOME

在apache-tomcat-6.0.36/bin/catalina.sh文件顶部添加如下内容

export JAVA_HOME=/usr/local/jdk1.6.0_41
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/lib
export CATALINA_HOME=$CATALINA_2_HOME
export CATALINA_BASE=$CATALINA_2_BASE

修改tomcat2/conf/server.xml文件
   修改三个监听端口
<Server port="8005" shutdown="SHUTDOWN">改成<Server port="9005" shutdown="SHUTDOWN">

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
改成
<Connector port="9080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
改成
<Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />

启动这两个 tomcat 
bin/startup.sh



修改 nginx.conf 配置文件  文件修改如下


#user  www www;
worker_processes  1;
pid     /usr/local/nginx/logs/nginx.pid;
events {
    use epoll;
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    include     proxy.conf;  #一定要指向代理文件
    sendfile        on;
    tcp_nopush      on;
    keepalive_timeout  65;

    upstream www.server80.com{
       server 127.0.0.1:8080 weight=1;
       server 127.0.0.1:9080 weight=1;
    }

    server {
     listen   8081;
     server_name   www.server80.com;
     location /{
       index  index.html  index.jsp index.htm;
       proxy_redirect off;
       proxy_set_header Host $host; #这一句至关重要
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_pass  http://www.server80.com; # to tomcat
     }
     #图片的访问转发给Squid
       location  ~* .*\.(gif|png|jpg|jpeg|bmp|swf)$ {
            proxy_pass http://www.server80.com;
    
       }
    error_page   500 502 503 504 /50x.html;
        location = /50x.html {
            root   html;
        }
   }

      #新加的虚拟机
      server {
         listen       8082;
        server_name www.server80.com; 
	location / {
	      #	root   html;
		index index.jsp index.html index.htm;
		proxy_redirect off;
		proxy_set_header Host $host; #这一句至关重要
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://www.server80.com;
	}
       
         #图片的访问转发给Squid
           location  ~* .*\.(gif|png|jpg|jpeg|bmp|swf)$ {
              proxy_pass http://www.server80.com; 
          }
         error_page   500 502 503 504 /50x.html;
       		location = /50x.html {
     		root   html;
	}

     }



    server {
        listen       8083;
        server_name  www.server80.com;
        charset gb2312;
        location / {
             index index.jsp index.html index.htm;
             proxy_redirect off;
             proxy_set_header Host $host; #这一句至关重要
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_pass http://www.server80.com;
             index  index.html index.htm;
        }
        #图片的访问转发给Squid
        location  ~* .*\.(gif|png|jpg|jpeg|bmp|swf)$ {
             proxy_pass http://www.server80.com;
        }
          
        location ~ .*.jsp$ {     #匹配以jsp结尾的,tomcat的网页文件是以jsp结尾         
                index   index.jsp;
                proxy_pass  http://www.server80.com; #主要在这里,设置一个代理 proxy to tomcat prot
        }
        location /nginxstatus {
#                stub_status on;
                access_log on;
                auth_basic "nginxstatus";
                auth_basic_user_file /usr/local/nagois/etc/htpasswd.users;
        }
        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}




6 字/etc/hosts 文件追加 www.server80.com域名

测试访问 www.server80.com 将以轮询的方式 访问两个tomcat




java web应用的部署
把web应用在eclipse里面export成war包文件并复制到tomcat/wabapps目录下
将被引用的项目的文件夹也考到tomcat/wabapps目录下
关闭后再次启动tomcat
访问时输入http://ip地址:8088/war文件名称/....
例如war文件名为wapinfo.war
则输入http://ip地址:8088/wapinfo/....
进行访问
为方便管理项目,可以修改/root/apache-tomcat-6.0.33/conf/tomcat-users.xml文件,在最后加上
<role rolename="manager"/>
<role rolename="admin"/>
<user username="admin" password="123456" roles="admin,manager"/>
点击tomcat欢迎页中左上角Tomcat Manager链接,输入admin,123456后可以查看正在运行的应用.

[/size]

你可能感兴趣的:(tomcat)