Step-by-Step: Set Up CentOS7 VM, Network, JDK, MySQL & Tomcat
This tutorial walks through importing a CentOS7 virtual machine into VMware, configuring static or dynamic IP settings, installing JDK 1.8, setting up MySQL 5.7 with remote access, and deploying Tomcat 8.5 and a Spring Boot service for automatic startup, including common pitfalls and fixes.
1. Import CentOS7 Virtual Machine
Open VMware, click “Open Virtual Machine”, select the centos7.ova file, choose a storage path, and click “Import”.
After import, click “Edit virtual machine settings” to adjust CPU, memory, and disk as needed, then start the VM. Use Ctrl+Alt to release the mouse to Windows.
Log in with username root and password 123456.
2. Configure IP Address
Set the VMware network mode to Bridge . There are two ways to obtain an IP address:
Dynamic (DHCP) – edit /etc/sysconfig/network-scripts/ifcfg-enp0s3 (replace the interface name if different) and set:
BOOTPROTO="dhcp"
ONBOOT="yes"Restart the network service:
systemctl restart networkVerify with ip addr and test connectivity (e.g., ping www.baidu.com).
Static – edit the same file and set:
BOOTPROTO="static"
IPADDR="192.168.0.121"
NETMASK="255.255.255.0"
GATEWAY="192.168.0.1"
DNS1="114.114.114.114"After editing, restart the network service as above.
3. Common Pitfalls and Fixes
systemctl restart network fails : check systemctl status network.service and journalctl -xn.
Cannot ping external sites : verify IP conflict, remove duplicate ifcfg-* files, correct HWADDR, comment or delete the DEVICE line, ensure NAME matches the file name, delete UUID entries, and stop NetworkManager.service if necessary.
Example commands:
rm -f /etc/sysconfig/network-scripts/ifcfg-eXXX
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service4. Install JDK 1.8 on CentOS7
Check existing JDK:
java -versionDownload JDK from Oracle (e.g., official site ) and upload the jdk-8u281-linux-x64.tar.gz to /usr via SFTP.
Extract and set up:
cd /usr
tar -zxvf jdk-8u281-linux-x64.tar.gzConfigure 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/tools.jar
export PATH=$PATH:$JAVA_HOME/binApply changes:
source /etc/profileVerify installation:
java -version5. Install MySQL 5.7
Install wget then download the MySQL 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.rpmInstall the server package:
sudo yum -y install mysql-community-serverStart and enable on boot:
sudo systemctl start mysqld
sudo systemctl enable mysqldFind the temporary root password in /var/log/mysqld.log and change it:
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 port 3306 in the firewall:
sudo systemctl start firewalld.service
sudo firewall-cmd --add-port=3306/tcp --permanent
sudo firewall-cmd --reload
# optionally stop firewall
sudo systemctl stop firewalld.serviceSet default charset to UTF‑8 by editing /etc/my.cnf:
character_set_server=utf8
init_connect='SET NAMES utf8'Restart MySQL:
sudo systemctl restart mysqld6. Deploy Spring Boot Application as a Service
Upload the compiled 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.targetMake it executable and enable:
chmod +x /etc/systemd/system/java.service
systemctl daemon-reload
systemctl start java
systemctl enable java7. Install Tomcat 8.5
Download Tomcat from the official site and extract to /usr:
tar -zxvf apache-tomcat-8.5.63.tar.gzCreate a PID file and set environment variables in setenv.sh:
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 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.targetMake it executable, reload daemon, start and enable:
chmod +x /etc/systemd/system/tomcat.service
systemctl daemon-reload
systemctl start tomcat
systemctl enable tomcatCheck status with systemctl status tomcat.service and stop with systemctl stop tomcat. For multiple Tomcat instances, copy to different directories and create separate service files.
8. Final Remarks
After completing the above steps, you should have a fully functional CentOS7 environment with network connectivity, JDK 1.8, MySQL 5.7, Tomcat 8.5, and a Spring Boot application running as a systemd service. Restart the server to verify everything starts correctly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
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.
