国土资源不动产档案管理系统本地搭建实操落地详细步骤
一、环境准备
必须使用CentOS7.9系统(2核4G配置,最小20G磁盘空间),所有命令均以root用户身份执行:
``` yum install -y epel-release yum install -y postgresql12-server postgresql12-contrib postgis3 git python38 nginx systemctl enable postgresql --now systemctl enable nginx --now ```二、PostgreSQL+PostGIS数据库配置
必须切换为postgres用户执行所有数据库相关命令,切换命令:
``` su - postgres ```执行以下命令创建数据库用户、数据库并启用空间扩展:
``` createuser -s arch_admin createdb -O arch_admin estate_archive psql -d estate_archive -c "CREATE EXTENSION postgis;" psql -d estate_archive -c "CREATE EXTENSION postgis_topology;" psql -c "ALTER USER arch_admin PASSWORD 'Arch@2024';" ```修改认证配置允许密码登录:
``` vi /var/lib/pgsql/12/data/pg_hba.conf ```找到「local all all peer」行,替换为「local all all md5」,保存后退出,重启数据库:
``` systemctl restart postgresql ```三、系统代码部署与依赖安装
执行exit切回root用户,克隆开源不动产档案系统代码:
创建Python虚拟环境并安装依赖:
``` python3.8 -m venv venv source venv/bin/activate pip install --upgrade pip pip install -r requirements.txt ```四、Django核心配置与数据库迁移
编辑项目配置文件,修改数据库连接信息:
``` vi estate_archive/settings.py ```
找到DATABASES节点,替换为以下完整内容:
保存后执行数据库迁移与超级用户创建:
``` python manage.py makemigrations python manage.py migrate python manage.py createsuperuser ```按提示输入用户名(如admin)、邮箱(如admin@test.com)、密码(如Arch@2024),完成超级用户创建。
五、Nginx反向代理与生产启动
创建Nginx站点配置文件:
``` vi /etc/nginx/conf.d/estate_archive.conf ```写入以下完整配置:
```nginx server { listen 80; server_name 你的服务器IP; client_max_body_size 100M; location /static/ { root /opt/estate_archive; expires 30d; } location /media/ { root /opt/estate_archive; } location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ```必须执行nginx -t检查配置语法正确性,正确则重启Nginx:
``` nginx -t systemctl restart nginx ```在虚拟环境下启动生产服务Gunicorn:
``` gunicorn --workers=2 --bind=127.0.0.1:8000 estate_archive.wsgi:application & ```六、功能验证
打开浏览器,访问你填写的服务器IP(如http://192.168.1.100),输入超级用户账号密码登录。登录后可完成以下核心操作:
- 在【档案管理】模块录入不动产基础档案,支持上传PDF、图片等附件
- 执行空间数据导入(需准备shapefile格式的不动产地块数据): ``` python manage.py import_shapefile /opt/test_shapefiles/estate_parcels.shp -t parcel ```
- 在【空间数据管理】模块查看导入的不动产地块图层,验证GIS功能正常