Step-by-Step Guide: Deploy Applications to CentOS 7 Server with JDK, MySQL, Spring Boot & Tomcat
This tutorial walks through deploying applications on a CentOS 7 virtual machine, covering VMware import, network configuration (DHCP/static IP), troubleshooting connectivity issues, installing JDK 1.8, MySQL 5.7, configuring Spring Boot auto-start via systemd, and setting up Tomcat 8.5 as a service.
Importing CentOS 7 Virtual Machine
Open VMware, click "Open a Virtual Machine", select the centos7.ova file, choose a storage path, and click Import. When prompted, select "Don't show this message again" and click Retry. Then click "Edit virtual machine settings" to adjust processor, memory, and disk as needed, and start the VM. Press Ctrl+Alt to release the mouse cursor back to Windows. After boot, log in with username root and password 123456.
Configuring IP Address
Set Network Mode to Bridged
In VMware, set the network adapter to Bridged Mode so the VM gets an IP from the physical router.
Method 1: Dynamic IP (DHCP)
Prerequisite: router has DHCP enabled. Edit the network interface file: vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 Modify two parameters:
BOOTPROTO="dhcp"ONBOOT="yes"Restart network service: systemctl restart network Verify with ip addr and test connectivity with ping baidu.com.
Method 2: Static IP
Set BOOTPROTO="static" and add: IPADDR="192.168.0.121" (choose an unused address in your subnet)
NETMASK="255.255.255.0"GATEWAY="192.168.0.1"(VMware gateway IP) DNS1="114.114.114.114" Restart network service again.
Troubleshooting Network Issues
If systemctl restart network fails with "Job for network.service failed", or ping fails, try these steps in order:
Check IP conflict: From the host, ping the static IP to see if it's already in use.
Remove duplicate interface configs: Delete extra ifcfg-e* files in /etc/sysconfig/network-scripts/: rm -f /etc/sysconfig/network-scripts/ifcfg-eXXX Fix HWADDR (MAC address): Run ip addr to find the correct MAC, then edit the corresponding ifcfg-ensXX file and set HWADDR to that value, or simply delete the HWADDR line. Restart with service network restart.
Comment out or delete the DEVICE line in ifcfg-ethXX.
Ensure NAME matches the filename in ifcfg-xxx.
Delete the UUID line from the interface config file.
Stop and disable NetworkManager:
systemctl stop NetworkManager.service
systemctl disable NetworkManager.serviceThen restart network: service network restart.
Remove persistent udev rules: rm -f /etc/udev/rules.d/70-persistent-net.rules Ensure VMware virtual network services are running (check Windows Services for VMware NAT, DHCP, etc.).
Verify VMware network adapter is connected in the VM settings (bottom-right icon).
Last resort: reboot the VM .
If bridged mode still fails, fall back to NAT mode, configure DHCP first, then switch back to static IP after installing required packages.
Installing JDK 1.8 on CentOS 7
Check existing Java: java -version.
Download JDK 8u281 from Oracle:
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html.
Upload the tarball to the VM via SFTP:
sftp> lcd d:/tmp1
sftp> cd /usr
sftp> put jdk-8u281-linux-x64.tar.gz
sftp> mv jdk-8u281-linux-x64.tar.gz java1.8Extract and rename:
cd /usr
tar -zxvf java1.8
# creates jdk1.8.0_281Configure environment variables in /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/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/binApply changes: source /etc/profile.
Verify: java -version should show 1.8.0_281.
Installing MySQL 5.7 on CentOS 7
Install wget: yum -y install wget.
Download and install MySQL repo RPM:
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.rpmInstall server: sudo yum -y install mysql-community-server (takes a few minutes).
Start and enable: sudo systemctl start mysqld and sudo systemctl enable mysqld.
Find temporary root password in /var/log/mysqld.log: cat /var/log/mysqld.log Example password: waf_eHWkr42K.
Log in and change password (must meet policy: 8+ chars, upper/lower/digit/special):
sudo mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '1qaz!QAZ';Enable remote root access:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1qaz!QAZ' WITH GRANT OPTION;
exitOpen firewall port 3306:
sudo systemctl start firewalld.service
sudo firewall-cmd --add-port=3306/tcp --permanent
sudo firewall-cmd --reloadSet default charset to UTF-8: edit /etc/my.cnf and add under [mysqld]:
character_set_server=utf8
init_connect='SET NAMES utf8'Restart MySQL: sudo systemctl restart mysqld. Verify with show variables like '%chara%';.
Test remote connection with Navicat or similar tool.
Key file locations:
Data: /var/lib/mysql Config: /etc/my.cnf Logs:
/var/log/mysqld.logSpring Boot Auto-start with systemd
Import the database schema into MySQL.
Upload the built JAR to /usr/local/project/springboot.jar. Test run: java -jar springboot.jar.
Create a systemd service file:
cd /etc/systemd/system
vi java.serviceContent:
[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.targetAdd execute permission: chmod +x /etc/systemd/system/java.service.
Reload daemon: systemctl daemon-reload.
Start and enable:
systemctl start java
systemctl enable javaVerify: ps -ef | grep java | grep -v grep and systemctl status java.service -l.
Installing Tomcat 8.5 as a systemd Service
Download Tomcat 8.5.63: https://tomcat.apache.org/download-80.cgi.
Upload to /usr/ and extract: tar -zxvf apache-tomcat-8.5.63.tar.gz.
Create a PID file in Tomcat root: touch tomcat.pid.
Create setenv.sh in bin/ with JVM 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 -XX:MaxNewSize=256m"Create systemd service file: vi /etc/systemd/system/tomcat.service Content:
[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.targetAdd execute permission: chmod +x /etc/systemd/system/tomcat.service.
Reload daemon: systemctl daemon-reload.
Start and enable:
systemctl start tomcat
systemctl enable tomcatCheck status: systemctl status tomcat.service. Stop with systemctl stop tomcat. List processes: ps -ef | grep tomcat | grep -v grep.
For multiple Tomcat instances, copy to different directories, change ports in server.xml, and create separate service files (e.g., tomcat1.service, tomcat2.service).
Reboot the server to verify auto-start works.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
