开源库存管理系统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 backend
    inventree-db:
        image: postgres:13
        container_name: inventree-db
        expose:
            - ${INVENTREE_DB_PORT:-5432}/tcp
        environment:
            - 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.0
        container_name: inventree-cache
        depends_on:
            - inventree-db
        profiles:
            - redis
        env_file:
            - .env
        expose:
            - ${INVENTREE_CACHE_PORT:-6379}
        restart: always

    # InvenTree web server service
    # Uses gunicorn as the web server
    inventree-server:
        # If you wish to specify a particular InvenTree version, do so here
        image: 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 1338
        expose:
            - 8000
        depends_on:
            - inventree-db
        env_file:
            - .env
        volumes:
            # Data volume must map to /home/inventree/data
            - inventree_data:/home/inventree/data
        restart: unless-stopped

    # Background worker process handles long-running or periodic tasks
    inventree-worker:
        # If you wish to specify a particular InvenTree version, do so here
        image: inventree/inventree:${INVENTREE_TAG:-stable}
        container_name: inventree-worker
        command: invoke worker
        depends_on:
            - inventree-server
        env_file:
            - .env
        volumes:
            # Data volume must map to /home/inventree/data
            - inventree_data:/home/inventree/data
        restart: 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: nginx
        container_name: inventree-proxy
        depends_on:
            - inventree-server
        env_file:
            - .env
        ports:
            # Default web port is 1337 (can be changed in the env.txt file)
            - ${INVENTREE_WEB_PORT:-1337}:80
        volumes:
            # 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/www
        restart: unless-stopped

volumes:
    # Persistent data, stored external to the container(s)
    inventree_data:
        driver: local
        driver_opts:
            type: none
            o: bind
            # This directory specified where InvenTree data are stored "outside" the docker containers
            device: ${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 details
    listen 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 match
        proxy_pass http://inventree-server:8000;
    }

    # Redirect any requests for static files
    location /static/ {
        alias /var/www/static/;
        autoindex on;

        # Caching settings
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public";
    }

    # Redirect any requests for media files
    location /media/ {
        alias /var/www/media/;

        # Media files require user authentication
        auth_request /auth;

        # Content header to force download
        add_header Content-disposition "attachment";
    }

    # Use the 'user' API endpoint for auth
    location /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=stable

COMPOSE_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.mfbz.cn/a/110264.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【腾讯云 TDSQL-C Serverless 产品体验】TDSQL-C MySQL Serverless最佳实践

一、引言: 随着云计算技术的不断发展,越来越多的企业开始选择将自己的数据库部署在云上,以更好了的支持企业数字化转型以及业务创新,在这个过程中,很多客户会遇到这样一个问题,业务会存在高峰期和低谷期&a…

计讯物联外贸公司--佰沃恩应邀出席第三届“嘉庚论坛”—科技创新推动经济高质量发展分论坛

10月22日,以“数智创新能动未来”为主题的第三届“嘉庚论坛”—科技创新推动经济高质量发展分论坛于集美海景皇冠假日酒店正式启幕。此论坛聚焦集美区战略前沿产业,汇聚来自全国各地优秀的企业家、高校及科研院所专家学者,并邀请相关领域的亲…

对象补充-原型和函数原型-创建对象

defineProperties可以定义多个属性描述符 var obj {// 私有属性(js里面是没有严格意义的私有属性)_age: 18,_eat: function() {} }Object.defineProperties(obj, {name: {configurable: true,enumerable: true,writable: true,value: "why"}…

Redis快速上手篇七(集群-六台虚拟机)

Redis集群 主从复制的场景无法吗满足主机单点故障时需要引入集群配置 一般数据库要处理的读请求远大于写请求 ,针对这种情况,我们优化数据库可以采用读写分离的策略。我们可以部 署一台主服务器主要用来处理写请求,部署多台从服务器 &#…

C#学习相关系列之多线程---ConfigureAwait的用法

一、ConfigureAwait的作用 ConfigureAwait方法是Task类中的一个实例方法,它用于配置任务的运行上下文。运行上下文指的是任务在执行期间所处的环境,包括线程、同步上下文等。ConfigureAwait方法接受一个布尔值参数,用于决定是否捕获上下文。当…

导弹拦截(最大不上升 或 不下降子序列,dp)

算法分析: 1.求最长子序列 1.每次输入时,计算每个元素对应的序列的长度 1.向前遍历找大于当前元素的数 2.若之前元素对应长度1 大于当前长度,更新当前长度 2.若当前元素对应长度 大于最大长度,更新最大长度 2.dilworth定理 故需…

HarmonyOS开发:NodeJs脚本实现组件化动态切换

前言 上篇文章,我们使用NodeJs脚本完成了HarmonyOS项目的组件化运行,但是由于脚本是基于4.0.0.400版本的DevEco Studio开发的,可能在配置文件的修改上有些许差距,那么遇到这种情况怎么办,一种是再写一套针对性的脚本文…

系列四十二、Spring的事务传播行为案例演示(二)#REQUIRED

一、演示Spring的默认传播行为(REQUIRED) 1.1、运行之前表中的数据 1.2、StockServiceImpl /*** Author : 一叶浮萍归大海* Date: 2023/10/30 15:43* Description:*/ Service(value "stockServiceREQUIRED") public class StockServiceImpl…

MSQL系列(十) Mysql实战-Join驱动表和被驱动表如何区分

Mysql实战-Join驱动表和被驱动表如何区分 前面我们讲解了Mysql的查询连接Join的算法原理, 我发现大家都知道小表驱动大表,要让小表作为驱动表, 现在有2个问题 查询多表, 到底哪个是驱动表?哪个是被驱动表, 如何区分?索引如何优化,到底是加在驱动表上,还是被驱动表上? &…

二维数组如何更快地遍历

二维数组如何更快地遍历 有时候,我们会发现,自己的代码和别人的代码几乎一模一样,但运行时间差了很多,别人是 AC \text{AC} AC,你是 TLE \text{TLE} TLE,这是为什么呢? 一个可能的原因是数组的…

2023高德地图poi资源下载

全国8千万地图poi地图数据:含名称、地址、电话、省份、城市、区县、经纬度、电话等信息

第五章 I/O管理 六、I/O核心子系统

目录 一、核心子系统 1、I/O调度 2、设备保护 二、假脱机技术 1、脱机: 2、假脱机(SPOOLing技术): 3、应用: 1.独占式设备: 2.共享设备: 4、共享打印机原理分析 三、总结 一、核心子系…

metaRTC集成flutter ui demo编译指南

概要 Flutter是由Google开发的开源UI工具包,用于构建跨平台应用程序,支持linux/windows/mac/android/ios等操作系统。 metaRTC新增flutter demo,支持linux/windows/mac/android/ios操作系统,此demo在ubuntu桌面环境下测试成功。…

Jenkins项目部署

使用jenkins部署项目 简易版使用jenkins部署项目 将war包部署到tomcat中 将已有的war包部署到tomcat中(jenkins与tomcat在同一台主机) 点击Jenkins主页的新建任务 输入任务名称 选择构建一个自由风格的软件项目后点击确定 在构建内添加构建步骤,选择执行shell 输入…

时间序列预测大模型-TimeGPT

时间序列预测领域正在经历一个非常激动人心的时期。仅在过去的三年里,我们就看到了许多重要的贡献,例如N-BEATS、N-HiTS、PatchTST和TimesNet。 与此同时,大型语言模型 (LLM)最近在 ChatGPT 等应用程序中广受欢迎,因为它们无需进…

自动化项目实战 [个人博客系统]

自动化博客项目 用户注册登录验证效验个人博客列表页博客数量不为 0 博客系统主页写博客 我的博客列表页效验 刚发布的博客的标题和时间查看 文章详情页删除文章效验第一篇博客 不是 "自动化测试" 注销退出到登录页面,用户名密码为空 用户注册 Order(1)Parameterized…

Spring Cloud之API网关(Zuul)

目录 Zuul 简介 功能 工作流程 搭建 1.引入依赖 2.添加注解 3.路由转发 4.测试 实现原理 EnableZuulProxy注解 ZuulServlet FilterProcessor Zuul内置过滤器 常用配置 Zuul 简介 zuul是SpringCloud子项目的核心组件之一,可以作为微服务架构中的API网…

【C】C语言文件操作

1.为什么使用文件 我们前面学习结构体时,写通讯录的程序,当通讯录运行起来的时候,可以给通讯录中增加、删除数据,此时数据是存放在内存中,当程序退出的时候,通讯录中的数据自然就不存在了,等下…

超全整理,Jmeter性能测试-脚本error报错排查/分布式压测(详全)

目录:导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结(尾部小惊喜) 前言 性能脚本error报错…

域名系统 DNS

DNS 概述 域名系统 DNS(Domain Name System)是因特网使用的命名系统,用来把便于人们使用的机器名字转换成为 IP 地址。域名系统其实就是名字系统。为什么不叫“名字”而叫“域名”呢?这是因为在这种因特网的命名系统中使用了许多的“域(domain)”&#x…
最新文章