[Linux Virtual Machine] JDK, Tomcat, MySQL installation and configuration explanation

Table of Contents

1. Upload the installation package to the server

2. JDK and Tomcat installation

2.1 Unzip the installation package

2.2 Configure JDK environment variables

2.3 Configure Tomcat environment

3. MySQL installation and configuration

3.1 Delete the default database

3.2 Install the mysql installation package

3.3 mysql initialization operation

4. Backend interface deployment

4.1 Import project.war

4.2 Create a new database

4.3 Run server project test


1. Upload the installation package to the server

1. Use the MobaXterm remote tool I used in my last blog to connect to the virtual machine IP address, and then create a folder to store jdk and other decompressed packages.

2. Find the downloaded file path and use drag and drop (copy and paste) to upload it.

3. Pay attention to the upload progress in the lower left corner. After the upload is completed, you can view the file on the virtual machine.

Why use the MobaXterm tool?

Compared with other server connection tools, such as: Xshell and FinalShell;

Xshell:

  • Commercial software: Xshell is commercial software and requires purchasing a license to use its advanced features.
  • Windows only: Xshell is mainly available for Windows operating systems and has limited support for other operating systems.

FinalShell:

  • Relatively few functions: Compared with other tools, FinalShell has relatively few functions and may not be suitable for some advanced remote management needs.
  • Simple user interface: FinalShell’s user interface is relatively simple and may not be intuitive and easy to use.

The MobaXterm tool is easier to use than others, but the functions of MobaXterm are relatively complex, and it may take some time for novice users to become familiar with and master it. (Finally, Xshell does not support the ability to quickly view files and upload files using drag and drop)

2. JDK and Tomcat installation

2.1 Unzip the installation package

Extraction command:

tar -zxvf compressed file name.tar.gz

Parameter Description:
z: Indicates that the compressed file is gzip compressed
x: means to perform decompression, if the c parameter is used, it means compression
v: Display detailed processing process
f: the file name to be operated on
-C: Decompress to the specified directory, such as: tar -zxf abc.tar.gz -C /root Decompress abc.tar.gz to the root directory.

2.2 Configure JDK environment variables

1. Enter the configuration file instructions:

vi /etc/profile

2. Add java environment variables to the configuration file:

#java environment
export JAVA_HOME=/javaxl/software/jdk1.8.0_151 (jdk decompression path)
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

3. Set the environment variable to take effect:

source /etc/profile

2.3 Configure Tomcat environment

First, enter the tomcat bin directory and you can see the startup.sh file that starts the service.

But now Tomcat cannot be accessed immediately after starting because port 8080 is blocked by the firewall. You can turn off the firewall (not recommended) or configure port 8080 in the firewall.

instruction:

firewall-cmd --zone=public --add-port=8080/tcp --permanent

But now it is still inaccessible and the firewall rules need to be refreshed.

Firewall rule instructions:

firewall-cmd --reload

Then start the Tomcat service for access:

./startup.sh

Additional directives:

  • Turn off firewall
systemctl stop firewalld.service
  • Start automatically at boot
systemctl enable firewalld.service

3. MySQL installation and configuration

3.1 Delete the default database

There should be default data in CentOS. First check the virtual machine database instructions:

rpm -qa|grep mariadb

Then run the command to delete the local default database:

#rpm -e --nodeps local default database
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

3.2 Install the mysql installation package

1. Unzip mysql to the specified file path

First you must have the mysql-5.7 folder

tar -xvf mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar -C mysql-5.7

2. Start installation

rpm -ivh mysql-community-common-5.7.23-1.el7.x86_64.rpm
 
rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-5.7.23-1.el7.x86_64.rpm //Client
 
rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm //Server

-ivh where i means installation, v means display the installation process, and h means display progress

3.3 mysql initialization operation

1. Start the MySQL service

systemctl start mysqld

2. Check the initialization password

grep "password" /var/log/mysqld.log

3. Log in to mysql and lower the password setting level.

#Set the password verification policy (0 or LOW), or the password is too simple to allow you to pass
set global validate_password_policy=0;
#Set the password verification length, otherwise the password will not be allowed to pass if it is too short (multiple tests found that the minimum password length is 4 digits)
set global validate_password_length=4;

4. Change the password and refresh the service

#Update password
set password = password("123456");
#After input, the following statement is needed to make the modification effective.
FLUSH PRIVILEGES;

5. Grant permissions to the root user

#Centos7 cannot remotely connect to the mysql database because the database is not authorized. The setting allows remote login to mysql as root.
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
#After input, the following statement is needed to make the modification effective.
FLUSH PRIVILEGES;

6. Open Navicat to test the connection

4. Backend interface deployment

4.1 Import project.war

How to import a project into a war, recommended article: How does IDEA package a web project into a war package? The most detailed graphic tutorial – Keeling1720

Then import the back-end project into a .war package and copy it to the virtual machine Tomacat/webapps/ path

4.2 Create a new database

Create a database to use based on imported projects

4.3 Run server project test

1. Restart the Tomcat service

Because new files have been imported, the tomcat service needs to be restarted.

2. Access server test

Because this project uses jwt technology, you need to log in to access it. However, since this tutorial is about deploying a back-end project and not deploying a front-end, it is inconvenient to perform login verification. As long as this interface does not appear, it means that the access is successful.

The next article will explain the deployment of front-end projects, so stay tuned!

The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Java Skill TreeHomepageOverview 138,700 people are learning the system