开源库存管理系统InvenTree的安装

在这里插入图片描述

本文是应网友 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_TAG=0.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_VOLUME=c:/Users/me/inventree-data# Default web port for the InvenTree server
INVENTREE_WEB_PORT=1337# Ensure debug is false for a production setup
INVENTREE_DEBUG=False
INVENTREE_LOG_LEVEL=WARNING# InvenTree admin account details
# Un-comment (and complete) these lines to auto-create an admin acount
INVENTREE_ADMIN_USER=laosu
INVENTREE_ADMIN_PASSWORD=123456
INVENTREE_ADMIN_EMAIL=wbsu2003@gmail.com# Database configuration options
# Note: The example setup is for a PostgreSQL database
INVENTREE_DB_ENGINE=postgresql
INVENTREE_DB_NAME=inventree
INVENTREE_DB_HOST=inventree-db
INVENTREE_DB_PORT=5432# Database credentials - These must be configured before running
# Uncomment the lines below, and change from the default values!
INVENTREE_DB_USER=pguser
INVENTREE_DB_PASSWORD=pgpassword# 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_HOST=inventree-cache
#INVENTREE_CACHE_PORT=6379# Options for gunicorn server
INVENTREE_GUNICORN_TIMEOUT=90# Enable custom plugins?
INVENTREE_PLUGINS_ENABLED=False# Run migrations automatically?
INVENTREE_AUTO_UPDATE=False# Image tag that should be used
INVENTREE_TAG=stableCOMPOSE_PROJECT_NAME=inventree-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 外,还支持 mysql
    • INVENTREE_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.

在这里插入图片描述

正常应该是下面这样的

在这里插入图片描述

创建管理员

  1. 已在 .env 中指定管理员帐户详细信息,可以跳过这一步;
  2. 为了安全起见,请确保在首次运行后从 .env 文件中删除管理员帐户凭据;
# 创建管理员账号
docker-compose run inventree-server invoke superuser

启动 Docker 容器

现在可以开始启动了

# 一键启动(不带 redis)
docker-compose up -d

如果需要 Redis 服务 ,首先修改 .env 中的 redis 设置,取消 INVENTREE_CACHE_HOSTINVENTREE_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/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/154613.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

将字符串中符合规则的元素替换为指定元素 re.sub()

【小白从小学Python、C、Java】 【计算机等级考试500强双证书】 【Python-数据分析】 将字符串中符合规则的元素 替换为指定元素 re.sub() 选择题 请问re.sub(r[0-9],*,s)的结果是: import re s "hello123" print("【显示】s ",s) print(&quo…

前端包管理工具详解

一、npm包管理工具 1.代码共享方案 我们已经学习了在JavaScript中可以通过模块化的方式将代码划分成一个个小的结构: 在以后的开发中我们就可以通过模块化的方式来封装自己的代码,并且封装成一个工具;这个工具我们可以让同事通过导入的方式…

软考系统架构师知识点集锦九:数据库系统

一、考情分析 二、考点精讲 2.1数据库概述 2.1.1数据库模式 (1)三级模式:外模式对应视图,模式(也称为概念模式)对应数据库表,内模式对应物理文件。(2)两层映像:外模式-模式映像,模式-内模式映像;两层映像可以保证数据库中的数据具有较高的…

如何在Android设备上检查应用程序使用情况,包括使用时间

你可能不知道自己花了多少时间在手机上。很可能你一天中有一半的时间都在盯着手机屏幕。如果你怀疑这一事实,你会很快核实的。在这篇文章中,我们将向你介绍如何在Android设备上检查应用程序的使用情况。 如何在Android上检查应用程序电池使用情况 你使用时间最长的应用程序…

delphi 11.3 FastReport 多设备跨平台 打印之解决方法

以下能WINDOWS10 DELPHI 11.3 FastReport6.0上顺利通过 FastReport6.2对Multi-Device Application应用的支持不够友好,如下图;在palette FastReport6.0才出现几个制件。 非Multi-Device Application应用时是一大堆; 非Multi-Device Appl…

C++笔记-RTTR编译安装简单使用

这里以Linux为例,我使用的机器的gcc版本是4.9.2 使用的RTTR的版本是0.9.5 编译&安装 首先在官网将rttr的0.9.5版本下载下来。 Home |RTTR 按照官方的安装流程: 但这里可能会出现一个问题: 按照解答,切换成root用户&#x…

[java/力扣110]平衡二叉树——优化前后的两种方法

分析 根据平衡二叉树的定义,只需要满足:1、根节点两个子树的高度差不超过1;2、左右子树都为平衡二叉树 代码 public class BalancedBinaryTree {public class TreeNode{int val;TreeNode left;TreeNode right;TreeNode(){}TreeNode(int va…

8+双疾病+WGCNA+多机器学习筛选疾病的共同靶点并验证表达

今天给同学们分享一篇双疾病WGCNA多机器学习的生信文章“Shared diagnostic genes and potential mechanism between PCOS and recurrent implantation failure revealed by integrated transcriptomic analysis and machine learning”,这篇文章于2023年5月16日发表…

生产级 React 框架介绍

文章目录 生产级 React 框架生产级 React 框架Next.jsRemixGatsbyExpo 如何选择生产级 React 框架 生产级 React 框架 React 是一个流行的 JavaScript 框架,用于构建用户界面。React 框架可以帮助你快速构建高质量的 React 应用,但并不是所有的 React 框…

MySQL(2):环境搭建

1.软件下载 软装去官网下载(社区版):https://downloads.mysql.com/archives/installer/(历史版本可选) 选择下面的,一步到位 2.软件安装 双击 .msi 文件 选完 Custom 自定义后点 next 按 1&#xff0c…

新恶意软件使用 MSIX 软件包来感染 Windows

人们发现,一种新的网络攻击活动正在使用 MSIX(一种 Windows 应用程序打包格式)来感染 Windows PC,并通过将隐秘的恶意软件加载程序放入受害者的 PC 中来逃避检测。 Elastic Security Labs 的研究人员发现,开发人员通常…

Shadow DOM API 的 ShadowRoot 接口支持挂载的 shadow DOM 元素仅有18个:

<article, aside, blockquote, body, div, footer, h1-h6, header, main, nav, p, section, span> 浏览器兼容性 Browser compatibility