Tomcat在Linux下的安装与配置

时间:2023-02-10 01:15:00

一、安装配置JDK

1.官网下载JDK1.7

mkdir /usr/java
cd /uar/java
wget http://download.oracle.com/otn/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz
tar -xf jdk-7u80-linux-x64.tar.gz
mv jdk1..0_80 /usr/java

2.配置JDK的环境变量

vi /etc/profile

export JAVA_HOME=/usr/java/jdk1.7.0_80
export PATH=$PATH:$JAVA_HOME/bin

使环境变量设置立即生效

source /etc/profile

  

二、安装配置tomcat

1.下载并解压tomcat7,并改名

cd /usr/local
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.72/bin/apache-tomcat-7.0.72.tar.gz
tar xf apache-tomcat-7.0..tar.gz
mv apache-tomcat-7.0./ tomcat

2.为了安全考虑最好将tomcat应用建立一个单独的tomcat用户及组

useradd -d /usr/local/tomcat tomcat 
password tomcat
chown -R tomcat.tomcat /usr/local/tomcat

2.启动tomcat

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

3.访问tomcat

http://localhost:8080/

4.关闭tomcat

/usr/local/tomcat/bin/shutdown.sh

三、tomcat的配置

1.tomcat配置管理员信息

生产环境不建议开启,容易被人攻击,适用于开发环境调试。

打开tomcat7下的~/conf/tomcat-users.xml文件,关于用户角色、管理员的信息都在这个配置文件中。在<tomcat-users>节点下添加如下内容:

<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="admin" password="admin" roles=" admin-gui , manager-gui "/>

2. 修改服务监听端口

默认监听的是8080,下面改成8090

vi  /usr/local/tomcat/conf/

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdcAAABSCAIAAACJ7AlJAAALFklEQVR4nO2dP2/jOBPGp9ouRYogRYDNdjECbJprzvkAceHKLvwBgkWAlAu3OeAaN2kuUHG9+wPiPvUB16jJd3g/wvZvIYuhyOEMLVF/HD0/GNhYHpFDrfx4PKQ5RAAAAAAAAID6nDz8+vry6/Lhvm9HAABgtHx7vniBFgMAQM/cnxVa/PTctycAAH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