网站建设过程心得体会,wordpress 网址全部变成ip,wordpress视频点播,百度网页版官方本文是应网友 shijie880500 要求折腾的#xff1b; 什么是 InvenTree #xff1f; InvenTree 是一个开源的库存管理系统#xff0c;提供强大的低级别库存控制和零件跟踪。InvenTree 系统的核心是 Python/Django 数据库后端#xff0c;它提供了一个管理界面#xff08;基于… 本文是应网友 shijie880500 要求折腾的 什么是 InvenTree InvenTree 是一个开源的库存管理系统提供强大的低级别库存控制和零件跟踪。InvenTree 系统的核心是 Python/Django 数据库后端它提供了一个管理界面基于 web和一个 REST API用于与外部接口和应用程序交互。强大的插件系统为自定义应用程序和扩展提供支持。 前期准备
在群晖上以 Docker 方式安装。因为涉及到多个容器所以采用了 docker-compose 安装
老苏是按生产环境搭建因为开发模式只能用 localhost 访问所需的文件都来自于官方的 production 目录https://github.com/inventree/InvenTree/tree/master/docker/production 版本选择的是 InvenTree 的最新稳定版本stable 对应的版本为 0.12.8 docker-compose.yml
将下面的内容保存为 docker-compose.yml 文件
version: 3.8# Docker compose recipe for a production-ready InvenTree setup, with the following containers:
# - PostgreSQL as the database backend
# - gunicorn as the InvenTree web server
# - django-q as the InvenTree background worker process
# - nginx as a reverse proxy
# - redis as the cache manager (optional, disabled by default)# ---------------------
# READ BEFORE STARTING!
# ---------------------# -----------------------------
# Setting environment variables
# -----------------------------
# Shared environment variables should be stored in the env.txt file
# Changes made to this file are reflected across all containers!
#
# IMPORTANT NOTE:
# You should not have to change *anything* within this docker-compose.yml file!
# Instead, make any changes in the env.txt file!# ------------------------
# InvenTree Image Versions
# ------------------------
# By default, this docker-compose script targets the STABLE version of InvenTree,
# image: inventree/inventree:stable
#
# To run the LATEST (development) version of InvenTree,
# change the INVENTREE_TAG variable (in the env.txt file) to latest
#
# Alternatively, you could target a specific tagged release version with (for example):
# INVENTREE_TAG0.7.5
#services:# Database service# Use PostgreSQL as the database backendinventree-db:image: postgres:13container_name: inventree-dbexpose:- ${INVENTREE_DB_PORT:-5432}/tcpenvironment:- PGDATA/var/lib/postgresql/data/pgdb- POSTGRES_USER${INVENTREE_DB_USER:?You must provide the INVENTREE_DB_USER variable in the env.txt file}- POSTGRES_PASSWORD${INVENTREE_DB_PASSWORD:?You must provide the INVENTREE_DB_PASSWORD variable in the env.txt file}- POSTGRES_DB${INVENTREE_DB_NAME:?You must provide the INVENTREE_DB_NAME variable in the env.txt file}volumes:# Map data volume such that postgres database is stored externally- inventree_data:/var/lib/postgresql/data/restart: unless-stopped# redis acts as database cache manager# only runs under the redis profile : https://docs.docker.com/compose/profiles/inventree-cache:image: redis:7.0container_name: inventree-cachedepends_on:- inventree-dbprofiles:- redisenv_file:- .envexpose:- ${INVENTREE_CACHE_PORT:-6379}restart: always# InvenTree web server service# Uses gunicorn as the web serverinventree-server:# If you wish to specify a particular InvenTree version, do so hereimage: inventree/inventree:${INVENTREE_TAG:-stable}container_name: inventree-server# Only change this port if you understand the stack.# If you change this you have to change:# - the proxy settings (on two lines)# - only change the exposed port - eg 1338:8000 if you want to expose the server on port 1338expose:- 8000depends_on:- inventree-dbenv_file:- .envvolumes:# Data volume must map to /home/inventree/data- inventree_data:/home/inventree/datarestart: unless-stopped# Background worker process handles long-running or periodic tasksinventree-worker:# If you wish to specify a particular InvenTree version, do so hereimage: inventree/inventree:${INVENTREE_TAG:-stable}container_name: inventree-workercommand: invoke workerdepends_on:- inventree-serverenv_file:- .envvolumes:# Data volume must map to /home/inventree/data- inventree_data:/home/inventree/datarestart: unless-stopped# nginx acts as a reverse proxy# static files are served directly by nginx# media files are served by nginx, although authentication is redirected to inventree-server# web requests are redirected to gunicorn# NOTE: You will need to provide a working nginx.conf file!inventree-proxy:image: nginxcontainer_name: inventree-proxydepends_on:- inventree-serverenv_file:- .envports:# Default web port is 1337 (can be changed in the env.txt file)- ${INVENTREE_WEB_PORT:-1337}:80volumes:# Provide nginx configuration file to the container# Refer to the provided example file as a starting point- ./nginx.prod.conf:/etc/nginx/conf.d/default.conf:ro# nginx proxy needs access to static and media files- inventree_data:/var/wwwrestart: unless-stoppedvolumes:# Persistent data, stored external to the container(s)inventree_data:driver: localdriver_opts:type: noneo: bind# This directory specified where InvenTree data are stored outside the docker containersdevice: ${INVENTREE_EXT_VOLUME:?You must specify the INVENTREE_EXT_VOLUME variable in the env.txt file!}相比官方的 docker-compose.yml老苏做了 2 处修改但都不是必须的你可以直接用官方原版的
nginx 的版本官方用的是 nginx:stable老苏为了少下载一个镜像改为了 nginx也就是 nginx:latest因为机器上已经有了这个不是必须要改的给每个容器增加了 container_name只是为了看着舒服同样也不是必须的
nginx.prod.conf
将下面的内容保存为 r-compose.yml 文件不需要做任何改动
server {# Listen for connection on (internal) port 80# If you are exposing this server to the internet, you should use HTTPS!# In which case, you should also set up a redirect from HTTP to HTTPS, and listen on port 443# See the Nginx documentation for more detailslisten 80;real_ip_header proxy_protocol;location / {proxy_set_header Host $http_host;proxy_set_header X-Forwarded-By $server_addr:$server_port;proxy_set_header X-Forwarded-For $remote_addr;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header X-Real-IP $remote_addr;proxy_set_header CLIENT_IP $remote_addr;proxy_pass_request_headers on;proxy_redirect off;client_max_body_size 100M;proxy_buffering off;proxy_request_buffering off;# Do not touch this unless you have a specific reason - this and the docker-compose need to matchproxy_pass http://inventree-server:8000;}# Redirect any requests for static fileslocation /static/ {alias /var/www/static/;autoindex on;# Caching settingsexpires 30d;add_header Pragma public;add_header Cache-Control public;}# Redirect any requests for media fileslocation /media/ {alias /var/www/media/;# Media files require user authenticationauth_request /auth;# Content header to force downloadadd_header Content-disposition attachment;}# Use the user API endpoint for authlocation /auth {internal;proxy_pass http://inventree-server:8000/auth/;proxy_pass_request_body off;proxy_set_header Content-Length ;proxy_set_header X-Original-URI $request_uri;}}.env
将下面的内容保存为 .env 文件
# InvenTree environment variables for a postgresql production setup# Location of persistent database data (stored external to the docker containers)
# Note: You *must* un-comment this line, and point it to a path on your local machine# e.g. Linux
INVENTREE_EXT_VOLUME/volume1/docker/inventree/data# e.g. Windows (docker desktop)
#INVENTREE_EXT_VOLUMEc:/Users/me/inventree-data# Default web port for the InvenTree server
INVENTREE_WEB_PORT1337# Ensure debug is false for a production setup
INVENTREE_DEBUGFalse
INVENTREE_LOG_LEVELWARNING# InvenTree admin account details
# Un-comment (and complete) these lines to auto-create an admin acount
INVENTREE_ADMIN_USERlaosu
INVENTREE_ADMIN_PASSWORD123456
INVENTREE_ADMIN_EMAILwbsu2003gmail.com# Database configuration options
# Note: The example setup is for a PostgreSQL database
INVENTREE_DB_ENGINEpostgresql
INVENTREE_DB_NAMEinventree
INVENTREE_DB_HOSTinventree-db
INVENTREE_DB_PORT5432# Database credentials - These must be configured before running
# Uncomment the lines below, and change from the default values!
INVENTREE_DB_USERpguser
INVENTREE_DB_PASSWORDpgpassword# Redis cache setup (disabled by default)
# Un-comment the following lines to enable Redis cache
# Note that you will also have to run docker-compose with the --profile redis command
# Refer to settings.py for other cache options
#INVENTREE_CACHE_HOSTinventree-cache
#INVENTREE_CACHE_PORT6379# Options for gunicorn server
INVENTREE_GUNICORN_TIMEOUT90# Enable custom plugins?
INVENTREE_PLUGINS_ENABLEDFalse# Run migrations automatically?
INVENTREE_AUTO_UPDATEFalse# Image tag that should be used
INVENTREE_TAGstableCOMPOSE_PROJECT_NAMEinventree-production参数说明
基本设置 INVENTREE_EXT_VOLUME映射为卷的本地目录需要根据自己的目录进行修改INVENTREE_WEB_PORT访问时的 Web 端口本地不冲突就可以INVENTREE_DEBUG调试模式默认 False 为关闭INVENTREE_LOG_LEVEL日志级别 【建议】前两项需要根据自己的情况就行修改 管理员设置 INVENTREE_ADMIN_USER管理员账号INVENTREE_ADMIN_PASSWORD管理员密码INVENTREE_ADMIN_EMAIL管理员邮件地址 【建议】三项都需要根据自己的情况进行修改这里如果不设置就需要用命令行去单独创建管理员 数据库设置 INVENTREE_DB_ENGINE数据库类型除了 postgresql 外还支持 mysqlINVENTREE_DB_NAME数据库库名INVENTREE_DB_HOST数据库主机INVENTREE_DB_PORT数据库端口INVENTREE_DB_USER数据库用户INVENTREE_DB_PASSWORD数据库密码 【建议】只要修改密码就可以的其他的不建议修改 Redis 设置 INVENTREE_CACHE_HOSTRedis 主机默认本行被注释在数据库初始化之前一定不要取消注释INVENTREE_CACHE_PORTRedis 端口默认本行被注释在数据库初始化之前一定不要取消注释 【强烈建议】不管你后续是否要使用Redis在数据库初始化之前一定不要取消注释否则会报错的切记切记 其他 INVENTREE_GUNICORN_TIMEOUT服务器超时设置INVENTREE_PLUGINS_ENABLED是否启用自定义插件INVENTREE_TAG镜像的 tag 的版本不建议修改COMPOSE_PROJECT_NAME默认就可以 【建议】保持默认就可以了 更多的参数说明请看官方文档https://docs.inventree.org/en/stable/start/config/
以上建议是给和老苏一样的小白用户的高手请忽略
命令行安装
上传文件
文件准备好之后依次执行下面的命令
# 新建文件夹 inventree 和 子目录
mkdir -p /volume1/docker/inventree/data# 进入 inventree 目录
cd /volume1/docker/inventree# 将 docker-compose.yml 、.env 、 nginx.prod.conf 放入当前目录现在的目录 初始化
# 初始化数据库
docker-compose run inventree-server invoke update这行初始化命令执行了以下步骤
确保安装了所需的 python 包创建一个新的空数据库执行所需的架构更新以创建所需的数据库表更新翻译文件将所有必需的静态文件收集到可由 nginx 提供服务的目录中 一定不要先注释 .env 中的 redis 设置否则最后 Running InvenTree database migrations... 时会有错误
redis.exceptions.ConnectionError: Error -2 connecting to inventree-cache:6379. Name or service not known.正常应该是下面这样的 创建管理员
已在 .env 中指定管理员帐户详细信息可以跳过这一步为了安全起见请确保在首次运行后从 .env 文件中删除管理员帐户凭据
# 创建管理员账号
docker-compose run inventree-server invoke superuser启动 Docker 容器
现在可以开始启动了
# 一键启动不带 redis
docker-compose up -d如果需要 Redis 服务 首先修改 .env 中的 redis 设置取消 INVENTREE_CACHE_HOST 和 INVENTREE_CACHE_PORT 前面的注释 如果你取消了 redis 注释但是执行的又是不带 redis 的一键启动也是会存在错误的或导致容器不断重启 然后再执行下面的启动命令
# 一键启动带 redis
docker-compose --profile redis up -d不出意外的话我们在 Docker 管理器中应该看到下面这样 inventree-production_inventree-server_run_2a703d49eef5 是初始化数据库的时候生成的看着不爽的话可以删掉 运行
在浏览器中输入 http://群晖IP:1337 就能看到登录界面 用我们前面设置的管理员账号、密码登录 主界面默认有部分中文显示显然翻译程度还不高 不知道初始化时最一行显示的 InvenTree translation coverage: 27% 是不是指的中文翻译 如果看到下面的提示只要重启 inventree-server 容器即可
Server Restart Required
A configuration option has been changed which requires a server restart. Contact your system administrator for further information其他
一些其他可能会用到的命令
# 一键删除
docker-compose down# 将数据库导出为 JSON
docker-compose run inventree-server invoke export-records -f /volume1/docker/inventree/data/data.json# 删除卷
docker volume rm -f inventree_data参考文档 InvenTree 地址https://github.com/inventree InvenTree 地址https://inventree.org InvenTree - InvenTree Documentation 地址https://docs.inventree.org Docker Production Server - InvenTree Documentation 地址https://docs.inventree.org/en/stable/start/docker_prod/