熱搜: 活動 交友 discuz
查看: 35|回復: 0

How to install Tomcat 8.5 on Debian 8










Rank: 9Rank: 9Rank: 9

發表於 2019-9-12 14:27:33 | 顯示全部樓層 |閱讀模式 简体中文繁體中文
How to install Tomcat 8.5 on Debian 8
Install Java
The first thing to do is to install python-software-properties, for managing repository:
# apt install python-software-properties -yNext, 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 updateNow, 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 -versionjust 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 javaYou 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:
Save and exit.
Next, edit ~/.bashrc writing the lines:
JAVA_HOME=/usr/lib/jvm/java-8-oracle/jreexport JAVA_HOMEPATH=$JAVA_HOME/binPATHexport PATHSave, exit and reload the file:
# source ~/.bashrcNow, executing the command:
# echo $JAVA_HOMEyou 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 tomcatWith 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/tom ... omcat-8.5.11.tar.gzNext, extract the Tomcat archive.
# tar xzvf apache-tomcat-8.5.11.tar.gzRename the extracted folder “tomcat”:
# mv apache-tomcat-8.5.11 tomcatThen, 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 ~/.bashrcTesting Apache Tomcat
In $CATALINA_HOME/bin there is a script, startup.sh. This starts and checks Tomcat. So, executing:
# $CATALINA_HOME/bin/startup.shyou should see the following output:
Using CATALINA_BASE:   /opt/tomcatUsing CATALINA_HOME:   /opt/tomcatUsing CATALINA_TMPDIR: /opt/tomcat/tempUsing JRE_HOME:        /usr/lib/jvm/java-8-oracle/jreUsing CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jarTomcat 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 8080Result should be like this one:
tcp6 0 0 :::8080 :::* LISTEN 3294/java
With your browser, go to the URL: localhost:8080
You should see the following page:

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.shCreate a systemd service
Once you have shut down Tomcat, in the systemd system directory, create a new file:
# $EDITOR /etc/systemd/system/tomcat.servicePaste the following configuration:
[Unit]Description=Apache Tomcat 8 Servlet ContainerAfter=syslog.target network.target[Service]User=tomcatGroup=tomcatType=forkingEnvironment=CATALINA_PID=/opt/tomcat/tomcat.pidEnvironment=CATALINA_HOME=/opt/tomcatEnvironment=CATALINA_BASE=/opt/tomcatExecStart=/opt/tomcat/bin/startup.shExecStop=/opt/tomcat/bin/shutdown.shRestart=on-failure[Install]WantedBy=multi-user.targetSave 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 tomcatNow 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.xmlUnder 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.xmlHere, 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 tomcatConclusion
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!

最近訪問 頭像模式 列表模式
您需要登錄後才可以回帖 登錄 | 立即註冊


小黑屋|手機版|Archiver|Hippies 手作皮革工作坊  

GMT+8, 2019-10-17 13:03 , Processed in 0.038600 second(s), 24 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表