安装tomcat7:
tomcat7下载主页: http://tomcat.apache.org/download-70.cgi
下载:(core: tar.gz)
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.47/bin/apache-tomcat-7.0.47.tar.gz
tar -zxvf apache-tomcat-7.0.47.tar.gz
mv apache-tomcat-7.0.47 /usr/share/tomcat7
然后可以cd /usr/share/tomcat7 && bin/startup.sh &
更多来自:http://www.cnblogs.com/sixiweb/archive/2012/11/26/2789458.html
查看目前系统的jdk: rpm -qa | grep jdk
得到的结果:
[root@dc-01 java]# rpm -qa | grep jdk
java-1.6.0-openjdk-1.6.0.0-1.45.1.11.1.el6.i686
卸载之:
[root@dc-01 java]# yum -y remove java-1.6.0-openjdk-1.6.0.0-1.45.1.11.1.el6.i686
等一段时间就Complete了。
下载Sun的JDK。我下载的是
jdk-6u37-linux-i586-rpm.bin
如果是64位系统的话,要下载:
jdk-6u37-linux-x64-rpm.bin
之类的64位专用的包
到/usr目录下创建java目录,将下载的文件放到/usr/java目录下
先将这个文件变为可执行文件(chmod 777) :
[root@dc-01 java]# chmod 777 jdk-6u37-linux-i586-rpm.bin
然后执行这个文件件进行安装:
[root@dc-01 java]# ./jdk-6u37-linux-i586-rpm.bin
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
inflating: jdk-6u37-linux-i586.rpm
inflating: sun-javadb-common-10.6.2-1.1.i386.rpm
inflating: sun-javadb-core-10.6.2-1.1.i386.rpm
inflating: sun-javadb-client-10.6.2-1.1.i386.rpm
inflating: sun-javadb-demo-10.6.2-1.1.i386.rpm
inflating: sun-javadb-docs-10.6.2-1.1.i386.rpm
inflating: sun-javadb-javadoc-10.6.2-1.1.i386.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
plugin.jar...
javaws.jar...
deploy.jar...
Installing JavaDB
Preparing... ########################################### [100%]
1:sun-javadb-common ########################################### [ 17%]
2:sun-javadb-core ########################################### [ 33%]
3:sun-javadb-client ########################################### [ 50%]
4:sun-javadb-demo ########################################### [ 67%]
5:sun-javadb-docs ########################################### [ 83%]
6:sun-javadb-javadoc ########################################### [100%]
Java(TM) SE Development Kit 6 successfully installed.
Product Registration is FREE and includes many benefits:
* Notification of new versions, patches, and updates
* Special offers on Oracle products, services and training
* Access to early releases and documentation
Product and system data will be collected. If your configuration
supports a browser, the JDK Product Registration form will
be presented. If you do not register, none of this information
will be saved. You may also register your JDK later by
opening the register.html file (located in the JDK installation
directory) in a browser.
For more information on what data Registration collects and
how it is managed and used, see:
http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html
Press Enter to continue.....
这个时候按一下回车。
出现Done .
至此安装结束。
接下来配置JDK:
vi /etc/profile打开profile文件,在profile文件的末尾加上:
JAVA_HOME=/usr/java/jdk1.6.0_37
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH
保存并关闭profile文件,执行source /etc/profile命令让修改生效。
运行下java -version 看一下java版本 :
[root@dc-01 java]# java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) Client VM (build 20.12-b01, mixed mode, sharing)
[root@dc-01 java]#
================================================
至此,整个安装过程完毕。
3:安装Tomcat
下载apache-tomcat-7.0.33.tar.gz。解压缩:
tar -xzvf apache-tomcat-7.0.33.tar.gz
将解压缩后的文件夹拷贝到/usr/local/tomcat:
cp -R apache-tomcat-7.0.33 /usr/local/tomcat
进入tomcat目录设置tomcat 的内存使用情况及其他配置:
cd /usr/local/tomcat/bin
vi daemon.sh
在正文开始的地方加入以下内容(注意将jdk等目录结合自己的实际情况进行修改) :
# chkconfig: 2345 20 80
# description: simple example to start tomcat
JAVA_HOME=/usr/java/jdk1.6.0_37
CATALINA_HOME=/usr/local/tomcat
CATALINA_OPTS="-Xms1024m -Xmx4096m -XX:PermSize=256m -XX:MaxPermSize=512m"
4: 配置Tomcat为daemon方式启动
将daemon.sh 拷贝到启动目录,安装服务,测试服务:
先编译安装 commons-daemon :
先安装gcc,因为编译的时候要用到
yum install gcc
创建tomcat用户,用来运行tomcat服务:
在生产环境用 root 是不安全的,所以
useradd -s /sbin/nologin tomcat
chown -R tomcat:tomcat /usr/local/tomcat
做为 service,和操作系统一起启动
# tar -xzvf commons-daemon-native.tar.gz
# cd commons-daemon-1.0.10-native-src/unix
# ./configure
# make
# cp jsvc ../..
# cd ../..
cp daemon.sh /etc/init.d/tomcat
chmod 755 /etc/init.d/tomcat
chkconfig --add tomcat
chkconfig tomcat on
chkconfig --list tomcat
显示:
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 确认2~5为on的状态就OK
启动Tomcat:
service tomcat start
增加防火墙配置,允许8080端口:
# vi /etc/sysconfig/iptables
在允许ssh的下面增加一条:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
保存,重启iptables服务 :
# service iptables restart
测试:
本机测试:
wget http://localhost:8080/
从其他机器 测试:
浏览器中输入 http://localhost:8080/
看看是否能打开网站。
=========================================
配置过程中参考了一下博客:
http://batizhao.github.com/linux/2012/07/17/install-tomcat7-on-centos/
(责任编辑:IT) |