Operations 14 min read

Set Up CentOS 7 VM, Configure IP, Install JDK, MySQL, Tomcat & Auto-Start

This guide walks through importing a CentOS 7 virtual machine in VMware, configuring network settings (dynamic or static IP), resolving common issues, then installing and configuring JDK 1.8, MySQL 5.7, and Tomcat 8.5, and finally creating systemd services for automatic startup of Java applications.

Open Source Linux
Open Source Linux
Open Source Linux
Set Up CentOS 7 VM, Configure IP, Install JDK, MySQL, Tomcat & Auto-Start

1. Import CentOS 7 Virtual Machine

Open VMware, click "Open Virtual Machine", select the centos7.ova file and choose a storage path. Click the import button, dismiss the warning by selecting "Do not show this message again", and click "Retry". Edit the VM settings to adjust CPU, memory, and disk size, then start the VM. Use Ctrl+Alt to release the mouse to Windows. Log in with username root and password 123456 after a successful boot.

2. Configure IP Address

Set the VMware network mode to Bridged . CentOS 7 can obtain an IP address either dynamically (DHCP) or statically.

Dynamic IP (DHCP)

Edit the NIC configuration file (replace enp0s3 with your actual interface name): vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 Set the following two parameters:

BOOTPROTO="dhcp"
ONBOOT="yes"

Restart the network service: systemctl restart network After the restart, ip addr should show an assigned IP and you can ping external sites (e.g., Baidu).

Static IP

BOOTPROTO="static"
IPADDR="192.168.0.121"
NETMASK="255.255.255.0"
GATEWAY="192.168.0.1"
DNS1="114.114.114.114"

3. Common Pitfalls and Fixes

Network restart error

Job for network.service failed. See ‘systemctl status network.service’ and ‘journalctl -xn’ for details.

Ping failure

Typical solutions include:

Eliminate IP conflicts by pinging the target IP from the host.

Delete duplicate NIC configuration files that start with ifcfg-e: rm -f /etc/sysconfig/network-scripts/ifcfg-eXXX Correct an incorrect HWADDR by checking ip addr and editing the corresponding ifcfg-* file, or simply remove the HWADDR line.

Stop NetworkManager if it interferes:

systemctl stop NetworkManager.service
systemctl disable NetworkManager.service

Delete persistent udev rules: rm -f /etc/udev/rules.d/70-persistent-net.rules Ensure the DEVICE line is commented out or removed, and that the NAME matches the file name.

Finally, restart the network service:

service network restart

4. Install JDK 1.8 on CentOS 7

Check if JDK is already installed: java -version Download JDK 1.8 from Oracle, then upload the tarball (e.g., jdk-8u281-linux-x64.tar.gz) to /usr on the CentOS VM via SFTP and rename it to java1.8:

sftp> lcd d:/tmp1
sftp> cd /usr
sftp> put jdk-8u281-linux-x64.tar.gz
sftp> mv jdk-8u281-linux-x64.tar.gz java1.8

Extract and install:

cd /usr
tar -zxvf java1.8

Configure environment variables by editing /etc/profile (as root):

# java environment
export JAVA_HOME=/usr/jdk1.8.0_281
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

Save the file, then apply the changes: source /etc/profile Verify the installation:

java -version

5. Install MySQL 5.7

Install wget and download the MySQL community repository RPM:

yum -y install wget
sudo wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
sudo rpm -ivh mysql57-community-release-el7-10.noarch.rpm

Install the server package: sudo yum -y install mysql-community-server Start and enable the service:

sudo systemctl start mysqld
sudo systemctl enable mysqld

Find the temporary root password: cat /var/log/mysqld.log Change the root password:

ALTER USER 'root'@'localhost' IDENTIFIED BY '1qaz!QAZ';

Allow remote login:

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

Open firewall port 3306:

sudo systemctl start firewalld.service
sudo firewall-cmd --add-port=3306/tcp --permanent
sudo firewall-cmd --reload

Set the default character set to UTF‑8 by editing /etc/my.cnf and adding:

character_set_server=utf8
init_connect='SET NAMES utf8'

Restart MySQL to apply:

sudo systemctl restart mysqld

6. Set Up Spring Boot Project Auto‑Start

Import the MySQL database, then upload the built springboot.jar to /usr/local/project/.

Create a systemd service file /etc/systemd/system/java.service:

[Unit]
Description=java
After=syslog.target

[Service]
Type=simple
ExecStart=/usr/jdk1.8.0_281/bin/java -jar /usr/local/project/springboot.jar

[Install]
WantedBy=multi-user.target

Make the service executable, reload the daemon, and enable it:

chmod +x /etc/systemd/system/java.service
systemctl daemon-reload
systemctl start java
systemctl enable java

7. Install Tomcat 8.5

Download Tomcat 8.5 from the official site and upload the archive to /usr: tar -zxvf apache-tomcat-8.5.63.tar.gz Create a PID file: touch /usr/apache-tomcat-8.5.63/tomcat.pid Add a setenv.sh script in tomcat/bin with memory options:

export CATALINA_HOME=/usr/apache-tomcat-8.5.63
export CATALINA_BASE=/usr/apache-tomcat-8.5.63
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M"

Create a systemd service file /etc/systemd/system/tomcat.service:

[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
Environment="JAVA_HOME=/usr/jdk1.8.0_281"
PIDFile=/usr/apache-tomcat-8.5.63/tomcat.pid
ExecStart=/usr/apache-tomcat-8.5.63/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Make the service file executable, reload, and enable:

chmod +x /etc/systemd/system/tomcat.service
systemctl daemon-reload
systemctl start tomcat
systemctl enable tomcat

Check status with systemctl status tomcat.service and manage the process with standard systemctl commands.

Article source: Linux运维进阶之路

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

mysqlJDKTomcatVMwareNetwork ConfigurationCentOSsystemd
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.