Linux系统下tomcat安装配置

时间:2024-01-14 08:27:50

Linux系统中Tomcat的安装配置。

前提JDK已经安装好。

安装

下载tomcat
wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.tar.gz

(1)解压apache-tomcat-8.0.20.tar.gz
# tar-zxvf apache-tomcat-8.0.20.tar.gz
(2)复制解压后的目录apache-tomcat-8.0.20到/usr/local下并重命名为tomcat8
# cp -Rapache-tomcat-8.0.20 /usr/local/tomcat8
注意:/usr/local/tomcat8就是后面我们要修改环境变量时需要填写的目录路径
(3)
添加tomcat环境变量
# vim /etc/profile
加入下代码
#set environment variable
JAVA_HOME=/usr/java/jdk1.8.0_31
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
exportTOMCAT_HOME=/usr/local/tomcat8
exportCATALINA_HOME=/usr/local/tomcat8
修改应用环境变量,是配置生效
# source/etc/profile

(4)进入bin目录 ,启动tomcat
# cd/usr/local/tomcat8/
# cd bin/
#./startup.sh

(5)修改环境变量后重新启动tomcat启动成功
[root@oracledb bin]# ./startup.sh 
Using CATALINA_BASE: /usr/local/tomcat8
Using CATALINA_HOME: /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME: /usr/java/jdk1.8.0_31
Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Tomcat started.

(6)关闭tomcat
[root@oracledb bin]# ./shutdown.sh
Using CATALINA_BASE: /usr/local/tomcat8
Using CATALINA_HOME: /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME: /usr/java/jdk1.8.0_31
Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar

(7) 查看进程
[root@oracledb bin]# ps -ef | grep tomcat
root 22552 1 99 09:58 pts/0 00:00:05 /usr/java/jdk1.8.0_31/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat8/endorsed -classpath /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8 -Dcatalina.home=/usr/local/tomcat8 -Djava.io.tmpdir=/usr/local/tomcat8/temp org.apache.catalina.startup.Bootstrap start
root 22581 22284 0 09:58 pts/0 00:00:00 grep tomcat

(8)添加管理权限
默认情况下,Tomcat并没提供具有管理权限的账号,所以需要添加具有这种权限的账号。角色manager-gui具有这种权限,但在系统用户控制文件 tomcat-users.xml中并没有设置这两种角色和对应的用户,所以需要添加这种角色和用户,方法是打开tomcat-users.xml文件, 添加如下内容:
<rolerolename="manager-gui"/>
<userusername="manager" password="manager"roles="manager-gui"/>
然后重启Tomcat服务器,文件修改生效。

配置

Linux下tomcat配置和windows下是一样的,这里讲下配置tomcat服务的访问端口:

cd /usr/local/tomcat/conf/
vim server.xml

找到:

<Connector port="8080" protocol="HTTP/1.1"
修改为:

<Connector port="你想要的端口" protocol="HTTP/1.1"

重启tomcat

service tomcat stop

service tomcat start

这样tomcat就配置成功了