欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

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语言。服务器系统和各软件版本如下所示

  1. [root@e ~]# uname -a
  2. 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
  3. [root@e ~]# /www/wdlinux/nginx/sbin/nginx -v
  4. nginx version: nginx/1.2.9
  5. [root@e ~]# /www/wdlinux/httpd-2.2.24/bin/httpd -v
  6. server version: apache/2.2.24 (unix)
  7. server built: oct 30 2014 00:17:07
  8. [root@e ~]# rpm -qa |grep mysql
  9. mysql-libs-5.1.66-2.el6_3.x86_64
  10. [root@e ~]# /www/wdlinux/php/bin/php -v
  11. cannot load zend extension manager - it was built with configuration 1.2.0, whereas running engine is api220090626,nts
  12. php 5.3.27 (cli) (built: oct 30 2014 00:30:02)
  13. copyright (c) 1997-2013 the php group
  14. zend engine v2.3.0, copyright (c) 1998-2013 zend technologies

开始安装jdk: 列出yum库可用的jdk安装包
  1. [root@e ~]# yum -y list java*
  2. loaded plugins: fastestmirror
  3. loading mirror speeds from cached hostfile
  4. * base: mirror.bit.edu.cn
  5. * extras: mirror.bit.edu.cn
  6. * rpmforge: mirrors.neusoft.edu.cn
  7. * updates: mirrors.neusoft.edu.cn
  8. base | 3.7 kb 00:00
  9. extras | 3.3 kb 00:00
  10. rpmforge | 1.9 kb 00:00
  11. updates | 3.4 kb 00:00
  12. updates/primary_db | 171 kb 00:00
  13. available packages
  14. java-1.5.0-gcj.x86_64 1.5.0.0-29.1.el6 base
  15. java-1.5.0-gcj-devel.x86_64 1.5.0.0-29.1.el6 base
  16. java-1.5.0-gcj-javadoc.x86_64 1.5.0.0-29.1.el6 base
  17. java-1.5.0-gcj-src.x86_64 1.5.0.0-29.1.el6 base
  18. java-1.6.0-openjdk.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates
  19. java-1.6.0-openjdk-demo.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates
  20. java-1.6.0-openjdk-devel.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates
  21. java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates
  22. java-1.6.0-openjdk-src.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates
  23. java-1.7.0-openjdk.x86_64 1:1.7.0.71-2.5.3.1.el6 updates
  24. java-1.7.0-openjdk-demo.x86_64 1:1.7.0.71-2.5.3.1.el6 updates
  25. java-1.7.0-openjdk-devel.x86_64 1:1.7.0.71-2.5.3.1.el6 updates
  26. java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.71-2.5.3.1.el6 updates
  27. java-1.7.0-openjdk-src.x86_64 1:1.7.0.71-2.5.3.1.el6 updates
  28. java-1.8.0-openjdk.x86_64 1.8.0.25-1.b17.el6 updates
  29. java-1.8.0-openjdk-demo.x86_64 1.8.0.25-1.b17.el6 updates
  30. java-1.8.0-openjdk-devel.x86_64 1.8.0.25-1.b17.el6 updates
  31. java-1.8.0-openjdk-headless.x86_64 1.8.0.25-1.b17.el6 updates
  32. java-1.8.0-openjdk-javadoc.noarch 1.8.0.25-1.b17.el6 updates
  33. java-1.8.0-openjdk-src.x86_64 1.8.0.25-1.b17.el6 updates
  34. java_cup.x86_64 1:0.10k-5.el6 base
  35. java_cup-javadoc.x86_64 1:0.10k-5.el6 base
  36. java_cup-manual.x86_64 1:0.10k-5.el6 base
  37. javacc.x86_64 4.1-0.5.el6 base
  38. javacc-demo.x86_64 4.1-0.5.el6 base
  39. javacc-manual.x86_64 4.1-0.5.el6 base
  40. javassist.noarch 3.9.0-6.el6 base
  41. javassist-javadoc.noarch 3.9.0-6.el6 base
选择jdk1.6安装
  1. [root@e ~]# yum -y install java-1.6.0-openjdk*

其它版本请自己修改对应的版本号安装 检测是否安装成功

  1. [root@e ~]# java -version
  2. java version "1.6.0_33"
  3. openjdk runtime environment (icedtea6 1.13.5) (rhel-1.13.5.0.el6_6-x86_64)
  4. openjdk 64-bit server vm (build 23.25-b01, mixed mode)
安装tomcat6 因为wdcp后台默认安装的端口是8080,tomcat默认端口也是8080为了避免冲突请提前把wdcp后台端口改为其它端口(如:8089...) 可以到wdcp后台系统设置中手动修改:
  1. [root@e ~]# yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps

安装成功 启动

  1. [root@e ~]# service tomcat6 start
  2. 其它命令: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

  1. [root@e ~]# cd /www/wdlinux/nginx/conf/vhost/
  2. [root@e ~]# vi myweb.com.conf
  3. 添加如下内容
  4. server {
  5. listen 80;
  6. server_name www.myweb.com myweb.com;
  7. #root /www/web/master_myweb_com/public_html;
  8. index index.html index.jsp index.htm;
  9. error_page 400 /errpage/400.html;
  10. error_page 403 /errpage/403.html;
  11. error_page 404 /errpage/404.html;
  12. error_page 405 /errpage/405.html;
  13. location ~ \.jsp$ {
  14. proxy_pass http://127.0.0.1:8080;
  15. include naproxy.conf;
  16. }
  17. location / {
  18. try_files $uri @tomcat;
  19. }
  20. location @tomcat {
  21. proxy_pass http://127.0.0.1:8080;
  22. include naproxy.conf;
  23. }
  24. access_log /www/web_logs/myweb_com_access.log wwwlogs;
  25. error_log /www/web_logs/myweb_com_error.log;
  26. }

重新加载nginx配置文件或重启nginx

  1. [root@e vhost]# service nginxd reload
  2. nginx: the configuration file /www/wdlinux/nginx/conf/nginx.conf syntax is ok
  3. 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项目,进行修改

  1. [root@e webapps]# pwd
  2. /var/lib/tomcat6/webapps
  3. [root@e webapps]# chown -r root myweb.com
  4. 修改权限,使新项目权限和默认项目权限一致
  5. [root@e webapps]# chgrp -r tomcat myweb.com
  6. [root@e webapps]# ll
  7. 总用量 24
  8. drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 examples
  9. drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 host-manager
  10. drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 manager
  11. drwxr-xr-x 3 root tomcat 4096 10月 30 22:48 myweb.com
  12. drwxrwxr-x 3 root tomcat 4096 10月 30 22:06 root
  13. drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 sample
  14. [root@e myweb.com]# cd myweb.com/
  15. [root@e myweb.com]# rm -f index.html
  16. [root@e myweb.com]# vi index.jsp
  17. 写入:webservice is tomcat
  18. 不要忘记删除root项目或者对它重命,否则新项目不生效
  19. [root@e webapps]# mv root/ root.bak

修改tomcat虚拟主机配置

  1. [root@e myweb.com]# vi /etc/tomcat6/server.xml
  2. 在最下面<host></host>标签后面添加如下内容
  3. <!--myweb.com host config-->
  4. <host name="www.myweb.com" appbase="webapps"
  5. unpackwars="true" autodeploy="true"
  6. xmlvalidation="false" xmlnamespaceaware="false">
  7. <context path="/" reloadable="true" docbase="myweb.com"/>
  8. <alias>myweb.com</alias>
  9. <!-- singlesignon valve, share authentication between web applications
  10. documentation at: /docs/config/valve.html -->
  11. <!--
  12. <valve classname="org.apache.catalina.authenticator.singlesignon" />
  13. -->
  14. <!-- access log processes all example.
  15. documentation at: /docs/config/valve.html -->
  16. <!--
  17. <valve classname="org.apache.catalina.valves.accesslogvalve" directory="logs"
  18. prefix="localhost_access_log." suffix=".txt" pattern="common" resolvehosts="false"/>
  19. -->
  20. </host>

重启tomcat,测试 [root@e myweb.com]# service tomcat6 restart success!