The whole process of deploying Java Web project on linux server

Posted by jozard on Sun, 19 Dec 2021 10:31:33 +0100

preface

I use:

  1. Development tool: idea
  2. jdk: 1.8
  3. mysql: 5.7.35
  4. tomcat: 8.0.35
  5. ssh tool: FinalShell

1, Environment configuration and construction

1. Installation and configuration of JDK

  1. download
    1) I use the Linux version of tar GZ compressed package, you need to download others by yourself

  2. install
    1) After downloading, put the compressed package in the specified directory of the server. I put it in the java file of usr here. After that, basically all installations are under usr
    2) Decompress

    	tar -zxvf jdk-8u301-linux-x64.tar.gz
    
  3. to configure
    1) Similar to windows, configure the environment and find the etc/profile file
    2) vim command to open the file, add the following content, and modify it according to your jdk location

    export JAVA_HOME=/usr/java/jdk1.8.0_301
    export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
    export PATH=$PATH:${JAVA_HOME}/bin
    

    3) Then exit editing and re execute the profile file, source /etc/profile
    4) Testing

     java -version
    

2. Mysql installation and configuration

  1. download
    https://dev.mysql.com/downloads/mysql/5.7.html#downloads

  2. install
    decompression

    tar -zxvf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz
    
  3. to configure
    1) Modify file name

    mv mysql-5.6.44-linux-glibc2.12-x86_64  mysql
    

    2) Environment configuration, find the etc/profile, vim command, and add the following

    export MYSQL_HOME=/usr/mysqld/mysql
    export PATH=$PATH:$MYSQL_HOME/bin:$MYSQL_HOME/lib
    

    3) Start mysql

    service mysqld start
    

    4) Set on self start

    chkconfig --list | grep mysqld
    
    chkconfig  mysqld on
    

    5) Create the root user and set the password

    mysqladmin -u root password 'root';
    

    6) Configure permissions and modify passwords
    a. Login to mysql

    mysql -u root -p
    

    b. Configure the permissions for Database Internet access

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
    

    c. Change password

    UPDATE mysql.user SET password=PASSWORD('New password') WHERE User='root';
    

    After modification, execute this command

    FLUSH PRIVILEGES;()
    

    7) Stop mysql

    service mysqld stop
    

    8) Restart mysql

    service mysqld restart
    

3. Tomcat installation and configuration

  1. download
    https://tomcat.apache.org/download-80.cgi

  2. install
    1) Decompress

    tar -zxvf apache-tomcat-8.5.37.tar.gz
    

    2) Modify file name

    mv apache-tomcat-8.5.37 tomcat
    
  3. to configure
    1) Environment configuration, find the etc/profile, vim command, and add the following

    export CATALINA_HOME=/usr/tomcat
    export PATH=$PATH:$CATALINA_HOME/bin:$CATALINA_HOME/lib
    

    2) Modify port number

    3) Start
    Enter the bin directory of the tomcat file

    ./startup.sh
    

    4) Testing
    Access the ip + port number to see if the tomcat screen will appear

2, Deployment project

  1. to configure
    1) Port number modification (use the port number defined by yourself)

    2) Modify the database in the configuration file, and change the user name and password of Mysql to that of the server mysql

  2. Packing note: I use idea development here

    I called the war package. If you have different needs, you can go to the POM of the main project XML self modification

  3. Deployment project
    1) Upload the downloaded war package to the webapps directory under tomcat on the server

    2) Stop tomcat from executing in the bin directory

    mv apache-tomcat-8.5.37 tomcat
    

    3) On tomcat's server Add the startup page specified by the project to the XML

    	<Context path="" docBase="/usr/tomcat/webapps/war Package name" debug="0" reloadable="true" crossContext="true"/>
    

    4) Start Tomcat/ startup. sh

    ./startup.sh
    

4. Test project browser request ip + port

Topics: Java Linux