欢迎访问www.showerlee.com, 您的支持就是我前进的动力.

Centos6.3下jdk+tomcat安装部署

showerlee 2013-08-26 21:49 APACHE 阅读 (16,885) 抢沙发

最近一直在学习LINUX下的脚本语言,好久没有更新应用了,刚好群里有人问我关于tomcat的安装配置问题,这不就忙里偷闲,整理了篇tomcat的文档,供大家分享。

安装部署:

系统环境:centos6.3 x64

JDK:      jdk-6u25-linux-x64-rpm.bin

TOMCAT:   apache-tomcat-7.0.42

服务端地址:192.168.7.73

配置前先关闭iptables和SELINUX,避免安装过程中报错。

# service iptables stop

# setenforce 0

# vi /etc/sysconfig/selinux

---------------

SELINUX=disabled

---------------

一.配置JDK

1.下载官方JDK安装包:

# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F"  http://download.oracle.com/otn-pub/java/jdk/6u25-b06/jdk-6u25-linux-x64-rpm.bin

注:--no-cookies --no-check-certificate --header...参数保证链接能够正常解析。


2.安装:

1).赋予安装包可执行权限

# chmod a+x jdk-6u25-linux-x64-rpm.bin

2).解包安装:

注:该bin包会解压出若干jdk的rpm安装包,而后自动安装

# ./jdk-6u25-linux-x64-rpm.bin

3).添加jdk软连接:

注:后面设置环境变量和编译时会用到

# ln -s /usr/java/jdk1.6.0_25 /usr/local/java

新版本安装步骤

# wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.rpm" -O /opt/jdk-8-linux-x64.rpm

# yum install /opt/jdk-8-linux-x64.rpm

3.设置环境变量

# vi /etc/profile

末尾增加如下内容

-----------------------

JAVA_HOME=/usr/local/java

export JAVA_HOME

set PATH=$JAVA_HOME/bin:$PATH

export PATH

set CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export CLASSPATH

------------------------

加载环境变量

# source /etc/profile

4.验证是否安装成功:

# java -version

注:这里因为当时安装centos时,将java开发环境勾选,所以这里显示的自带的java版本

------------------------

java version "1.6.0_24"

OpenJDK Runtime Environment (IcedTea6 1.11.1) (rhel-1.45.1.11.1.el6-x86_64)

OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

------------------------

测试成功

二.配置tomcat

1.下载最新官方tomcat源码包:

# wget -c http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.54/bin/apache-tomcat-7.0.54.tar.gz

2.解压安装:

# tar -zxvf apache-tomcat-7.0.54.tar.gz

# mv apache-tomcat-7.0.54 tomcat

# cp -rf tomcat/ /usr/local/

3.初始化配置:

# cd /usr/local/tomcat/bin/

# vi catalina.sh

末行添加:

---------------------

CATALINA_HOME=/usr/local/tomcat/

JAVA_HOME=/usr/local/java

---------------------

3.启动tomcat

# /usr/local/tomcat/bin/startup.sh  

# /usr/local/tomcat/bin/catalina.sh start

4.查看tomcat启动日志:

# cd /usr/local/tomcat/logs/

# cat catalina.out

-------------------

2013-8-1 3:23:56 org.apache.catalina.core.AprLifecycleListener init

信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/server:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

.......

-------------------

发现日志提示缺少ARP模块,google了下,原因是tomcat默认未加载Tomcat Native增强组件:

解决方法:

a.安装apr组件:

# wget http://archive.apache.org/dist/apr/apr-1.4.6.tar.gz

# tar zxvf apr-1.4.6.tar.gz

# cd apr-1.4.6

# ./configure --prefix=/usr/local/apr

# make && make install

b.安装Tomcat Native模块

注:这里千万不要去官网下载Native编译包,试了好几个版本都会出现编译报错的BUG.

解决办法是tomcat的bin目录下会自带兼容该tomcat版本的Native编译包,这里被卡了2个小时,最后无意看到一篇文档介绍/usr/local/tomcat/bin/下自带,终于通过安装.

# cd /usr/local/tomcat/bin/

# tar zxvf tomcat-native.tar.gz

# cd tomcat-native-1.1.27-src/jni/native/

# ./configure --with-apr=/usr/local/apr --with-java-home=/usr/local/java

注:--with-java-home=/usr/local/java对应之前安装JDK的软链路径

# make && make install

c.加载apr的环境变量,使tomcat加载Tomcat Native组件:

# vi /etc/profile

添加如下内容:

----------------------

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib  

----------------------

加载环境变量,使其立即生效

# source /etc/profile  

d.查看tomcat启动日志变化:

# tail -f  /usr/local/tomcat/logs/catalina.out

e.重启tomcat:

# killall java

# /usr/local/tomcat/bin/catalina.sh start

e.观察日志滚动行若有如下提示,说明Tomcat Native安装成功

-----------------------

Loaded APR based Apache Tomcat Native library 1.1.27 using APR version 1.4.6.

........

-----------------------

f.查看端口状态:

# lsof -i:8080

注:tomcat默认为8080端口

------------------------

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

java    26116 root   40u  IPv6  66456      0t0  TCP *:webcache (LISTEN)

------------------------

5.测试启动页面:

浏览器输入 http://192.168.7.73:8080/

出现以下tomcat页面则测试成功

1

注: tomcat的默认测试页面是放在webapps下面,在tomcat配置文件主配置文件server.xml内有相应配置的,如下:

-------------------------------------

<Host name="localhost"  appBase="webapps"

           unpackWARs="true" autoDeploy="true"

           xmlValidation="false" xmlNamespaceAware="false">

-------------------------------------

6.目录结构:

# cd /usr/local/tomcat/

# ls

--------------------

bin   lib      logs    RELEASE-NOTES  temp     work

conf  LICENSE  NOTICE  RUNNING.txt    webapps

--------------------

1) webapps目录主要用于web应用程序部署,比如你可以把你的应用程序包,如war文件拷到该目录下,容器会自动部署

2) conf目录下主要是放置tomcat的服务器的相关配置文件

3) logs存放tomcat的日志

4)bin目录存放tomcat的指令

5.修改tomcat的监听端口

# cd /usr/local/tomcat/conf

# vi server.xml

---------------------------------

# 停止tomcat时的端口

<Server port="8005" shutdown="SHUTDOWN">

# tomcat默认的监听端口是8080

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />  

# apache+tomcat模式时访问tomcat的端口

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

---------------------------------

大功告成....

正文部分到此结束
版权声明:除非注明,本文由(showerlee)原创,转载请保留文章出处!
本文链接:http://www.showerlee.com/archives/548

继续浏览:JDKTOMCAT

还没有评论,快来抢沙发!

发表评论

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif