未加星标

How to install Tomcat 8.5 on Debian 8

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二03 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

How to install Tomcat 8.5 on Debian 8
Introduction

Apache Tomcatis a Java Servlet Container which implementsseveral Java EE specifications including JavaServer Pages (JSP), Java Servlet, WebSocket and Java EL. It also provides an HTTP web server environment in which Java code can run. It’s distributed under the Apache License 2.0.

This tutorial explains how to install and configure Tomcat 8.5.11 on Debian 8 .

Getting started

Install Java

The first thing to do is to install python-software-properties , for managing repository:

# apt install python-software-properties -y

Next, add required repository:

# echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
# echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
# apt update

Now, you can install Java :

# apt install oracle-java8-installer -y

Accept the licence, and then wait for the installation process to complete. Next, check Java version:

# java -version

just to be sure that everything went well.

Configure JAVA_HOME

Now you need to configure the environment variable (JAVA_HOME) on the server:

# update-alternatives --config java

You should see the following Java path: /usr/lib/jvm/java-8-oracle/jre/bin/java

Edit the environment file /etc/environment , adding the following line:

JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre"

Save and exit.

Next, edit ~/.bashrc writing the lines:

JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH

Save, exit and reload the file:

# source ~/.bashrc

Now, executing the command:

# echo $JAVA_HOME

you should read the correct path to Java .

Install Tomcat

Once you have configured Java , it’s time to install Apache Tomcat . For that, we will use a “tomcat” as the user and group:

# groupadd tomcat
# useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

With this command we created a user named tomcat, which uses /opt/tomcat as the home directory. In /opt , download Tomcat:

# cd /opt && wget http://apache.panu.it/tomcat/tomcat-8/v8.5.11/bin/apache-tomcat-8.5.11.tar.gz

Next, extract the Tomcat archive.

# tar xzvf apache-tomcat-8.5.11.tar.gz

Rename the extracted folder “tomcat”:

# mv apache-tomcat-8.5.11 tomcat

Then, change the owner to the ‘tomcat’ user, and make all the files in the bin directory executable. To accomplish this, execute the following commands:

# chown -hR tomcat:tomcat tomcat
# chmod +x tomcat/bin/*

Next, you’ll need to define $CATALINA_HOME, which is an environment variable pointing to the base path of the Tomcat installation. In the ~/.bashrc write:

export CATALINA_HOME=/opt/tomcat

and reload the file:

# source ~/.bashrc Testing Apache Tomcat

In $CATALINA_HOME/bin there is a script, startup.sh . This starts and checks Tomcat. So, executing:

# $CATALINA_HOME/bin/startup.sh

you should see the following output:

Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-8-oracle/jre
Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.

Make sure that the last line is “Tomcat started.”; this means that Tomcat is correctly installed.

Tomcat uses the port 8080, so check that everything is okay:

# netstat -plntu | grep 8080

Result should belike this one:

tcp6 0 0 :::8080 :::* LISTEN 3294/java With your browser, go to the URL: localhost:8080

You should see the following page:


How to install Tomcat 8.5 on Debian 8

If you see this page it means that Tomcat is up and running correctly.

To shut down Tomcat, use this script:

# $CATALINA_HOME/bin/shutdown.sh Create a systemd service

Once you have shut down Tomcat, in the systemd system directory, create a new file:

# $EDITOR /etc/systemd/system/tomcat.service

Paste the following configuration:

[Unit]
Description=Apache Tomcat 8 Servlet Container
After=syslog.target network.target
[Service]
User=tomcat
Group=tomcat
Type=forking
Environment=CATALINA_PID=/opt/tomcat/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target

Save and exit.

Now, use systemd to start the Tomcat service and then add its service to start at boot time. The commands are:

# systemctl daemon-reload
# systemctl start tomcat
# systemctl enable tomcat

Now Tomcat is running on port 8080.

Configure users

This next step is necessary because we can’t access the site-manager dashboard. So:

# $EDITOR /opt/tomcat/conf/tomcat-users.xml

Under line 43, paste the following content:

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

Next, edit the context.xml file.

# $EDITOR /opt/tomcat/webapps/manager/META-INF/context.xml

Here, comment the following lines:

<Context antiResourceLocking="false" privileged="true" >
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
</Context>

Save, exit and restart Tomcat:

# systemctl restart tomcat Conclusion

That’s all! Now, you can go to localhost:8080/manager/html , which is the manager dashboard.

From now on, you can do everything through your browser. Tomcat 8.5 is running on your Debian 8 server!

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: TomcatJavaDebianWebSocketJSPJava EEEDIEPA
分页:12
转载请注明
本文标题:How to install Tomcat 8.5 on Debian 8
本站链接:http://www.codesec.net/view/534018.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(78)