admin 發表於 2019-9-12 14:27:33

How to install Tomcat 8.5 on Debian 8

网络上这篇文章值得参考看看
How to install Tomcat 8.5 on Debian 8
节录下一些重点看看
Install JavaThe 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_HOMENow 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:
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/jreexport JAVA_HOMEPATH=$JAVA_HOME/bin:$PATHexport PATHSave, exit and reload the file:
# source ~/.bashrcNow, executing the command:
# echo $JAVA_HOMEyou should read the correct path to Java.

Install TomcatOnce 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/tomcat-8/v8.5.11/bin/apache-tomcat-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 TomcatIn $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:
https://s24255.pcdn.co/wp-content/uploads/2017/02/1.png
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 serviceOnce you have shut down Tomcat, in the systemd system directory, create a new file:# $EDITOR /etc/systemd/system/tomcat.servicePaste the following configuration:
Description=Apache Tomcat 8 Servlet ContainerAfter=syslog.target network.targetUser=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-failureWantedBy=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 usersThis 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 tomcatConclusionThat’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!

頁: [1]
查看完整版本: How to install Tomcat 8.5 on Debian 8