共计 4700 个字符,预计需要花费 12 分钟才能阅读完成。
一. 安装 Tomcat 和 jdk
1. 安装 jdk
# tar xvf jdk1.6.0_11.tar
# mv jdk1.6.0_11 /usr/local/
配置环境变量
# vim /etc/profile 添加
JAVA_HOME=/usr/local/jdk1.6.0_11
export JAVA_HOME
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
下面的可能更全面一些
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib:$JAVA_HOME/jre/bin
export CLASSPATH
PATH=$JAVA_HOME/bin:$PATH
export PATH
# sourse /etc/profile
# echo $JAVA_HOME
/usr/local/jdk1.6.0_11
二、设置 jdk 环境变量
vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.6.0_45
export CLASSPATH=$JAVA_HOME/jre/lib:$JAVA_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin
然后保存退出, 使环境变量生效
source /etc/profile
java -version
2. 安装 tomcat
# tar zxvf apache-tomcat-6.0.29.tar.gz
# mv apache-tomcat-6.0.29 /usr/local/tomcat6
3. 启动 tomcat
# /usr/local/tomcat6/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat6
Using CATALINA_HOME: /usr/local/tomcat6
Using CATALINA_TMPDIR: /usr/local/tomcat6/temp
Using JRE_HOME: /usr/local/jdk1.6.0_11
# ps aux | grep tomcat
root 12717 0.5 12.3 220452 31588 pts/0 Sl 19:24 0:02 /usr/local/jdk1.6.0_11/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/usr/local/tomcat6/conf/logging.properties -Djava.endorsed.dirs=/usr/local/tomcat6/endorsed -classpath :/usr/local/tomcat6/bin/bootstrap.jar -Dcatalina.base=/usr/local/tomcat6 -Dcatalina.home=/usr/local/tomcat6 -Djava.io.tmpdir=/usr/local/tomcat6/temp org.apache.catalina.startup.Bootstrap start
root 13187 0.0 0.2 5072 708 pts/0 R+ 19:31 0:00 grep tomcat
启动成功!
4. 访问测试
http://192.168.2.150:8080
会看到 tomcat 的主页
5. 修改配置文件
# pwd
/usr/local/tomcat6/conf
# vim server.xml
<Connector port=”8080″ protocol=”HTTP/1.1″ 端口设置
<Host name=”localhost” appBase=”webapps” 家目录,页面文件要放在 webapps/ROOT 下面
将家目录改成 /www/web/
<Host name=”localhost” appBase=”/www/web”
# mkdir -p /www/web/ROOT
# vim /www/web/ROOT/index.jsp
Hello,tomcat home!
重启 tomcat, 再次访问
改变访问
改变家目录的访问默认文件
# vim web.xml
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
二.nginx 安装配置
1. 安装支持正则的 pcre 模块
# rpm -ivh pcre-devel-6.6-2.el5_1.7.i386.rpm
yum –y install pcre*
yum -y install zlib*
yum -y install openssl*
2. 安装 nginx
# tar zxvf nginx-0.7.62.tar.gz
# cd nginx-0.7.62
# ./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module
# make
# make install
3. 启动 nginx
# /usr/local/nginx/sbin/nginx
4. 访问 nginx(默认为 80 端口)
http://192.168.2.150
三.nginx 与 tomcat 整合
1. 在 /usr/local/nginx/conf 下面添加文件 proxy.conf
# cat /usr/local/nginx/confg/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. 配置 nginx.conf
# cat /usr/local/nginx/confg/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 /usr/local/nginx/conf/proxy.conf; #一定要指向代理文件
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
charset gb2312;
location / {
root /www/web/ROOT;
index index.html index.htm;
}
location ~ .*.jsp$ {#匹配以 jsp 结尾的,tomcat 的网页文件是以 jsp 结尾
index index.jsp;
proxy_pass http://127.0.0.1:8080; #主要在这里,设置一个代理
}
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;
}
}
}
3. 测试
在 /www/web/ROOT 下添加文件 index.html
# cat index.html
the port:80
重启 nginx
/usr/local/nginx/sbin/nginx -s reload
检测配置
/usr/local/nginx/sbin/nginx -t
http://192.168.2.150
http://192.168.2.150:8080
http://192.168.2.150/index.jsp
更多 Tomcat 相关教程见以下内容:
CentOS 6.6 下安装配置 Tomcat 环境 http://www.linuxidc.com/Linux/2015-08/122234.htm
RedHat Linux 5.5 安装 JDK+Tomcat 并部署 Java 项目 http://www.linuxidc.com/Linux/2015-02/113528.htm
Tomcat 权威指南(第二版)(中英高清 PDF 版 + 带书签) http://www.linuxidc.com/Linux/2015-02/113062.htm
Tomcat 安全配置与性能优化 http://www.linuxidc.com/Linux/2015-02/113060.htm
Linux 下使用 Xshell 查看 Tomcat 实时日志中文乱码解决方案 http://www.linuxidc.com/Linux/2015-01/112395.htm
CentOS 64-bit 下安装 JDK 和 Tomcat 并设置 Tomcat 开机启动操作步骤 http://www.linuxidc.com/Linux/2015-01/111485.htm
CentOS 6.5 下安装 Tomcat http://www.linuxidc.com/Linux/2015-01/111415.htm
Tomcat 中 session 的管理机制 http://www.linuxidc.com/Linux/2016-09/135072.htm
Tomcat 的详细介绍:请点这里
Tomcat 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-04/143020.htm