教育部门数字档案馆系统从零搭建与部署实战指南
系统架构设计与技术选型
本系统采用微服务架构,前端使用Vue 3 + TypeScript,后端使用Spring Boot 2.7,数据库采用PostgreSQL 14,文件存储使用MinIO,全文检索使用Elasticsearch 7.17。
硬件环境要求
最低配置:4核CPU/8GB内存/200GB SSD存储。生产环境建议:8核CPU/16GB内存/500GB SSD存储,并配置RAID 1磁盘阵列。
软件依赖清单
- JDK 17.0.2
- Node.js 16.14.0
- PostgreSQL 14.2
- MinIO RELEASE.2022-03-17T06-34-49Z
- Elasticsearch 7.17.0
- Nginx 1.20.2
环境准备与依赖安装
操作系统配置
使用CentOS 7.9系统,执行以下命令进行基础配置:
``` 关闭防火墙(生产环境需配置安全组规则) systemctl stop firewalld systemctl disable firewalld 设置时区 timedatectl set-timezone Asia/Shanghai 安装基础工具 yum install -y wget vim net-tools ```Java环境安装
下载并安装JDK 17:
``` wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm rpm -ivh jdk-17_linux-x64_bin.rpm 配置环境变量 echo 'export JAVA_HOME=/usr/java/jdk-17.0.2' >> /etc/profile echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile source /etc/profile ```数据库安装配置
安装PostgreSQL 14:
``` 添加PostgreSQL官方仓库 yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm 安装PostgreSQL yum install -y postgresql14-server 初始化数据库 /usr/pgsql-14/bin/postgresql-14-setup initdb 启动服务 systemctl start postgresql-14 systemctl enable postgresql-14 ```创建数据库和用户:
``` 切换到postgres用户 su - postgres 创建数据库 createdb edu_archive 创建用户并设置密码 createuser archive_admin psql -c "ALTER USER archive_admin WITH PASSWORD 'StrongPass123!';" psql -c "GRANT ALL PRIVILEGES ON DATABASE edu_archive TO archive_admin;" ```核心组件部署
MinIO对象存储部署
下载并安装MinIO:
``` wget https://dl.min.io/server/minio/release/linux-amd64/minio chmod +x minio mkdir -p /data/minio 创建启动脚本 cat > /etc/systemd/system/minio.service << EOF [Unit] Description=MinIO After=network.target [Service] Type=simple User=root ExecStart=/usr/local/bin/minio server /data/minio --console-address ":9001" Restart=on-failure [Install] WantedBy=multi-user.target EOF 移动MinIO到系统目录 mv minio /usr/local/bin/ systemctl daemon-reload systemctl start minio systemctl enable minio ```访问http://服务器IP:9001,使用默认账号minioadmin/minioadmin登录,创建名为edu-archive的存储桶。
Elasticsearch部署
下载并安装Elasticsearch:
``` wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.0-linux-x86_64.tar.gz tar -xzf elasticsearch-7.17.0-linux-x86_64.tar.gz mv elasticsearch-7.17.0 /usr/local/elasticsearch 创建elasticsearch用户 useradd elasticsearch chown -R elasticsearch:elasticsearch /usr/local/elasticsearch 修改配置文件 vim /usr/local/elasticsearch/config/elasticsearch.yml ```配置文件内容:
``` cluster.name: edu-archive node.name: node-1 path.data: /var/lib/elasticsearch path.logs: /var/log/elasticsearch network.host: 0.0.0.0 http.port: 9200 discovery.type: single-node xpack.security.enabled: false ```启动Elasticsearch:
``` 创建数据目录 mkdir -p /var/lib/elasticsearch mkdir -p /var/log/elasticsearch chown -R elasticsearch:elasticsearch /var/lib/elasticsearch chown -R elasticsearch:elasticsearch /var/log/elasticsearch 修改系统参数 echo "elasticsearch soft nofile 65536" >> /etc/security/limits.conf echo "elasticsearch hard nofile 65536" >> /etc/security/limits.conf echo "vm.max_map_count=262144" >> /etc/sysctl.conf sysctl -p 启动服务 su - elasticsearch -c "/usr/local/elasticsearch/bin/elasticsearch -d" ```后端服务部署
项目编译与打包
下载项目源码并编译:
``` git clone https://github.com/edu-archive/backend.git cd backend 修改配置文件 vim src/main/resources/application-prod.yml ```配置文件内容:
``` spring: datasource: url: jdbc:postgresql://localhost:5432/edu_archive username: archive_admin password: StrongPass123! driver-class-name: org.postgresql.Driver jpa: hibernate: ddl-auto: update show-sql: true servlet: multipart: max-file-size: 500MB max-request-size: 500MB minio: endpoint: http://localhost:9000 accessKey: minioadmin secretKey: minioadmin bucketName: edu-archive elasticsearch: host: localhost port: 9200 server: port: 8080 ```
编译打包:
``` 使用Maven打包 mvn clean package -DskipTests 生成的jar包在target目录下 ls target/edu-archive-backend-1.0.0.jar ```服务部署与启动
创建服务启动脚本:
``` 创建应用目录 mkdir -p /opt/edu-archive/backend cp target/edu-archive-backend-1.0.0.jar /opt/edu-archive/backend/ 创建启动脚本 cat > /opt/edu-archive/backend/start.sh << EOF !/bin/bash nohup java -jar edu-archive-backend-1.0.0.jar --spring.profiles.active=prod > app.log 2>&1 & EOF chmod +x /opt/edu-archive/backend/start.sh ```创建systemd服务:
``` cat > /etc/systemd/system/edu-archive.service << EOF [Unit] Description=Edu Archive Backend Service After=network.target postgresql-14.service [Service] Type=simple User=root WorkingDirectory=/opt/edu-archive/backend ExecStart=/usr/bin/java -jar edu-archive-backend-1.0.0.jar --spring.profiles.active=prod Restart=on-failure [Install] WantedBy=multi-user.target EOF 启动服务 systemctl daemon-reload systemctl start edu-archive systemctl enable edu-archive ```前端服务部署
环境准备与项目构建
安装Node.js环境:
``` 下载Node.js wget https://nodejs.org/dist/v16.14.0/node-v16.14.0-linux-x64.tar.xz tar -xJf node-v16.14.0-linux-x64.tar.xz mv node-v16.14.0-linux-x64 /usr/local/node 配置环境变量 echo 'export PATH=/usr/local/node/bin:$PATH' >> /etc/profile source /etc/profile ```下载并构建前端项目:
``` git clone https://github.com/edu-archive/frontend.git cd frontend 安装依赖 npm install --registry=https://registry.npm.taobao.org 修改API地址配置 vim .env.production ```.env.production文件内容:
``` VUE_APP_API_BASE_URL=http://服务器IP:8080/api VUE_APP_TITLE=教育部门数字档案馆 ```构建项目:
``` npm run build 构建产物在dist目录 ls dist/ ```Nginx配置与部署
安装并配置Nginx:
``` yum install -y nginx 创建Nginx配置文件 cat > /etc/nginx/conf.d/edu-archive.conf << EOF server { listen 80; server_name 服务器IP或域名; location / { root /opt/edu-archive/frontend/dist; index index.html; try_files \$uri \$uri/ /index.html; } location /api/ { proxy_pass http://localhost: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; } location /minio/ { proxy_pass http://localhost:9000; proxy_set_header Host \$host; } } EOF 部署前端文件 mkdir -p /opt/edu-archive/frontend cp -r dist/ /opt/edu-archive/frontend/ 启动Nginx systemctl start nginx systemctl enable nginx ```系统初始化与验证
数据库初始化
访问后端API初始化数据库:
``` 调用初始化接口 curl -X POST http://localhost:8080/api/system/init 创建管理员账号 curl -X POST http://localhost:8080/api/auth/register \ -H "Content-Type: application/json" \ -d '{ "username": "admin", "password": "Admin@123", "realName": "系统管理员", "department": "信息中心" }' ```系统功能验证
按顺序验证以下功能:
- 访问http://服务器IP,确认前端页面正常加载
- 使用admin/Admin@123登录系统
- 测试文件上传功能,上传一个测试文档
- 在搜索框输入文档关键词,验证全文检索功能
- 进入系统管理页面,创建部门、用户等基础数据
监控与维护
配置日志监控:
``` 查看后端日志 tail -f /opt/edu-archive/backend/app.log 查看Nginx访问日志 tail -f /var/log/nginx/access.log 数据库连接检查 psql -U archive_admin -d edu_archive -c "SELECT count() FROM archive_documents;" ```设置定期备份任务:
``` 创建备份脚本 cat > /opt/backup.sh << EOF !/bin/bash BACKUP_DIR="/backup/edu-archive" DATE=\$(date +%Y%m%d_%H%M%S) 备份数据库 pg_dump -U archive_admin edu_archive > \${BACKUP_DIR}/db_backup_\${DATE}.sql 备份配置文件 tar -czf \${BACKUP_DIR}/config_backup_\${DATE}.tar.gz /opt/edu-archive/backend/application-prod.yml 保留最近7天备份 find \${BACKUP_DIR} -type f -mtime +7 -delete EOF chmod +x /opt/backup.sh 添加到crontab,每天凌晨2点执行 echo "0 2 /opt/backup.sh" >> /var/spool/cron/root ```至此,教育部门数字档案馆系统已完成全部部署。所有服务均配置为开机自启动,系统具备完整的文档管理、检索、权限控制功能。