wdcp添加tomcat,同时支持php和java教程
程序员文章站
2022-04-06 20:25:27
用wdcp官方提供的脚本安装lnamp环境,安装请参考:http://www.wdlinux.cn/bbs/thread-6292-1-1.html,本文主要讲如何在lna...
用wdcp官方提供的脚本安装lnamp环境,安装请参考:http://www.wdlinux.cn/bbs/thread-6292-1-1.html,本文主要讲如何在lnamp环境下安装jdk+tomcat6使同一台服务器同时支持php和java语言。服务器系统和各软件版本如下所示
- [root@e ~]# uname -a
- linux e.centos6.4 2.6.32-358.el6.x86_64 #1 smp fri feb 22 00:31:26 utc 2013 x86_64 x86_64 x86_64 gnu/linux
- [root@e ~]# /www/wdlinux/nginx/sbin/nginx -v
- nginx version: nginx/1.2.9
- [root@e ~]# /www/wdlinux/httpd-2.2.24/bin/httpd -v
- server version: apache/2.2.24 (unix)
- server built: oct 30 2014 00:17:07
- [root@e ~]# rpm -qa |grep mysql
- mysql-libs-5.1.66-2.el6_3.x86_64
- [root@e ~]# /www/wdlinux/php/bin/php -v
- cannot load zend extension manager - it was built with configuration 1.2.0, whereas running engine is api220090626,nts
- php 5.3.27 (cli) (built: oct 30 2014 00:30:02)
- copyright (c) 1997-2013 the php group
- zend engine v2.3.0, copyright (c) 1998-2013 zend technologies
开始安装jdk: 列出yum库可用的jdk安装包
- [root@e ~]# yum -y list java*
- loaded plugins: fastestmirror
- loading mirror speeds from cached hostfile
- * base: mirror.bit.edu.cn
- * extras: mirror.bit.edu.cn
- * rpmforge: mirrors.neusoft.edu.cn
- * updates: mirrors.neusoft.edu.cn
- base | 3.7 kb 00:00
- extras | 3.3 kb 00:00
- rpmforge | 1.9 kb 00:00
- updates | 3.4 kb 00:00
- updates/primary_db | 171 kb 00:00
- available packages
- java-1.5.0-gcj.x86_64 1.5.0.0-29.1.el6 base
- java-1.5.0-gcj-devel.x86_64 1.5.0.0-29.1.el6 base
- java-1.5.0-gcj-javadoc.x86_64 1.5.0.0-29.1.el6 base
- java-1.5.0-gcj-src.x86_64 1.5.0.0-29.1.el6 base
- java-1.6.0-openjdk.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates
- java-1.6.0-openjdk-demo.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates
- java-1.6.0-openjdk-devel.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates
- java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates
- java-1.6.0-openjdk-src.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates
- java-1.7.0-openjdk.x86_64 1:1.7.0.71-2.5.3.1.el6 updates
- java-1.7.0-openjdk-demo.x86_64 1:1.7.0.71-2.5.3.1.el6 updates
- java-1.7.0-openjdk-devel.x86_64 1:1.7.0.71-2.5.3.1.el6 updates
- java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.71-2.5.3.1.el6 updates
- java-1.7.0-openjdk-src.x86_64 1:1.7.0.71-2.5.3.1.el6 updates
- java-1.8.0-openjdk.x86_64 1.8.0.25-1.b17.el6 updates
- java-1.8.0-openjdk-demo.x86_64 1.8.0.25-1.b17.el6 updates
- java-1.8.0-openjdk-devel.x86_64 1.8.0.25-1.b17.el6 updates
- java-1.8.0-openjdk-headless.x86_64 1.8.0.25-1.b17.el6 updates
- java-1.8.0-openjdk-javadoc.noarch 1.8.0.25-1.b17.el6 updates
- java-1.8.0-openjdk-src.x86_64 1.8.0.25-1.b17.el6 updates
- java_cup.x86_64 1:0.10k-5.el6 base
- java_cup-javadoc.x86_64 1:0.10k-5.el6 base
- java_cup-manual.x86_64 1:0.10k-5.el6 base
- javacc.x86_64 4.1-0.5.el6 base
- javacc-demo.x86_64 4.1-0.5.el6 base
- javacc-manual.x86_64 4.1-0.5.el6 base
- javassist.noarch 3.9.0-6.el6 base
- javassist-javadoc.noarch 3.9.0-6.el6 base
- [root@e ~]# yum -y install java-1.6.0-openjdk*
其它版本请自己修改对应的版本号安装 检测是否安装成功
- [root@e ~]# java -version
- java version "1.6.0_33"
- openjdk runtime environment (icedtea6 1.13.5) (rhel-1.13.5.0.el6_6-x86_64)
- openjdk 64-bit server vm (build 23.25-b01, mixed mode)
- [root@e ~]# yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps
安装成功 启动
- [root@e ~]# service tomcat6 start
- 其它命令:service tomcat6 {start|stop|restart|condrestart|try-restart|reload|force-reload|status|version}
启动成功,访问测试:http://ip:8080 能访问即为安装成功: 配置nginx和tomcat,使其不加端口号,直接通过域名也能访问 首先增加解析,使域名指向到主机ip,本地可以直接改host实现 解析正常 不加8080端口访问 添加8080端口访问 接下来修改nginx和tomcat的配置使其不加端口号也能访问到tomcat的webservice
- [root@e ~]# cd /www/wdlinux/nginx/conf/vhost/
- [root@e ~]# vi myweb.com.conf
- 添加如下内容
- server {
- listen 80;
- server_name www.myweb.com myweb.com;
- #root /www/web/master_myweb_com/public_html;
- index index.html index.jsp index.htm;
- error_page 400 /errpage/400.html;
- error_page 403 /errpage/403.html;
- error_page 404 /errpage/404.html;
- error_page 405 /errpage/405.html;
- location ~ \.jsp$ {
- proxy_pass http://127.0.0.1:8080;
- include naproxy.conf;
- }
- location / {
- try_files $uri @tomcat;
- }
- location @tomcat {
- proxy_pass http://127.0.0.1:8080;
- include naproxy.conf;
- }
- access_log /www/web_logs/myweb_com_access.log wwwlogs;
- error_log /www/web_logs/myweb_com_error.log;
- }
重新加载nginx配置文件或重启nginx
- [root@e vhost]# service nginxd reload
- nginx: the configuration file /www/wdlinux/nginx/conf/nginx.conf syntax is ok
- nginx: configuration file /www/wdlinux/nginx/conf/nginx.conf test is successful
不加端口号访问测试: 至此nginx已经成功将来自myweb.com域名的请求代理到8080端口 如果需要配置多域名的话,还需要修改tomcat虚拟主机配置文件 默认配置文件路径:/etc/tomcat6/ 默认项目路径:/var/lib/tomcat6/webapps/ tomcat默认指向/var/lib/tomcat6/webapps/root目录 创建新项目目录,这里直接复制root项目,进行修改
- [root@e webapps]# pwd
- /var/lib/tomcat6/webapps
- [root@e webapps]# chown -r root myweb.com
- 修改权限,使新项目权限和默认项目权限一致
- [root@e webapps]# chgrp -r tomcat myweb.com
- [root@e webapps]# ll
- 总用量 24
- drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 examples
- drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 host-manager
- drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 manager
- drwxr-xr-x 3 root tomcat 4096 10月 30 22:48 myweb.com
- drwxrwxr-x 3 root tomcat 4096 10月 30 22:06 root
- drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 sample
- [root@e myweb.com]# cd myweb.com/
- [root@e myweb.com]# rm -f index.html
- [root@e myweb.com]# vi index.jsp
- 写入:webservice is tomcat
- 不要忘记删除root项目或者对它重命,否则新项目不生效
- [root@e webapps]# mv root/ root.bak
修改tomcat虚拟主机配置
- [root@e myweb.com]# vi /etc/tomcat6/server.xml
- 在最下面<host></host>标签后面添加如下内容
- <!--myweb.com host config-->
- <host name="www.myweb.com" appbase="webapps"
- unpackwars="true" autodeploy="true"
- xmlvalidation="false" xmlnamespaceaware="false">
- <context path="/" reloadable="true" docbase="myweb.com"/>
- <alias>myweb.com</alias>
- <!-- singlesignon valve, share authentication between web applications
- documentation at: /docs/config/valve.html -->
- <!--
- <valve classname="org.apache.catalina.authenticator.singlesignon" />
- -->
- <!-- access log processes all example.
- documentation at: /docs/config/valve.html -->
- <!--
- <valve classname="org.apache.catalina.valves.accesslogvalve" directory="logs"
- prefix="localhost_access_log." suffix=".txt" pattern="common" resolvehosts="false"/>
- -->
- </host>
重启tomcat,测试 [root@e myweb.com]# service tomcat6 restart success!