部署前确保服务器满足以下最低配置,避免运行卡顿或存储不足:
以下为CentOS7.9环境下依赖安装命令,可直接复制执行,Ubuntu环境可替换为apt命令:
``` 1.更新系统源 yum update -y 2.安装Nginx、MySQL5.7、Redis6、JDK11 yum install nginx mysql-server redis java-11-openjdk -y 3.启动所有依赖并设置开机自启 systemctl start nginx mysqld redis systemctl enable nginx mysqld redis ```执行完成后需要初始化MySQL root密码,执行命令mysql_secure_installation按提示设置密码即可,牢记设置的root密码后续会用到。
直接执行以下命令下载官方适配镇江档案标准的程序包和初始化脚本:
``` 创建程序存放目录 mkdir -p /opt/archives cd /opt/archives 下载核心程序包 wget https://gitee.com/zhenjiang-archives/digital-archives-system/releases/download/v1.2.0/archives-system.jar 下载数据库初始化脚本 wget https://gitee.com/zhenjiang-archives/digital-archives-system/releases/download/v1.2.0/init.sql ```执行以下命令创建专用数据库、用户并导入初始化表结构:
``` 登录MySQL,输入之前设置的root密码 mysql -u root -p 执行以下SQL语句 CREATE DATABASE archives_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; CREATE USER 'archives_user'@'localhost' IDENTIFIED BY 'Ar@chives2024'; GRANT ALL PRIVILEGES ON archives_db. TO 'archives_user'@'localhost'; FLUSH PRIVILEGES; use archives_db; source /opt/archives/init.sql; exit; ```在/opt/archives目录下创建application.yml配置文件,以下为完整可直接复制的配置内容:
``` server: port: 8080 spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/archives_db?useUnicode=true&characterEncoding=utf8mb4&useSSL=false&serverTimezone=Asia/Shanghai username: archives_user password: Ar@chives2024 redis: host: localhost port: 6379 password: "" 若设置了Redis密码请填写此处 database: 0 servlet: multipart: max-file-size: 10GB max-request-size: 10GB web: resources: static-locations: file:/opt/archives/files/ archives: storage: path: /opt/archives/files/ max-quota-per-user: 100GB 单用户档案存储配额可按需调整 ```执行命令mkdir -p /opt/archives/files创建文件存储目录,再执行chown -R www:www /opt/archives给目录赋权,避免后续上传文件报错。

使用systemd管理系统服务,创建/usr/lib/systemd/system/archives.service文件,内容如下:
``` [Unit] Description=Zhenjiang Digital Archives System After=network.target mysqld.service redis.service [Service] Type=simple User=www Group=www WorkingDirectory=/opt/archives ExecStart=/usr/bin/java -jar archives-system.jar --spring.config.location=application.yml Restart=always RestartSec=5 StandardOutput=journal+console StandardError=journal+console [Install] WantedBy=multi-user.target ```执行以下命令启动服务:
``` systemctl daemon-reload systemctl start archives systemctl enable archives ```执行systemctl status archives查看服务状态,显示active(running)即为启动成功。
创建/etc/nginx/conf.d/archives.conf配置文件,内容如下:
``` server { listen 80; server_name 你的服务器公网IP或绑定的域名; client_max_body_size 10G; access_log /var/log/nginx/archives_access.log; error_log /var/log/nginx/archives_error.log; 档案文件静态资源访问 location /files/ { alias /opt/archives/files/; expires 30d; } 后台接口代理 location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; } } ```执行nginx -t验证配置无误后,执行nginx -s reload重载配置即可。
访问地址http://你的IP/admin进入后台,默认账号为admin,默认密码为Admin@123456,登录后第一时间进入「个人中心」修改默认密码,避免安全风险。
点击「档案上传」按钮上传任意测试文档,提交后进入「档案检索」页面搜索文件名,可正常查看、下载文件即为部署成功。