export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
保存并退出,重启机器,输入
# echo $PATH
查看是否识别jdk路径
# java -version
显示jdk当前版本
-------------------------------------------------------------------
安装Tomcat7
# cd /home/java
# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.78/bin/apache-tomcat-7.0.78.tar.gz
# tar -zxvf apache-tomcat-7.0.78.tar.gz
# mv apache-tomcat-7.0.78 tomcat7
# /home/java/tomcat7/bin/startup.sh
启动tomcat即可,然后网页打开 0.0.0.0:8080 查看效果
-------------------------------------------------------------------
与Nginx实现动静分离
Nginx安装方法:http://blog.csdn.net/kenkao/article/details/53333595
Nginx添加Tomcat代理:
#
vim /etc/nginx/nginx.conf
添加如下内容:include enable-jsp.conf;
# vim /etc/nginx/enable-jsp.conf
输入如下内容:
location ~ (\.jsp)|(\.do)$ ###jsp、do的动态请求都交给后面的tomcat处理
{
proxy_pass http://127.0.0.1:8080;
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;
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;
}
重定向Tomcat的ROOT目录到Nginx默认html目录:(
因为静态文件全部导向Nginx跟目录,动静结合模式下访问jsp,其相对路径下的静态文件会失效)# vim /home/java/tomcat7/conf/server.xml
<Context path="" docBase="/usr/share/nginx/html/" debug="0"/>
重启Tomcat:
# cd /home/java/tomcat7/bin
# ./shutdown.sh
Tomcat ROOT 完整目录拷贝到 /usr/share/nginx/html
# cp -a /home/java/tomcat7/webapps/ROOT/* /usr/share/nginx/html
访问Nginx主页:127.0.0.1/index.html
访问Tomcat主页:127.0.0.1/index.jsp
阿里云、腾讯云 在配置完毕tomcat之后,第一次访问会奇慢无比,之后就没问题了...
参考文章:
http://www.cppblog.com/kenkao/archive/2017/04/11/214832.html
http://www.centoscn.com/image-text/install/2014/0827/3585.html
http://www.centoscn.com/image-text/config/2014/1127/4194.html
http://www.jb51.net/article/49814.htm
http://www.cnblogs.com/tovep/articles/2473147.html
https://zhidao.baidu.com/question/1386525852148480540.html