一、安装环境包
首先使用yum命令安装、升级所需的程序库。
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-server krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
二、安装nginx
Nginx的安装方法:
http:[email protected]/blog/static/424111452011112102447696/
三.安装jdk
1、安装jdk。
wget http://cds-esd.sun.com/ESD6/JSCDL/jdk/6u24-b07/jdk-6u24-linux-i586.bin?AuthParam=1301239661_e064c3c5e58eb26bc89c2d3e83aaff41&TicketId=B%2Fw2nByASltMSBdFOVNfkgPr&GroupName=CDS&FilePath=/ESD6/JSCDL/jdk/6u24-b07/jdk-6u24-linux-i586.bin&File=jdk-6u24-linux-i586.bin
如遇到权限问题不能下载,请在windows端下载后,上传到centos服务器。
下载完后,修改jdk-6u23-linux-i586.bin的文件属性为可执行,然后执行该程序安装
#chmod +x jdk-6u23-linux-i586.bin
#cd ./ jdk-6u23-linux-i586.bin
#mv jdk1.6.0_23 /usr/local/jdk
2、编辑profile文件 设置开机文件java开机执行环境文件
#vi /etc/profile
在文件的末尾增加如下内容
JAVA_HOME="/usr/local/jdk"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
PATH=".:$PATH:%JAVA_HOME/bin"
CATALINA_HOME="/usr/local/tomcat"
export JAVA_HOME CATALINA_HOME
保存并退出vi,执行以下命令使配置生效
#source /etc/profile
四、安装apache tomcat
1、下载apache tomcat并安装tomcat
#mkdir /www 建立网页根目录
#cp /usr/share/nginx/html/* /www/
#wget http://apache.etoak.com/tomcat/tomcat-7/v7.0.5-beta/bin/apache-tomcat-7.0.5.tar.gz
错误提示:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/catalina/startup/Bootstrap
有部分网友安装7.0后,由于类库不全,无法正常启动,可下载6.0.23版本即可
wget
http://dl.javaeye.com/topics/download/6a5e75ef-38b6-3c44-8890-a1de74544185
#tar zxvf apache-tomcat-6.0.23.tar.gz
#mv apache-tomcat-6.0.23 /usr/local/tomcat
#cp –rf /usr/local/tomcat/webapps/* /www/
2、配置tomcat的server.xml文件,并启动或停止tomcat
#vim /usr/local/tomcat/conf/server.xml
查找appBase=”webapps”,修改为appBase=”/www”,其中/www 即为网页的根目录。
安装完成后,启动tomcat,默认监听端口为8080
#/usr/local/tomcat/bin/startup.sh
停止tomcat可以使用以下命令:
#/usr/local/tomcat/bin/shutdown.sh
五、nginx与tomcat整合
Nginx与tomcat的整合其实就是只要配置好nginx.conf文件就可以了。
#vim /etc/nginx/nginx.conf //配置好的nginx.conf文件如下
worker_processes 8;
pid /usr/local/webserver/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
upstream tomcat_server {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name _;
charset utf-8;
root /www;
location / {
index index.html index.htm index.jsp index.do default.jsp default.do index.php;
}
if (-d $request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
location ~ .(jsp|jspx|do)?$ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://tomcat_server;
}
location ~ .*.(php|php5)?$ {
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 1h;
}
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
}
}
六、测试
启动nginx
#service nginx restart
Nginx启动后,可以访问以下URL中的jsp实例程序,检查jsp程序能否运行。
http://localhost/examples/jsp/
注意:nginx与tomcat的工作原理是由nginx代理tomcat输出网页,因此如果开启了防火墙,防火墙不用打开8080端口,也一样可以访问jsp页面。