Linux Installation JDK + Tomcat + MySQL tutorial



Linux version: CentOS 7 64 bit

The following operations are all performed under the root account

1、 To install the JDK:

1. Check and uninstall JDK

Check whether the system comes with JDK and related installation package. If so, uninstall it first.

Check JDK version:

java -version

Query all installed JDK RPM packages

rpm -qa|grep java
Linux Installation JDK + Tomcat + MySQL tutorial

If the JDK and the installation package are found, uninstall them in turn.

Uninstall command: RPM – E — nodeps name, which is found above.

rpm -e --nodeps java-1.6.0-openjdk-devel-
rpm -e --nodeps tzdata-java-2012j-1.el6.noarch

2. Download JDK1.8 64 bit

jdk-8u161-linux-x64. tar.gz When installing, the latest version of JDK is 8u161, you can download it according to your own needs. (mine is: jdk-8u181-linux-x64 tar.gz )

3. Install JDK

Will download the good JDK tar.gz Upload the package to the system / usr / local / Java (I use finalshell), CD it to the directory, and execute the decompression command:

cd /usr/local/java
tar -zxvf jdk-8u161-linux-x64.tar.gz

Decompression command: tar – zxvf file name

Remove installation files (not required)

rm -rf jdk-8u161-linux-x64.tar.gz

4. Configure environment variables

Edit / etc / profile file (can be edited directly with finalshell)

vim /etc/profile

Add the following configuration at the end of the file:

# jdk1.8.0_161


After editing, press ESC key, enter WQ or X! To save and exit.

(warm tips: in Linux system, it is not displayed to enter the password when logging in first. When editing a file, first enter the I, a, O commands to enter the editing state. After editing, press ESC to exit the editing mode and return to the command mode. In the command mode, input: WQ means save exit,: WQ! Force save exit,: W means save,: W File means save in another file: Q means exit, (Note:)

The last step is to reload the / etc / profile file through the source command to make the modified content valid in the current shell window

source /etc/profile

5. Test whether JDK is installed successfully

java -version

The Java version is displayed normally, and the configuration is successful~


2、 Install Tomcat

1. Check whether Tomcat is installed

Method 1: under the root permission, recursively search the file name containing Tomcat field from the root directory

sudo find / -name *tomcat*

Method 2

ps -ef |grep tomcat

If the following information is returned, Tomcat is not started

root     15721 15602  0 10:13 pts/0    00:00:00 grep tomcat

If the following information is returned, it indicates that Tomcat has been started (the first is the user who started the process, the second is the ID of the process, the third is the percentage of CPU occupied, and the fourth is the percentage of memory occupied)

Linux Installation JDK + Tomcat + MySQL tutorial
2. Download Tomcat (Tomcat 7 recommended) (mine: apache-tomcat-8.5.39 tar.gz )
(download address )

3. Install Tomcat

Will download the good… Tomcat tar.gz Upload the file to the server’s / usr / local / tomcat, CD to the directory, and execute the decompression command:

cd /usr/local/tomcat
tar -zxvf apache-tomcat-8.5.39.tar.gz 

After successful decompression, get the folder

Apache-tomcat-8.5.39, renamed Tomcat
mv apache-tomcat-8.5.39 tomcat

Remove installation files (not required)

rm -rf apache-tomcat-8.5.39.tar.gz

4. Configure environment variables

Edit / etc / profile file

vim /etc/profile

Add the following configuration at the end:

# Tomcat


Reload the / etc / profile file to take effect:

source /etc/profile

5. Configure Tomcat file

Enter Tomcat bin directory


Editor file


Locate ා OS specific support, and add the following configuration below this line:


Save and exit.

6. Install Tomcat service

cp /etc/init.d/tomcat

7. Start & test Tomcat

Start Tomcat


If there is no problem with the above, enter in the local browser to open the Tomcat home page.

Linux Installation JDK + Tomcat + MySQL tutorial

8. Set the power on and auto start

When the server is shut down and restarted, the service can not start itself with the computer startup. Then we can set the Tomcat service to boot.

Open the file of Linux boot settings, and write the following configuration file to the end of this file. Note that it is the last of the file. If you want to add other booting files in the future,

It can only be added before this. In a word, the following sentence should be kept at the end of the document.

Open the boot file / etc / RC. D/ rc.local

vi /etc/rc.d/rc.local

Add the following code:

#Java configuration environment variables
export JAVA_HOME=/usr/local/java/jdk1.8.0_181
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
#Tomcat configuration environment variable
export CATALINA_HOME=/usr/local/tomcat/tomcat
#Tomcat auto start

Tomcat relies on Java’s JDK, so JDK is also imported synchronously.

After completing the above steps, you can shut down CentOS and restart it to check.


3、 Install MySQL

1. MySQL relies on libaio, so install libaio first

yum install libaio

2. Check whether MySQL is installed

yum list installed | grep mysql

If installed, uninstall first

yum -y remove mysql-libs.x86_64

Check MySQL installed in other ways

rpm -qa | grep mysql

If so, use the RPM – e command or the RPM – E — nodeps command to uninstall

Name checked by RPM - e MySQL ා normal deletion mode
RPM - E -- nodeps check the name ා strong delete mode. If you use the above command to delete other files, you can use this command to forcibly delete them

After deletion, we can check whether MySQL has been successfully unloaded by using the RPM – QA | grep MySQL command!!

3. Install mysql

MySQL official website Yum source RPM installation package:

3.1 download MySQL GZ source installation package


3.2 copy to / usr / local / MySQL Directory:

3.3 decompression:

tar xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

3.4 name modification:

tar xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

4. Create users and user groups

groupadd mysql

useradd -r -g mysql mysql

The purpose is to modify the installation authorityMySQLThe owner of the directory ismysqlUser of groupMySQLgroup

chown -R mysql .

chgrp -R mysql .

6. Initialize the database

  bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql --datadir=/usr/local/mysql/mysql/data


This is my file directory. Under / usr / local / MySQL, you can store it as you like.. It’s OK to modify it.

6.1 after initialization, there will be an initialization password. Write it down in Notepad

6.2 generating configuration files

vim /etc/my.cnf
basedir = /usr/local/mysql/mysql
datadir = /usr/local/mysql/mysql/data
socket = /usr/local/mysql/mysql/mysql.sock
port = 3306
socket = /usr/local/mysql/mysql/mysql.sock

6.3 configuring MySQL service

cp /usr/local/mysql/mysql/support-files/mysql.server /etc/init.d/mysql
  chmod +x /etc/init.d/mysql

  chkconfig --add mysql


6.4 configure environment variables

Open/Etc / profile file, and fill in the following at the end

vim /etc/profile
# mysqlexport MYSQL_HOME=/usr/local/mysql/mysqlexport PATH=$PATH:$MYSQL_HOME/bin:$MYSQL_HOME/lib
Make environment variables work
source /etc/profile

7. Start mysql

service mysql start

8. Change initial password

mysql -u root -p

Enter the initial password and log in to MySQL (the password is changed and saved, and copy and paste when entering, the password will not be displayed on the console!! )

Change password

alter user'root'@'localhost' identified by 'root'
vim /etc/my.cnf

Add under [mysqld]


(this means to skip the authority verification and log in without password)

Then save and exit,

Restart MySQL

service mysql restart

Log in again with the new password.