系统环境
[root@localhost ~]# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.9 (Final)
Release: 5.9
Codename: Final
软件版本
tomcat 6.0.18
jre 1.6_u45
nginx(tengine) 2.02
Tomcat和JRE软件安装配置
具体多个tomcat配置过程(暂时两个,后期如需增加按此配置即可)
1.配置第二个tomcat主目录
[root@localhost opt]# cp -r apache-tomcat-6.0.18 apache-tomcat2-6.0.18
[root@localhost opt]# ln -s apache-tomcat2-6.0.18 tomcat2
2.配置第二个tomcat的环境变更
[root@localhost opt]# cd /etc/profile.d/
[root@localhost profile.d]# cp tomcat.sh tomcat2.sh
[root@localhost profile.d]# vim tomcat2.sh
export TOMCAT_2_HOME=/opt/tomcat2
export CATALINA_2_HOME=/opt/tomcat2
export CATALINA_2_BASE=/opt/tomcat2
export CATALINA_2_TMPDIR=/opt/tomcat2/temp
使第二个环境变量生效
[root@localhost profile.d]# source /etc/profile
3.修改第二个tomcat的server.xml配置文件的端口号
[root@localhost conf]# cd /opt/tomcat2/conf/
[root@localhost conf]# vim server.xml
主要修改以下三个地方的端口号,与第一个tomcat默认的8005、8080、8009端口号不同即可
8006" shutdown="SHUTDOWN">
8081" protocol="HTTP/1.1"
connectionTimeout="20000" redirectPort="8443" />
8010" protocol="AJP/1.3" redirectPort="8443" />
3.配置第二个tomcat的启动脚本
[root@localhost conf]# cp /opt/tomcat/bin/catalina.sh /etc/init.d/tomcat2
[root@localhost conf]# vim /etc/init.d/tomcat2
执行以下操作将启动脚本中的环境变量替换成tomcat2的环境变量
:%s/CATALINA_HOME/CATALINA_2_HOME/gc
:%s/CATALINA_BASE/CATALINA_2_BASE/gc
:%s/CATALINA_TMPDIR/CATALINA_2_TMPDIR/gc
:wq
4.启动两个tomcat
[root@localhost ~]# /etc/init.d/tomcat start
Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME: /opt/jre
[root@localhost ~]# /etc/init.d/tomcat2 start
Using CATALINA_2_BASE: /opt/tomcat2
Using CATALINA_2_HOME: /opt/tomcat2
Using CATALINA_2_TMPDIR: /opt/tomcat2/temp
Using JRE_HOME: /opt/jre
[root@localhost ~]# netstat -ntpul | grep 80
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 3086/java
tcp 0 0 ::ffff:127.0.0.1:8006 :::* LISTEN 3110/java
tcp 0 0 :::8009 :::* LISTEN 3086/java
tcp 0 0 :::8010 :::* LISTEN 3110/java
tcp 0 0 :::8080 :::* LISTEN 3086/java
tcp 0 0 :::8081 :::* LISTEN 3110/java
通过以上检查,可确定两个tomcat都已成功启动
为达到更直观的效果,可修改两个tomcat目录下webapps/ROOT/index.html文件,修改title即可
Apache Tomcat1
修改后再重启动两个tomcat,通过浏览器访问,效果如下
配置nginx负载均衡(tengine)
[root@localhost ~]# cd /opt/tengine/conf/
[root@localhost conf]# vim web.conf
upstream backend {
ip_hash;
session_sticky;
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
server {
listen 80;
server_name localhost;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend;
}
}
[root@localhost conf]# vim nginx.conf
在http {} 中添加
include web.conf;
再重启nginx(tengine)服务即可
阅读(1731) | 评论(0) | 转发(0) |