#================================ 1、安装tomcat、JDK =================================
mv apache-tomcat-6.0.33.tar.gz jdk-6u25-linux-i586.bin /usr/local/
tar -zxvf apache-tomcat-6.0.32.tar.gz
mv apache-tomcat-6.0.33 tomcat
chmod +x jdk-6u25-linux-i586.bin
./jdk-6u25-linux-i586.bin
tar -zxvf apr-1.4.2.tar.gz
cd apr-1.4.2
./configure
make
make install
cd ..
tar -zxvf apr-util-1.3.9.tar.gz
cd apr-util-1.3.9
./configure --with-apr=/usr/local/apr/
make
make install
cd ../
cp tomcat-native-1.1.20-src.tar.gz /usr/local/tomcat/bin/
cd /usr/local/tomcat/bin/
tar -zxvf tomcat-native.tar.gz
cd ./tomcat-native-1.1.12-src/jni/native/
./configure --with-apr=/usr/local/apr --with-java-home=/usr/local/jdk1.6.0_25
make;make install
#设置环境变量
cat >>/etc/profile<<EOF
export JAVA_HOME=/usr/local/jdk1.6.0_25
export CLASS_PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=.:$PATH:$JAVA_HOME/bin
export CATALINA_HOME=/usr/local/tomcat
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
EOF
source /etc/profile
#查看java版本
java -version
#启动tomcat
/usr/local/tomcat/bin/startup.sh
echo "/usr/local/tomcat/bin/startup.sh" >> /etc/rc.local
#http://localhost:8080,如果看到猫的页面即tomcat和jdk安装成功
#新建文件目录/data/www为网站存放目录,设置server.xml文件,在Host name="localhost"处将appBase=的指向路径改为/data/www,创建index.jsp至/data/www/ROOT,内容为:“My web!”
#修改tomcat网站目录
#sed -i 's#appBase="webapps"#appBase="/data/www/test"#' /usr/local/tomcat/conf/server.xml
#报错信息:java.lang.IllegalArgumentException: Document base /data/www/truboshop/host-manager does not exist or is not a readable directory
#解决方法:删除conf\Catalina\localhost目录下面的host-manager.xml、manager.xml两个文件
#============================= 2、安装Nginx =============================
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www -s /sbin/nologin
mkdir -p /data/www
chmod +w /data/www
chown -R www:www /data/www
tar zxvf pcre-8.12.tar.gz
cd pcre-8.12/
./configure
make;make install
cd ../
#使用Tcmalloc 优化nginx、mysql
wget http://google-perftools.googlecode.com/files/google-perftools-1.7.tar.gz
tar -zxvf google-perftools-1.7.tar.gz
cd google-perftools-1.7/
./configure --enable-frame-pointers
make;make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
cd ../
tar zxvf nginx-1.0.0.tar.gz
cd nginx-1.0.0
./configure --user=www --group=www --prefix=/usr/local/nginx \
--with-http_stub_status_module --with-http_ssl_module \
--with-http_flv_module --with-http_gzip_static_module \
--with-google_perftools_module
如果报错 解决办法yum -y install openssl openssl-devel
make;make install
mkdir -p /data/logs
chmod +w /data/logs
chown -R www:www /data/logs
#编辑nginx.config
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
vim /usr/local/nginx/conf/nginx.conf
#运行nginx所在的用户名和用户组
user www www;
#启动进程数
worker_processes 8;
#全局错误日志及PID文件
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
#工作模式及连接数上限
events
{
use epoll;
worker_connections 65535;
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http
{
#设定mime类型
include mime.types;
default_type application/octet-stream;
# include /usr/local/nginx/conf/proxy.conf;
#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;
###禁止通过ip访问站点
#server{
# server_name _;
# return 404;
# }
#
server
{
listen 80;
server_name localhost;
index index.html index.htm index.jsp;#设定访问的默认首页地址
root /data/www/ROOT;#设定网站的资源存放路径
#limit_conn crawler 20;
location ~ .*.jsp$ #所有jsp的页面均交由tomcat处理
{
index index.jsp;
proxy_pass http://localhost:8080;#转向tomcat处理
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ #设定访问静态文件直接读取不经过tomcat
{
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';
access_log /usr/local/nginx/logs/localhost.log access;#设定访问日志的存放路径
}
}
/usr/local/nginx/sbin/nginx -t
显示以下信息为正确的
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
启动 nginx /usr/local/nginx/sbin/nginx
停止 /usr/local/nginx/sbin/nginx -s stop
查看Nginx主进程号:ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
21739
kill -HUP 21739
或者无需这么麻烦,找到Nginx的Pid文件:
vi /data/www/ROOT/index.jsp
<html>
<body>
<h1>JSP Test</h1>
<%=new java.util.Date()%>
</body>
</html>
nginx启动好后启动tomcat,此时输入http://主机ip地址即可看到 时间显示成功
本文出自 “ganlou0089.com” 博客,谢绝转载!