1.项目部署环境准备
MySQL准备
[root@Services ~]# getenforce
Enforcing [root@Services ~]# setenforce 0
[root@Services ~]# systemctl stop firewalld.service --now
[root@Services ~]# ls -l vehicle.zip
-rw-r--r--. 1 root root 4497919 6月 17 15:08 vehicle.zip
# 导入项目数据
[root@Services ~]# ls vehicle_backend/sql/vehicle.sql
vehicle_backend/sql/vehicle.sql
#安装MySQL服务
[root@Services ~]# yum -y install mysql.x86_64 mysql-server.x86_64 #启动MySQL服务
[root@Services ~]# systemctl enable mysqld
[root@Services ~]# systemctl start mysqld #配置MySQL用户密码
[root@Services ~]# mysql
mysql> ALTER USER USER() IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec) mysql> EXIT Bye [root@Services ~]# #测试MySQL连接访问
[root@Services ~]# mysql -hlocalhost -uroot -p'123456' -e "SELECT USER();"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------------+
| USER() |
+----------------+
| root@localhost |
+----------------+
[root@Services ~]# mysql -hlocalhost -uroot -p'123456'
mysql> CREATE USER 'prouser'@'localhost' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO 'prouser'@'localhost'; Query OK, 0 rows affected (0.00 sec) mysql> EXIT; [root@Services ~]# mysql -hlocalhost -uprouser -p'123456' < vehicle_backend/sql/vehicle.sql
2.后端代码编译
# 调整后端配置
[root@Services ~]# cd vehicle_backend/
[root@Services vehicle_backend]# ls
pom.xml sql src vehicle.iml [root@Services vehicle_backend]# vim pom.xml
[root@Services vehicle_backend]# sed -rn '41,47p' pom.xml
mysql mysql-connector-java 8.0.26#设置MySQL驱动版本为8.0.26
runtime# cd src/main/resources/
[root@192 resources]# ls
application-vm.yml application.yml mapper sql [root@Services resources]# vim application-vm.yml
server: port: 8080
servlet: session: timeout: 86400
spring: servlet: multipart: max-file-size: 10MB max-request-size: 10MB datasource: # 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://localhost:3306/vehicle_management? characterEncoding=utf8&serverTimezone=UTC driver-class-name: com.mysql.cj.jdbc.Driver #调整驱动名称
username: prouser password: 123456
mybatis: mapper-locations: classpath*:mapper/*Mapper.xml
# configuration: # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
pagehelper: helper-dialect: mysql #reasonable: true
support-methods-arguments: true
params: count=countSql upload: project: /manage_backend linux-dir-url: /images/vehicle linux-img-prefix: http://images.project.tedu.cn/vehicle/ [root@Services resources]# vim application.yml #创建主配置文件
[root@Services resources]# cat application.yml
spring: profiles: active: vm [root@Services ~]# # 编译代码
[root@Services ~]# cd vehicle_backend/
[root@Services vehicle_backend]# ls
pom.xml sql src vehicle.iml [root@Services vehicle_backend]# yum -y install maven.noarch # 配置阿里云中央仓库
[root@Services ~]# vim /etc/maven/settings.xml
[root@Services ~]# sed -rn '159,165p' /etc/maven/settings.xml
车辆项目后端部署
nexus-aliyun * Nexus aliyun http://maven.aliyun.com/nexus/content/groups/public#本行存在,无需复制
[root@Services ~]# mvn -v
[root@Services vehicle_backend]# mvn clean package -Dmaven.test.skip=true
... [INFO] Replacing main artifact with repackaged archive [INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:24 min [INFO] Finished at: 2024-04-11T15:41:34+08:00 [INFO] ------------------------------------------------------------------------
[root@Services vehicle_backend]# ls target/vehicle-0.0.1-SNAPSHOT.jar
target/vehicle-0.0.1-SNAPSHOT.jar [root@Services vehicle_backend]# cd
3.项目后端部署
车辆项目后端部署
# 创建项目目录
[root@Services ~]# mkdir -p /usr/local/project/vehicle/
[root@Services ~]# cp vehicle_backend/target/vehicle-0.0.1-SNAPSHOT.jar
/usr/local/project/vehicle/
# 安装Java环境
[root@Services ~]# yum -y install java-1.8.0-openjdk-devel
[root@Services ~]# java -version
openjdk version "1.8.0_332"
OpenJDK Runtime Environment (build 1.8.0_332-b09)
OpenJDK 64-Bit Server VM (build 25.332-b09, mixed mode)
[root@Services ~]#
# 编写服务管理脚本
[root@Services ~]# vim /usr/local/project/vehicle/run.sh
[root@Services ~]# cat /usr/local/project/vehicle/run.sh
#!/bin/bash
start_project(){
nohup java -Dfile.encoding=utf-8 \
-jar /usr/local/project/vehicle/vehicle-0.0.1-SNAPSHOT.jar \
-Xmx256M \
-Xms128M \
-XX:MaxMetaspaceSize=256M \
-XX:MetaspaceSize=128M \
--server.port=8080 \
--spring.profiles.active=vm >/usr/local/project/vehicle/vehicle.log 2>&1 &
}
stop_project(){
# 编写service脚本
[root@Services ~]# vim /usr/lib/systemd/system/vehicle.service
[root@Services ~]# cat /usr/lib/systemd/system/vehicle.service
[Unit]
Description=VehicleProject Jar
After=sshd.service [Service]
ExecStart=/usr/local/project/vehicle/run.sh start
ExecStop=/usr/local/project/vehicle/run.sh stop
Type=forking [Install]
WantedBy=multi-user.target [root@Services ~]# systemctl daemon-reload # 启动服务
[root@Services ~]# systemctl enable vehicle.service --now
Created symlink /etc/systemd/system/multi-user.target.wants/vehicle.service → /usr/lib/systemd/system/vehicle.service. [root@Services ~]# ss -anptul | grep java
tcp LISTEN 0 100 *:8080 *:* users: (("java",pid=11096,fd=15)) [root@Services ~]# # 测试接口(需登录认证123456/123456)
4.前端部署
# 上传前端资源
[root@Services ~]# cp -r vehicle_frontend/dist /usr/local/project/vehicle/
[root@Services ~]# cd /usr/local/project/vehicle/
[root@Vehicle vehicle]# ls dist
css favicon.ico img index.html js
# 部署大屏幕
[root@Services ~]# cp -r vehicle_homepage /usr/local/project/vehicle/homepage
[root@Services ~]# ls /usr/local/project/vehicle/homepage/
data files homepage.html images index.html plugins resources start_c_1.html start.html start_with_pages.html [root@Services ~]# # 安装nginx
[root@Services ~]# yum -y install nginx
[root@Services ~]# vim /etc/nginx/nginx.conf
访问测试
[root@Services ~]# sed -rn '38,40p' /etc/nginx/nginx.conf
server { #listen 80 default_server;
#listen [::]:80 default_server;
[root@Services ~]# # 配置nginx发布资源
[root@Services ~]# vim /etc/nginx/conf.d/vehicle.conf
[root@Services ~]# cat /etc/nginx/conf.d/vehicle.conf
server { listen 80; server_name __; location / { root "/usr/local/project/vehicle/dist/"; index index.html index.htm; try_files $uri $uri/ /index.html; } location /dashboard/display/ { alias "/usr/local/project/vehicle/homepage/"; index homepage.html index.html index.htm; try_files $uri $uri/ /index.html; } location /api/ { proxy_pass http://localhost:8080/; } } [root@Services ~]# # 启动服务
[root@Services ~]# systemctl enable nginx.service --now
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service. [root@Services ~]# ss -anptul | grep nginx
tcp LISTEN 0 128 0.0.0.0:80 0.0.0.0:* users: (("nginx",pid=13668,fd=6),("nginx",pid=13667,fd=6),("nginx",pid=13666,fd=6)) [root@Services ~]#
5.访问测试