本文共 4578 字,大约阅读时间需要 15 分钟。
一.安装启动apache
# netstat -tnlp |grep 80
tcp 0 0 :::80 :::* LISTEN 1960/httpd
二、单独使用Tomcat
]# rpm -qa |grep java
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
# rpm -e --nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
# java -version
-bash: /usr/bin/java: 没有那个文件或目录
==安装JDK
# rpm -ivh jdk-7u11-linux-i586.rpm 如果装不上就加上--force强行
]# java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build1.7.0_11-b21)
Java HotSpot(TM) Client VM (build 23.6-b04,mixed mode, sharing)
# ls /usr/java/jdk1.7.0_11
# vim /etc/profile 设置环境变量
JAVA_HOME=/usr/java/jdk1.7.0_11
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME PATH
# source /etc/profile
#echo$PATH /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:
/root/bin:/usr/java/jdk1.7.0_11/bin
==Tomcat
# tar xvf apache-tomcat-7.0.34.tar.gz -C/usr/local/
# cd /usr/local/
# ln -sv apache-tomcat-7.0.34 tomcat
创建指向“apache-tomcat-7.0.34”的符号链接“tomcat”
# vim /etc/profile 定义Tomcat环境变量
CATALINA_HOME=/usr/local/tomcat
export CATALINA_HOME
# source /etc/profile
# env |grep HOME
CATALINA_HOME=/usr/local/tomcat
JAVA_HOME=/usr/java/jdk1.7.0_11
HOME=/root
# /usr/local/tomcat/bin/catalina.sh start 启动
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR:/usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.7.0_11
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
PID/Program name
tcp 0 0::ffff:127.0.0.1:8005 :::* LISTEN 2920/java
tcp 0 0 :::8009 :::* LISTEN 2920/java
tcp 0 0 :::8080 :::* LISTEN 2920/java
tcp 0 0 :::80 :::* LISTEN 2135/httpd
System V脚本可选项
# vim /etc/init.d/tomcat
#!/bin/bash
# Init file for Tomcat server daemon
#
# chkconfig: 2345 96 14
# description: Tomcat server daemon
JAVA_OPTS='-Xms64m -Xmx128m'
JAVA_HOME=/usr/java/jdk1.7.0_11
CATALINA_HOME=/usr/local/tomcat
export JAVA_OPTS JAVA_HOME CATALINA_HOME
exec $CATALINA_HOME/bin/catalina.sh $*
# chmod a+x /etc/init.d/tomcat
# chkconfig tomcat --list
tomcat 服务支持 chkconfig,但它在任何级别中都没有被引用(运行“chkconfig--add tomcat”)
# chkconfig --add tomcat
# chkconfig tomcat --list
tomcat 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
]# chkconfig tomcat on
# service tomcat stop
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR:/usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.7.0_11
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
# service tomcat start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR:/usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.7.0_11
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
=================================================
测试:
http://192.168.0.118 / IP是自己电脑的IP
groupinstall 组安装一组一组的-y 不用写yes
安装tomcat-native
# yum groupinstall -y "Developmenttools" "Development libraries"
# yum -y install openssl-devel apr-devel
# cd /usr/local/tomcat/bin/
# ls
bootstrap.jar commons-daemon-native.tar.gz digest.bat shutdown.sh tool-
wrapper.bat
catalina.bat configtest.bat digest.sh startup.bat tool-
wrapper.sh
catalina.sh configtest.sh setclasspath.bat startup.sh
version.bat
catalina-tasks.xml cpappend.bat setclasspath.sh tomcat-juli.jar
version.sh
commons-daemon.jar daemon.sh shutdown.bat tomcat-native.tar.gz
# tar xf tomcat-native.tar.gz
# cd tomcat-native-1.1.24-src/jni/native/
# ls
build build-outputs.mk include NMAKEmakefile srclib
buildconf config.layout libtcnative.dsp NMAKEmakefile.inc tcnative.dsp
build.conf configure libtcnative.dsw os tcnative.pc.in
BUILDING configure.in Makefile.in src tcnative.spec
# ./configure --with-apr=/usr/ --with-ssl--with-java-home=/usr/java/jdk1.7.0_11/
# make && make install 这可能会报错 yum –y install java
# echo "/usr/local/apr/lib" >/etc/ld.so.conf.d/apr.conf搜索库文件的路径给他添加库文件路径
# ldconfig 重新加载库文件
为查看Tomcat运行状态添加用户:
/usr/local/tomcat/conf/server.xml Tomcat配置文件
[root@node1 ~]# vim /usr/local/tomcat/conf/tomcat-users.xml
<tomcat-users>
<role rolename="manager-gui"/>
<rolerolename="manager-scripts"/>
<rolerolename="manager-status"/>
<user username="tomcat"password="123456"roles="manager-gui,manager-scripts,manager-status"/>
</tomcat-users>
# service tomcat stop
# service tomcat start
然后就可以在刚才tomcat页面最右面的 Server status 输入帐号tomcat 密码123456 在最下面有后台运行状
态 S sleep状态
=================================================
本文转自潘阔 51CTO博客,原文链接:http://blog.51cto.com/pankuo/1369774,如需转载请自行联系原作者