Deploying a Spring Boot Application on Tencent Cloud Lighthouse with Persistent Background Execution
Provisioning the Cloud Environment
Begin by registering or logging into your Tencent Cloud account. Complete identity verification as required to activate services.
Required Components
- Cloud Instance: Tencent Cloud Lighthouse running CentOS 7.8 (64-bit)
- Local Application: A Spring Boot + MyBatis Plus-based news management system
- Client Tools:
- Xshell 6 for SSH access
- Navicat Premium for database export
- WinSCP for file transfer
Migrating the Local Database
Export the local database using Navicat Premium: right-click the database, select Dump SQL File, and include both structure and data.
On the server, use phpMyAdmin (installed via BT Panel) to import the dump:
- Create a new database with the same name as the original.
- Use the Import tab to upload and execute the SQL file.
- Verify that tables and data are correctly restored.
Adjusting Application Configuration
Edit application.properties to avoid port conflicts. Since the server already runs a standalone Tomcat on port 8080, configure the embedded Tomcat in Spring Boot to use an alternative port:
server.port=9001
Packaging and Uploading the Application
Use Maven to package the project:
mvn clean package
This generates a JAR file in the target/ directory. Create a dedicated directory on the server (e.g., /usr/newsapp) and upload the JAR ussing WinSCP.
Running the Application
Foreground Execution (Not Recommended for Production)
java -jar news-system-0.0.1-SNAPSHOT.jar
This process terminates when the SSH session ends.
Persistent Background Execution
Create a startup script to ensure the application runs independently of the terminal session:
vim /usr/newsapp/start.sh
Insert the following content (press i to enter insert mode):
#!/bin/bash
nohup java -jar /usr/newsapp/news-system-0.0.1-SNAPSHOT.jar > app.log 2>&1 &
Save and exit (Esc, then :wq). Make the script executable:
chmod +x /usr/newsapp/start.sh
Launch the application:
sh /usr/newsapp/start.sh
Verify the process is runing:
ps aux | grep news-system
The application is now accessible via http://<server-public-IP>:9001.
To stop the service, identify the process ID and terminate it:
ps aux | grep news-system
kill <PID>