本地测试用的(注意红色部分)
第一步、自己的windows电脑,在c盘中有个hosts文件(搜索一下),做以下修改(其中127.0.0.1是本机地址,192.1638.10.139是我虚拟机中linux机的ip,aaa.wscapp.cn为希望这个项目访问的地址,例如http://aaa.wscapp.cn)
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
127.0.0.1 wscapp.cn
192.168.10.139 aaa.wscapp.cn
192.168.10.139 bbb.wscapp.cn
第二步:linux中的tomcat修改成下面的样子(有几个项目就加几个Host,我测试的两个项目是放在tomcat的webapps目录下)
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<!-- name="aaa.wscapp.cn":外部访问的地址,要和windows上配置的一样
appBase="/tmp/tomcat6/webapps/aaa":项目在tomcat中的绝对路径,aaa为项目名-->
<Host name="aaa.wscapp.cn" appBase="/tmp/tomcat6/webapps/xmenh"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="/tmp/tomcat6/webapps/xmenh" reloadable="true"></Context>
</Host>
<Host name="bbb.wscapp.cn" appBase="/tmp/tomcat6/webapps/bbb"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="/tmp/tomcat6/webapps/bbb" reloadable="true"></Context>
</Host>
</Engine>
</Service>
</Server>
第三步:配置完成之后就可以在windows上分别通过http://aaa.wscapp.cn和http://bbb.wscapp.cn访问项目了
将tomcat配置成系统服务:
下面内容来自:http://www.cnblogs.com/ilahsa/p/linux.html
1. 首先需要将$Tomcat_HOME/bin目录下的Catalina.sh脚本复制到目录/etc/init.d中,重命名为tomcat,文件名即为以后的服务名
2. 修改刚才复制的tomcat脚本:
a. 在脚本的第三行后面插入下面两行
# chkconfig: 2345 10 90
# description:Tomcat service
第一行是服务的配置:第一个数字是服务的运行级,2345表明这个服务的运行级是2、3、4和5级(Linux的运行级为0到6);第二个数字是启动优先级,数值从0到99;第三个数是停止优先级,数值也是从0到99。
第二行是对服务的描述
b. 在脚本中设置 CATALINA_HOME 和 JAVA_HOME 这两个脚本必需的环境变量,如:
CATALINA_HOME=/usr/share/tomcat
JAVA_HOME=/usr/share/java/jdk
经过实验发现,即使在系统中设置了这两个环境变量也没有用,只好在这里再设置一遍
c. 添加tomcat 脚本为可执行权限
[root@localhost bin]# chmod 755 /etc/init.d/tomcat
d. 最后用chkconfig设置服务运行
#chkconfig --add tomcat
服务就添加成功了。
然后你就可以用 chkconfig --list 查看,在服务列表里就会出现自定义的服务了。
注意:
在tomcat文件的头两行的注释语句中,需要包含chkconfig和description两部分内容(确认不要拼写错误,),否则在执行“chkconfig --add tomcat”时,会出现“tomcat服务不支持chkconfig”的错误提示
(注:如果不添加为系统服务,仅是使用service 命令来管理tomcat 的话,a,c ,d 步骤可以省略)
3. OK!现在就可以用service tomcat start|stop|run来管理tomcat服务了
4. 设置tomcat 在操作系统重启后自动重启
直接在/etc/rc.local 后添加下面的语句
/usr/local/tomcat/bin/startup.sh