本指南旨在提供一套基于国家档案局最新规范(《机关档案管理规定》等)的、可直接部署的档案制度数字化建设方案。它适用于希望从零建立合规电子档案体系,或将传统纸质档案系统升级为数字系统的机关、企事业单位技术负责人与档案管理员。方案聚焦于利用现有成熟开源技术栈,以最低成本实现档案收集、整理、保管、利用的全流程电子化与标准化。
以下工具为构建系统的最小必要集合,均选择开源、稳定版本。
在CentOS 7.9或Ubuntu 20.04 LTS服务器上执行。首先安装基础依赖:
sudo yum install -y epel-release CentOS
sudo yum install -y python3-pip git nginx java-11-openjdk
或对于Ubuntu:
sudo apt update && sudo apt install -y python3-pip git nginx openjdk-11-jdk
1. 数据库(PostgreSQL 13):
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql13-server
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl start postgresql-13
sudo systemctl enable postgresql-13
创建数据库及用户:
sudo -u postgres psql -c "CREATE USER dauser WITH PASSWORD 'YourStrongPassword123!';"
sudo -u postgres psql -c "CREATE DATABASE digital_archive OWNER dauser;"
sudo -u postgres psql -d digital_archive -c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
2. 全文检索与档案检索引擎(Elasticsearch 7.17.3):
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
cat > /etc/yum.repos.d/elasticsearch.repo << EOF
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
sudo yum install -y elasticsearch-7.17.3
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch
验证安装:执行 curl -X GET "localhost:9200/",应返回包含版本号的JSON信息。
3. 对象存储服务(MinIO):用于存储电子档案原文。
wget https://dl.min.io/server/minio/release/linux-amd64/minio
chmod +x minio
sudo mv minio /usr/local/bin/
sudo useradd -r minio-user -s /sbin/nologin
sudo mkdir -p /data/minio
sudo chown -R minio-user:minio-user /data/minio
创建Systemd服务文件 /etc/systemd/system/minio.service:
[Unit]
Description=MinIO
After=network.target
[Service]
User=minio-user
Group=minio-user
ExecStart=/usr/local/bin/minio server /data/minio --console-address ":9001"
Restart=always
[Install]
WantedBy=multi-user.target
启动服务:
sudo systemctl daemon-reload
sudo systemctl enable minio
sudo systemctl start minio
通过浏览器访问 http://服务器IP:9001,使用默认账号密码(minioadmin/minioadmin)登录,立即修改密码,并创建一个名为“digital-archive”的存储桶(Bucket)。
我们将使用一个轻量级Django应用作为核心业务系统。
克隆示例应用代码并安装Python依赖:

git clone https://github.com/example/digital-archive-core.git 此为示例仓库,实际需替换
cd digital-archive-core
pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
编辑项目配置文件 digital_archive/settings/production.py,关键部分如下:
数据库配置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'digital_archive',
'USER': 'dauser',
'PASSWORD': 'YourStrongPassword123!',
'HOST': 'localhost',
'PORT': '5432',
}
}
Elasticsearch配置
ELASTICSEARCH_DSL = {
'default': {
'hosts': 'localhost:9200'
},
}
MinIO对象存储配置
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = 'Your-MinIO-Access-Key' 在MinIO控制台创建
AWS_SECRET_ACCESS_KEY = 'Your-MinIO-Secret-Key'
AWS_STORAGE_BUCKET_NAME = 'digital-archive'
AWS_S3_ENDPOINT_URL = 'http://localhost:9000' MinIO API端口
AWS_S3_USE_SSL = False
执行以下命令创建数据表并初始化预置数据(如档案门类、保管期限表等):
python3 manage.py migrate
python3 manage.py loaddata initial_data.json 加载预置的分类数据
python3 manage.py createsuperuser 创建管理员账号
创建Gunicorn服务文件 /etc/systemd/system/gunicorn_digital_archive.service:
[Unit]
Description=Gunicorn for Digital Archive
After=network.target
[Service]
User=your_username
Group=nginx
WorkingDirectory=/path/to/digital-archive-core
ExecStart=/usr/local/bin/gunicorn --workers 3 --bind unix:/path/to/digital-archive-core/digital_archive.sock digital_archive.wsgi:application
[Install]
WantedBy=multi-user.target
配置Nginx站点 /etc/nginx/conf.d/digital_archive.conf:
server {
listen 80;
server_name your_domain_or_ip;
location / {
proxy_pass http://unix:/path/to/digital-archive-core/digital_archive.sock;
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 /static/ {
alias /path/to/digital-archive-core/static/;
}
location /media/ {
alias /path/to/digital-archive-core/media/;
}
}
收集静态文件并重启服务:
python3 manage.py collectstatic --noinput
sudo systemctl start gunicorn_digital_archive
sudo systemctl enable gunicorn_digital_archive
sudo nginx -s reload
登录系统后台,进入“档案门类管理”。严格按《机关档案管理规定》设置一级类目:文书档案(WS)、科技档案(KJ)、人事档案(RS)、会计档案(KJ)、专业档案(ZY)、照片档案(ZP)、录音录像档案(LY)、业务数据档案(SJ)、公务电子邮件档案(YJ)、网页信息档案(WY)、社交媒体档案(MT)。为每个类目配置明确的归档范围和保管期限表。
进入“元数据管理”,为每个档案门类添加必填元数据字段。核心字段必须包括:档号、题名、责任者、日期、页数、保管期限、密级、归档部门、归档人。系统已预置DA/T 46-2009《文书类电子文件元数据方案》核心元数据,可直接引用或调整。
普通用户可通过前台检索页面,进行全文检索或高级组合检索(按档号、题名、责任者、日期等)。授权用户可在线预览档案(系统集成PDF.js),并记录完整的利用日志,包括查阅人、时间、档案ID、操作类型。
系统在以下环节自动执行检测:
检测脚本 scripts/integrity_check.py 可加入定时任务(Crontab),每周执行一次:
0 2 1 python3 /path/to/digital-archive-core/scripts/integrity_check.py >> /var/log/da_integrity.log
每日凌晨3点执行全量备份,编写备份脚本 /usr/local/bin/backup_digital_archive.sh:
!/bin/bash
BACKUP_DIR="/backup/digital_archive/$(date +%Y%m%d)"
mkdir -p $BACKUP_DIR
备份PostgreSQL数据库
pg_dump -U dauser -h localhost digital_archive > $BACKUP_DIR/db_backup.sql
备份Elasticsearch索引(使用快照功能,需提前在ES中配置快照仓库)
curl -X PUT "localhost:9200/_snapshot/backup_repository/snapshot_$(date +%Y%m%d)?wait_for_completion=true"
使用MinIO Client同步存储桶内容
/usr/local/bin/mc mirror --overwrite local/digital-archive $BACKUP_DIR/minio_data/
保留最近30天备份
find /backup/digital_archive/ -type d -mtime +30 -exec rm -rf {} \;
添加定时任务:crontab -e 中加入 0 3 /usr/local/bin/backup_digital_archive.sh。
配置Elasticsearch + Logstash + Kibana(ELK)栈集中收集Nginx、Gunicorn、Django应用日志,监控系统访问异常与性能瓶颈。确保所有操作日志至少保存30年,与档案保管期限对齐。
每月检查:
df -h)。curl -X GET "localhost:9200/_cluster/health?pretty")。
档案软件审计日志不完整?别慌,老司机带你填坑!