根据使用规模选择对应配置,避免资源浪费或性能不足:
所有软件均使用固定版本,避免兼容性问题:CentOS7.9操作系统、Python3.8.10、MySQL8.0、Nginx1.20、Redis6.2
首先执行以下命令关闭防火墙和SELinux,避免端口访问拦截:
``` systemctl stop firewalld systemctl disable firewalld setenforce 0 sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config ```安装Python3.8.10,执行以下命令:
``` yum install -y wget gcc make zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel wget https://www.python.org/ftp/python/3.8.10/Python-3.8.10.tgz tar zxvf Python-3.8.10.tgz cd Python-3.8.10 ./configure --prefix=/usr/local/python3.8 --enable-shared make && make install ln -s /usr/local/python3.8/bin/python3 /usr/bin/python3 ln -s /usr/local/python3.8/bin/pip3 /usr/bin/pip3 echo "/usr/local/python3.8/lib" >> /etc/ld.so.conf ldconfig ```安装MySQL8.0并初始化数据库:
``` rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm yum install -y mysql-community-server systemctl start mysqld systemctl enable mysqld 获取初始密码 grep 'temporary password' /var/log/mysqld.log 登录MySQL(替换为获取到的初始密码) mysql -uroot -p'初始密码' 执行以下SQL语句创建数据库和授权用户(替换为自定义密码) ALTER USER 'root'@'localhost' IDENTIFIED BY '自定义Root密码'; CREATE DATABASE archive_system DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'archive_user'@'127.0.0.1' IDENTIFIED BY '自定义业务库密码'; GRANT ALL ON archive_system. TO 'archive_user'@'127.0.0.1'; FLUSH PRIVILEGES; exit; ```安装Redis和Nginx:
``` yum install -y redis nginx systemctl start redis nginx systemctl enable redis nginx ```拉取开源稳定版源码并安装依赖:
``` git clone https://gitee.com/opensource_archive/archive-digital-system.git /opt/archive_system cd /opt/archive_system pip3 install -r requirements.txt ```修改配置文件/opt/archive_system/archive_system/settings.py,替换为以下内容(对应修改数据库密码部分):
``` import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = 'django-insecure-=t!s1u90%&8z3@9%xq5z3@9%xq5z3@9%xq5z3' DEBUG = False ALLOWED_HOSTS = [''] INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'archive', ] DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'archive_system', 'USER': 'archive_user', 'PASSWORD': '你设置的业务库密码', 'HOST': '127.0.0.1', 'PORT': '3306', } } CACHES = { 'default': { 'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': 'redis://127.0.0.1:6379/0', 'OPTIONS': { 'CLIENT_CLASS': 'django_redis.client.DefaultClient', } } } CACHE_TTL = 3600 MEDIA_ROOT = '/data/archive_files' MEDIA_URL = '/media/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') ```
创建档案存储目录并授权:
``` mkdir -p /data/archive_files chmod 755 /data/archive_files ```执行数据库迁移和创建超级管理员账号:
``` python3 manage.py makemigrations python3 manage.py migrate 按提示输入管理员账号、邮箱、密码 python3 manage.py createsuperuser ```配置系统服务开机自启,新建/etc/systemd/system/archive.service文件,内容如下:
``` [Unit] Description=Archive Digital System After=network.target mysql.service redis.service [Service] Type=simple User=root WorkingDirectory=/opt/archive_system ExecStart=/usr/bin/python3 manage.py runserver 0.0.0.0:8000 Restart=always RestartSec=5 [Install] WantedBy=multi-user.target ```启动服务:
``` systemctl daemon-reload systemctl start archive systemctl enable archive ```新建/etc/nginx/conf.d/archive.conf文件,内容如下(替换为你的服务器IP或域名):
``` server { listen 80; server_name 你的服务器IP或域名; client_max_body_size 100M; location / { root /opt/archive_system/dist; index index.html index.htm; try_files $uri $uri/ /index.html; } location /api/ { proxy_pass http://127.0.0.1:8000/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location /media/ { root /data/archive_files; rewrite ^/media/(.)$ /$1 break; } } ```验证配置并重启Nginx:
``` nginx -t systemctl restart nginx ```在浏览器输入服务器IP或域名,使用之前创建的超级管理员账号登录,确认页面正常加载无报错。
进入【系统设置】-【用户管理】页面,按岗位分配权限:档案录入员仅分配录入权限,档案管理员分配查询、借阅审批权限,普通用户仅分配本人权限范围内的查询权限,避免越权操作。