用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
- [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!