↑nginx+tomcat+httpd实现动静分离↑
2013-10-01 16:39:54
标签:tomcat动静分离
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://gyulong.blog.51cto.com/6844383/1304021
拓扑图:
node1:nginx 172.16.8.10
node2:tomcat 172.16.8.8
node3:httpd 172.16.251.130
-----------------------------------------------------------------------------------------
实验环境:
jdk-7u9-linux-x64.rpm
apache-tomcat-7.0.42.tar.gz
mysql-5.5.33.tar.gz
nginx-1.4.2.tar.gz
JspRun!_6.0.0_GBK.zip
-----------------------------------------------------------------------------------------
1.在node1节点上安装nginx并添加如下内容
[root@yulong ~]# vim /etc/nginx/nginx.conf
location / {
}
location ~* \.(gif|png|jpeg|bmp|jpg|htm)$ {
proxy_pass http://172.16.251.130:80;
} #要代理的静态文件和图片服务器
location ~* \.(jsp|do|css) {
proxy_pass http://172.16.8.8:80;
} #要代理的动态数据服务器
2.在node2上安装tomcat和mysql数据库
2.1 安装JDK
[root@yulong ~]# rpm -ivh jdk-7u9-linux-x64.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
2.2.设置JDK的环境变量
[root@yulong jdk1.7.0_09]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/latest
export PATH=$JAVA_HOME/bin:$PATH
[root@yulong jdk1.7.0_09]# source /etc/profile.d/java.sh
2.3.查看java版本状态
[root@yulong bin]# java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
2.4.安装tomcat
[root@yulong ~]# tar xf apache-tomcat-7.0.42.tar.gz -C /usr/local/
[root@yulong local]# ln -sv apache-tomcat-7.0.42 tomcat
`tomcat' -> `apache-tomcat-7.0.42'
2.5.设置tomcat环境变量
[root@yulong tomcat]# vim /etc/profile.d/tomcat.sh
[root@yulong tomcat]# source /etc/profile.d/tomcat.sh
export CATALINA_HOME=/usr/local/tomcat
export PATH=$CATALINA_HOME/bin:$PATH
2.6.启动tomcat
[root@yulong bin]# catalina.sh start
2.7.编辑tomcat配置文件,添加如下内容
[root@yulong conf]# vim server.xml
[root@yulong conf]# mkdir /web/app -p
Host name="www.yulong.com" appBase="/web/app"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="yulong_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="/" docBase="/web/app" />
</Host>
Connector port="80" protocol="HTTP/1.1" 这项不用添加,只需把8080修改为80
2.8.解压论坛安装包并放到tomcat程序目录文件下
[root@yulong ~]# unzip JspRun\!_6.0.0_GBK.zip
[root@yulong ~]# cp upload/* /web/app/ -r
3.在node3上安装http提供静态页面
[root@yulong ~]# unzip JspRun\!_6.0.0_GBK.zip
[root@yulong ~]# cp upload/* /var/www/html -r
3.1启动httpd服务
[root@yulong ~]# service httpd start
4.测试页面是否正常显示