Virtual machine installation of CentOS7 and jdk1.8, mysql5.7, tomcat9

Article directory

1. Virtual machine installation CentOS7


The download speed of the official website is slow. You can download CentOS7 from the image of Huawei cloud.
If the link fails, you can directly access the Huawei cloud image official website , find the CentOS project, select the appropriate version to download


  1. New virtual machine
  2. Typical (recommended)
  3. Install the operating system later
  4. Linux centos7 64 bit
  5. Modify installation path
  6. Specify disk capacity
  7. To customize the hardware, click new CD / DVD - > use ISO image file, and select download CentOS7 image file
  8. Turn on virtual machine
  9. install CentOS 7
  10. Choose Chinese
  11. Click Network and host name to open network connection
  12. Click software selection and choose GNOME desktop
  13. Click Start installation to set the root password and create a new user.

Connecting to CentOS using xshell

xshell6 download address
Log in to the system and enter ip add to view the ip address

Enter ssh root@ in the xshell console. The ip address here is the one you just found.
Next, you will be prompted to enter the root account password. If the password is correct, the connection is successful.

2. Install jdk1.8

Uninstall OpenJDK

In general, OpenJDK is installed on linux, but the OpenJDK code is incomplete and only contains the thinnest jdk. In order to avoid problems in future project operation, it needs to be uninstalled and installed with the jdk provided by Oracle.
Enter java version to view the installed java version

[root@localhost ~]# java -version
openjdk version "1.8.0_222-ea"
OpenJDK Runtime Environment (build 1.8.0_222-ea-b03)
OpenJDK 64-Bit Server VM (build 25.222-b03, mixed mode)

Enter rpm -qa | grep java to query Java Suite

[root@localhost ~]# rpm -qa | grep java

Delete the java suite with openjdk with the following command

[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-headless-
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-
[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-


Create a new java folder in the user directory:

# cd /usr/
# mkdir java
# cd java

Method 1: use wget command to download directly from the server
Get into Select the linux version to get the download link, copy the link to the wget instruction, and then download it directly in the server

Method 2: download the jdk locally and upload it to the server with ftp tool
FileZilla Download

Decompress and configure environment variables

  1. Decompress: tar -zxvf package name file name press tab to complete
  2. Delete: rm -f package name
  3. See:
  4. Configure the environment variable vim /etc/profile, move the cursor to the last line, and press o to enter in the next line
export JAVA_HOME=/usr/java/jdk1.8.0_241
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export export PATH=$JAVA_HOME/bin:$PATH

5. Use the source /etc/profile command to make the changed configuration take effect immediately
6. Enter java version to see if the installation is complete

3. Install mysql5.7

Uninstall the pre installed database

MySQL is pre installed in CentOS 6, which needs to be uninstalled before installation. CentOS7 is pre installed with MariaDB, which is a branch of MySQL. What we need to install is mysql5.7
Check whether mysql has been installed, command: rpm -qa | grep mysql
If it has been installed, the above command will check the relevant installation information and uninstall it. Command: RPM - E -- nodes MySQL version
Check if the MariaDB database that comes with CentOS7 exists, and if so, uninstall it

[root@localhost ~]# rpm -qa | grep mariadb
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64


Go to the official website to download the rpm installation package


Create mysql Directory: mkdir /usr/local/src/mysql
Use ftp to upload the downloaded tar package to the directory
Unzip: tar - xvf mysql-5.7.29-1.el7.x86_.rpm-bundle.tar
Install the following four files in sequence:

# rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm
# rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm
# rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm
# rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm

Modify the configuration file my.cnf: vim /etc/my.cnf, and add a code under the [mysqld] label so that we can log in with an empty password: skip grant tables

Open mysql service: systemctl start mysqld.service
Empty password login: enter password prompt in mysql-uroot-p and enter directly to login successfully
Change Password:

mysql> use mysql; 
mysql> update user set authentication_string=password('123456') where user='root' and host='localhost'; #Set password to 123456
mysql>exit; #Quit mysql

Modify the configuration file my.cnfvim/etc/my.cnf, delete skip grant tables, and save to exit.
Restart mysql service: systemctl restart mysqld.service, recover password login.
The following prompts may appear after logging in:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

terms of settlement:

mysql>set global validate_password_policy=LOW; #Set the authentication strength level of the password
mysql>set global validate_password_length=6; #Set password length to 6
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';  #Change Password

Important setup

  1. Set startup auto start: systemctl enable mysqld.service
  2. Open external network segment access port 3306
#After logging in to mysql, switch to mysql library and execute the following command
[root@localhost src]# mysql -uroot -p123456
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; #  Here% means all IP addresses. If only one IP can be accessed, you can change% to a specific IP address. The above root represents root user, which can be changed to other user names as required. The above '123456' is the password of root user.
  1. Firewall configuration 3306 port allows external access
#Open 3306 port
firewall-cmd --zone=public --add-port=3306/tcp --permanent  
#Restart firewall  
firewall-cmd --reload 
#View open ports
firewall-cmd --list-ports 
  1. Verifying connections using Navicat
  2. Modify the code to utf-8
    View code:
mysql> show variables like 'character%';

Modify my.cnf file vim /etc/my.cnf, and add a line character set server = utf8 to the file

Restart MySQL systemctl restart mysqld.service

4. Install tomcat9


Create directory and download:

cd /usr/local/
mkdir tomcat
cd tomcat

If the link fails, you can go to the official website to find new links

Unzip: tar -xvf apache-tomcat-9.0.30.tar.gz
Command to turn tomcat on and off:

cd /usr/local/tomcat9/apache-tomcat-9.0.30/bin #Enter the bin directory under the installation directory
./ #Start tomcat
./ #Close tomcat

Firewall opens port 8080:

#Open port 8080
firewall-cmd --zone=public --add-port=8080/tcp --permanent  
#Restart firewall  
firewall-cmd --reload 
#View open ports
firewall-cmd --list-ports 

Configure self start

Under the apache-tomcat-9.0.30/bin directory, add the configuration, which will be called when starts, and configure the Java memory parameters.

cd /usr/local/tomcat9/apache-tomcat-9.0.30/bin

Add the following to

#add tomcat pid  
#add java opts  
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"  

Create a service name. Service (the service name here can be defined by yourself. It is recommended to use Tomcat or tomcat9) file, direct vim command, edit and save

cd /usr/lib/systemd/system
vim tomcat.service

Press i to insert the following

ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
#Configure startup 
systemctl enable tomcat.service
#Start tomcat
systemctl start tomcat.service
#Stop tomcat
systemctl stop tomcat.service
#Restart tomcat
systemctl restart tomcat.service
Published 3 original articles, won praise 0, visited 627
Private letter follow

Tags: MySQL Tomcat Java RPM

Posted on Sun, 02 Feb 2020 01:40:26 -0800 by ozace