本文是應(yīng)網(wǎng)友
shijie880500
要求折騰的;
什么是 InvenTree ?
InvenTree
是一個(gè)開(kāi)源的庫(kù)存管理系統(tǒng),提供強(qiáng)大的低級(jí)別庫(kù)存控制和零件跟蹤。InvenTree
系統(tǒng)的核心是Python/Django
數(shù)據(jù)庫(kù)后端,它提供了一個(gè)管理界面(基于web
)和一個(gè)REST API
,用于與外部接口和應(yīng)用程序交互。強(qiáng)大的插件系統(tǒng)為自定義應(yīng)用程序和擴(kuò)展提供支持。
前期準(zhǔn)備
在群暉上以 Docker 方式安裝。因?yàn)樯婕暗蕉鄠€(gè)容器,所以采用了 docker-compose
安裝
老蘇是按生產(chǎn)環(huán)境搭建,因?yàn)殚_(kāi)發(fā)模式只能用 localhost
訪問(wèn),所需的文件都來(lái)自于官方的 production
目錄:https://github.com/inventree/InvenTree/tree/master/docker/production
版本選擇的是
InvenTree
的最新穩(wěn)定版本stable
,對(duì)應(yīng)的版本為0.12.8
docker-compose.yml
將下面的內(nèi)容保存為 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
,老蘇為了少下載一個(gè)鏡像,改為了nginx
,也就是nginx:latest
,因?yàn)闄C(jī)器上已經(jīng)有了,這個(gè)不是必須要改的; - 給每個(gè)容器增加了
container_name
,只是為了看著舒服,同樣也不是必須的;
nginx.prod.conf
將下面的內(nèi)容保存為 r-compose.yml
文件,不需要做任何改動(dòng)
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
將下面的內(nèi)容保存為 .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
參數(shù)說(shuō)明:
- 基本設(shè)置
-
INVENTREE_EXT_VOLUME
:映射為卷的本地目錄,需要根據(jù)自己的目錄進(jìn)行修改; -
INVENTREE_WEB_PORT
:訪問(wèn)時(shí)的Web
端口,本地不沖突就可以; -
INVENTREE_DEBUG
:調(diào)試模式,默認(rèn)False
為關(guān)閉; -
INVENTREE_LOG_LEVEL
:日志級(jí)別;
-
【建議】:前兩項(xiàng)需要根據(jù)自己的情況就行修改;
- 管理員設(shè)置
-
INVENTREE_ADMIN_USER
:管理員賬號(hào); -
INVENTREE_ADMIN_PASSWORD
:管理員密碼; -
INVENTREE_ADMIN_EMAIL
:管理員郵件地址;
-
【建議】:三項(xiàng)都需要根據(jù)自己的情況進(jìn)行修改;這里如果不設(shè)置,就需要用命令行去單獨(dú)創(chuàng)建管理員;
- 數(shù)據(jù)庫(kù)設(shè)置
-
INVENTREE_DB_ENGINE
:數(shù)據(jù)庫(kù)類(lèi)型,除了postgresql
外,還支持mysql
-
INVENTREE_DB_NAME
:數(shù)據(jù)庫(kù)庫(kù)名; -
INVENTREE_DB_HOST
:數(shù)據(jù)庫(kù)主機(jī); -
INVENTREE_DB_PORT
:數(shù)據(jù)庫(kù)端口; -
INVENTREE_DB_USER
:數(shù)據(jù)庫(kù)用戶(hù); -
INVENTREE_DB_PASSWORD
:數(shù)據(jù)庫(kù)密碼;
-
【建議】:只要修改密碼就可以的,其他的不建議修改;
-
Redis
設(shè)置-
INVENTREE_CACHE_HOST
:Redis
主機(jī),默認(rèn)本行被注釋?zhuān)跀?shù)據(jù)庫(kù)初始化之前,一定不要取消注釋?zhuān)?/strong> -
INVENTREE_CACHE_PORT
:Redis
端口,默認(rèn)本行被注釋?zhuān)跀?shù)據(jù)庫(kù)初始化之前,一定不要取消注釋?zhuān)?/strong>
-
【強(qiáng)烈建議】:不管你后續(xù)是否要使用
Redis
,在數(shù)據(jù)庫(kù)初始化之前,一定不要取消注釋?zhuān)駝t會(huì)報(bào)錯(cuò)的,切記!切記!
- 其他
-
INVENTREE_GUNICORN_TIMEOUT
:服務(wù)器超時(shí)設(shè)置; -
INVENTREE_PLUGINS_ENABLED
:是否啟用自定義插件; -
INVENTREE_TAG
:鏡像的tag
的版本,不建議修改; -
COMPOSE_PROJECT_NAME
:默認(rèn)就可以;
-
【建議】:保持默認(rèn)就可以了;
更多的參數(shù)說(shuō)明,請(qǐng)看官方文檔:https://docs.inventree.org/en/stable/start/config/
以上建議是給和老蘇一樣的小白用戶(hù)的,高手請(qǐng)忽略
命令行安裝
上傳文件
文件準(zhǔn)備好之后,依次執(zhí)行下面的命令
# 新建文件夾 inventree 和 子目錄
mkdir -p /volume1/docker/inventree/data
# 進(jìn)入 inventree 目錄
cd /volume1/docker/inventree
# 將 docker-compose.yml 、.env 、 nginx.prod.conf 放入當(dāng)前目錄
現(xiàn)在的目錄
初始化
# 初始化數(shù)據(jù)庫(kù)
docker-compose run inventree-server invoke update
這行初始化命令執(zhí)行了以下步驟:
- 確保安裝了所需的
python
包 - 創(chuàng)建一個(gè)新的(空)數(shù)據(jù)庫(kù)
- 執(zhí)行所需的架構(gòu)更新以創(chuàng)建所需的數(shù)據(jù)庫(kù)表
- 更新翻譯文件
- 將所有必需的靜態(tài)文件收集到可由
nginx
提供服務(wù)的目錄中
一定不要先注釋 .env
中的 redis
設(shè)置,否則最后 Running InvenTree database migrations...
時(shí)會(huì)有錯(cuò)誤
redis.exceptions.ConnectionError: Error -2 connecting to inventree-cache:6379. Name or service not known.
正常應(yīng)該是下面這樣的
創(chuàng)建管理員
- 已在
.env
中指定管理員帳戶(hù)詳細(xì)信息,可以跳過(guò)這一步; - 為了安全起見(jiàn),請(qǐng)確保在首次運(yùn)行后從
.env
文件中刪除管理員帳戶(hù)憑據(jù);
# 創(chuàng)建管理員賬號(hào)
docker-compose run inventree-server invoke superuser
啟動(dòng) Docker 容器
現(xiàn)在可以開(kāi)始啟動(dòng)了
# 一鍵啟動(dòng)(不帶 redis)
docker-compose up -d
如果需要 Redis
服務(wù) ,首先修改 .env
中的 redis
設(shè)置,取消 INVENTREE_CACHE_HOST
和 INVENTREE_CACHE_PORT
前面的注釋
如果你取消了
redis
注釋?zhuān)菆?zhí)行的又是不帶redis
的一鍵啟動(dòng),也是會(huì)存在錯(cuò)誤的,或?qū)е氯萜鞑粩嘀貑ⅲ?/p>
然后再執(zhí)行下面的啟動(dòng)命令
# 一鍵啟動(dòng)(帶 redis)
docker-compose --profile redis up -d
不出意外的話(huà),我們?cè)?Docker
管理器中應(yīng)該看到下面這樣
inventree-production_inventree-server_run_2a703d49eef5
是初始化數(shù)據(jù)庫(kù)的時(shí)候生成的,看著不爽的話(huà),可以刪掉
運(yùn)行
在瀏覽器中輸入 http://群暉IP:1337
就能看到登錄界面
用我們前面設(shè)置的管理員賬號(hào)、密碼登錄
主界面默認(rèn)有部分中文顯示,顯然翻譯程度還不高
不知道初始化時(shí)最一行顯示的
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
其他
一些其他可能會(huì)用到的命令
# 一鍵刪除
docker-compose down
# 將數(shù)據(jù)庫(kù)導(dǎo)出為 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文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-736964.html
Docker Production Server - InvenTree Documentation
地址:https://docs.inventree.org/en/stable/start/docker_prod/文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-736964.html
到了這里,關(guān)于開(kāi)源庫(kù)存管理系統(tǒng)InvenTree的安裝的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!