Install and configure java and tomcat under linux system


 

Personal habits put the source package under opt


 

1. Install jdk

       JDK is the running environment of java, and the whole jenkins is a var package, which is a program written by java.

1.1. Install via yum

       A. Install yum:

#yum install wget

           Download in opt directory

  #cd opt
  #wget http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

B. Download and upload

         A. Oracle officially downloads the latest version of jdk (jdk-8u171-linux-x64.tar.gz):

             http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

         B. Install upload command

yum -y install lrzsz 

         C. In the opt directory, run rz -be to upload the file.

rz -be

1.3. Unzip the tar package

tar -zxvf jdk-8u171-linux-x64.tar.gz

          ls confirms that it has been decompressed: (supplementary image)           

1.4 Move the decompressed files to /usr/local/

mv jdk1.8.0_171/ /usr/local/

         Confirm that it has been moved by ls under /usr/local/: (supplementary image)

1.5 Making java soft links  

ln -s /usr/loca/jdk /usr/local/java

            ln -s /usr/loca/jdk /usr/local/java

            ********Remove soft link: rm java********

            ********Why do soft links ************

           jdk often needs to be upgraded. If you upgrade and make a soft link, you only need to delete the previous soft link and make a new soft link (ln -s jdk1.9.0/java). The path in the program does not need to be changed, and the configuration file and environment variables do not need to be reconfigured.

           ******Whether it is java, tomcat, nginx is a soft link, linked to a version number, if you want to upgrade, point the soft link to the new version number ********

1.6 Configure environment variables

          1. Open environment variables

[root@training local]# vi /etc/profile

          2. Add /usr/local/java to PATH:

              Put the following sentence at the end of /etc/profile. PATH=/usr/local/java/bin:$PATH

          3. Log out and log in again, or directly execute source /etc/profile

          4. Run java -version to see if it is successful.

[root@training local]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

 


2. Install tomcat

   Tomcat is a java container and itself is a web container, which can provide web pages and parsing of java pages.

   All java development, either directly from the var package, or use the container.

 2.1 In the opt directory, download the latest version of tomcat from the apache official website .

[root@training opt]# wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.30/bin/apache-tomcat-8.5.30.tar.gz

[root@training opt]# ll
total 195740
-rw-r--r--. 1 root root   9541892 Apr  4 04:35 apache-tomcat-8.5.30.tar.gz
-rw-r--r--. 1 root root 190890122 Apr 27 17:15 jdk-8u171-linux-x64.tar.gz

 2.2 tomcat can be used directly after unpacking, provided that the jdk is installed correctly

[root@training opt]# tar -zxvf apache-tomcat-8.5.30.tar.gz

[root@training opt]# ll
total 195740
drwxr-xr-x. 9 root root       160 Apr 28 11:08 apache-tomcat-8.5.30
-rw-r--r--. 1 root root   9541892 Apr  4 04:35 apache-tomcat-8.5.30.tar.gz
-rw-r--r--. 1 root root 190890122 Apr 27 17:15 jdk-8u171-linux-x64.tar.gz

2.3 Move to /usr/local/

[root@training opt]# mv apache-tomcat-8.5.30 /usr/local/
[root@training opt]# cd /usr/local/
[root@training local]# ll
total 0
drwxr-xr-x. 9 root root 160 Apr 28 11:08 apache-tomcat-8.5.30

   2.4 Making Soft Links

[root@training local]# ln -s apache-tomcat-8.5.30/ tomcat
[root@training local]# ls
apache-tomcat-8.5.30  etc    include  jdk1.8.0_171  lib64    sbin   src
bin                   games  java     lib           libexec  share  tomcat

  2.5 tomcat needs to start

      Commands to start and stop tomcat: all under the bin of the main directory, there is a catalina.sh

[root@training local]# cd tomcat/
[root@training tomcat]# ls
bin   lib      logs    RELEASE-NOTES  temp     work
conf  LICENSE  NOTICE  RUNNING.txt    webapps
[root@training tomcat]# cd bin/
[root@training bin]# ls
bootstrap.jar                 daemon.sh         startup.sh
catalina.bat                  digest.bat        tomcat-juli.jar
catalina.sh                   digest.sh         tomcat-native.tar.gz
catalina-tasks.xml            setclasspath.bat  tool-wrapper.bat
commons-daemon.jar            setclasspath.sh   tool-wrapper.sh
commons-daemon-native.tar.gz  shutdown.bat      version.bat
configtest.bat                shutdown.sh       version.sh
configtest.sh                 startup.bat

  Start: sh catalina.sh start

[root@training bin]# sh catalina.sh start

Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/java
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

       Usually add a node when starting: start tomcat, and open the log by the way.

     (If there is no var package, it can be started in half a second. At this time, there is no var package. If you open the website, it will be a blank page)

 

[root@training bin]# sh catalina.sh start;tail -f ../logs/catalina.out
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/java
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

2.6 Check if port 8080 is enabled:

            See if the startup is successful, the default port of tomcat is 8080

           *****netstat -lnp: is to view the port ********

        A. Install net-tools:

[root@training bin]# yum install net-tools

     B. View port:

[root@training bin]# yum install net-tools

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1144/sshd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1243/master        
tcp6       0      0 :::8080                 :::*                    LISTEN      1728/java

  Log in with your browser:

Now the Edge login cannot find the page, because port 8080 is not added to the firewall to allow access.

 


3. How to use tomcat:

   3.1 Stop tomcat:

       Enter /tomcat/bin to stop catalina.sh, and use ps -ef | grep java to see if it is really stopped (the java process is gone).

[root@training bin]# sh catalina.sh stop
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/java
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@training bin]# ps -ef | grep java
root      1882  1320  0 13:16 pts/0    00:00:00 grep --color=auto java

 

     3.2 Enter the main directory (tomcat)/webapps, delete everything else, only one root is left, and the root is also cleared.

       Including manage should also be deleted. If manage is used and released to the public network, it will be broken in an instant.

[root@training tomcat]# cd webapps/
[root@training webapps]# ls
docs  examples  host-manager  manager  ROOT
[root@training webapps]# rm -rf docs/ examples/ host-manager/ manager/
[root@training webapps]# ls
ROOT
[root@training webapps]# pwd
/usr/local/tomcat/webapps
[root@training webapps]# cd ROOT/
[root@training ROOT]# pwd
/usr/local/tomcat/webapps/ROOT
[root@training ROOT]# rm -rf *
[root@training ROOT]# ls
[root@training ROOT]#

  3.3 Change the uppercase SHUTDOWN to anything in tomcat/conf/server.xml.

  This is a function that can turn off tomcat on the page and disable this function. (Or disable port 8005 as well)

[root@training tomcat]# cd conf/
[root@training conf]# vi server.xml

  --------- At this point, the security reinforcement of tomcat is completed, and you can add things to it. At least there will be no problems coming in from the vulnerabilities of tomcat itself, at least not from the tomcat pages, as well as the very simple exploitable vulnerabilities of manager and shutdown.

       3.4 How to put the project in tomcat

       tomcat itself can unpack the var package, but there is a drawback: put the var package in the big root directory, and the var package will be automatically unpacked as soon as tomcat is started. At this time, if you want to modify some parameters and configurations in the var package, after the modification, the next time you start tomcat, the parameters and configurations modified before the startup will be unpacked from the var package again, so you need to reconfigure them.

        So we all unpack the var package and then put it in the tomcat path before loading it, usually in the big root directory or a directory on the same level as the big root.


 

 

 

 

 

 

 

 

 

 

 

 

 

 

    

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325017993&siteId=291194637