Docker部署snipe-it资产管理系统
🎉
Snipe-IT是一款开源的资产管理系统,用于IT运营中的资产管理。了解谁拥有哪台笔记本电脑,何时购买以正确折旧,处理软件许可证等。
前期准备:
- 服务器一台,最低配置1核1G(推荐1核2G);
- 已经解析的域名一个;
- 系统要求:
需要以下Ubuntu64位版本之一:
Ubuntu Lunar 23.04
Ubuntu Kinetic 22.10
Ubuntu Jammy 22.04(LTS)
Ubuntu Focal 20.04(LTS)
Docker Engine for Ubuntu兼容x86_64(或amd64),armhf,arm64, S390X和PPC64LE(PPC64EL)体系结构。 - 需要安装Docker Engine、Docker-compose、Nginx Proxy Manager;
- 关于如何安装Docker,请参考Docker安装教程
- 官方文档说明
开始安装:
#切换到指定安装目录
cd /root
#创建项目所需的目录
mkdir snipe_it
mkdir snipe_mysql
#进入网站项目文件夹
cd /root/snipe_it
#创建一个docker-compose.yml配置文件
touch docker-compose.yml
#编辑该文件
vim docker-compose.yml
将下面代码复制到docker-compose.yml中保存即可
version: '3'
services:
# Snipe-IT 服务配置
snipeit:
container_name: snipeit
image: snipe/snipe-it:latest # 使用最新版 Snipe-IT 镜像
restart: always # 总是在容器退出时重启
ports:
- "8000:80" # 映射容器端口 80 到主机端口 8000
volumes:
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime # 设置容器时区为上海
- ./logs:/root/snipe_it/logs/ # 映射日志目录到本地logs目录
- ./snipe-vol:/var/lib/snipeit # 映射 Snipe-IT 数据目录到本地snipe-vol目录
depends_on:
- mysql # 依赖于 mysql 服务
env_file:
- .env.docker # 使用 .env.docker 文件中的环境变量配置
networks:
- snipeit-backend # 使用 snipeit-backend 网络
# MySQL 服务配置
mysql:
image: mysql:8.0 # 使用 MySQL 8.0 镜像
container_name: mysql
ports:
- 3306:3306 # 映射容器端口 3306 到主机端口 3306
restart: always # 总是在容器退出时重启
volumes:
- ./db:/var/lib/mysql # 映射数据库目录到本地db目录
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime # 设置容器时区为上海
environment:
MYSQL_ROOT_PASSWORD: 123456789 # MySQL root 用户密码
MYSQL_DATABASE: snipeit_data # 新建数据库名称
MYSQL_USER: snipeit # 新建用户
MYSQL_PASSWORD: 123456789 # 设置用户密码
command:
- --default-authentication-plugin=mysql_native_password # 设置 MySQL 默认认证插件为 mysql_native_password
- --character-set-server=utf8mb4 # 设置 MySQL 服务器使用 utf8mb4 字符集
- --collation-server=utf8mb4_unicode_ci # 设置 MySQL 服务器的字符校对规则为 utf8mb4_unicode_ci
networks:
- snipeit-backend # 使用 snipeit-backend 网络
networks:
snipeit-backend: # Snipe-IT 和 MySQL 服务共用的网络
#确保当前在/root/snipe_it目录下,创建docker-compose.yml文件中所需要的.env.docker配置依赖
touch .env.docker
#生成APP_KEY值
docker run --rm snipe/snipe-it
#你将得到如下的显示
Please re-run this container with an environment variable $APP_KEY
An example APP_KEY you could use is:
base64:2g4tKBr2Knc8pW5fHNJPhge/q/s3bbVxsqCT2hnOt5I=
将下面代码复制到.env.docker中保存,其中的密码请重新自定义,并将上面自己生成的base64整行key值替换到下面文件中对应的地方
# --------------------------------------------
# REQUIRED: DB SETUP
# --------------------------------------------
# 当数据库使用mysql的时候的配置
MYSQL_PORT_3306_TCP_ADDR=mysql
MYSQL_PORT_3306_TCP_PORT=3306
MYSQL_DATABASE=snipeit_data
MYSQL_USER=snipeit
MYSQL_PASSWORD=123456789
MYSQL_ROOT_PASSWORD=123456789
# --------------------------------------------
# REQUIRED: BASIC APP SETTINGS
# --------------------------------------------
#环境设置成生产环境
APP_ENV=production
#关掉debug
APP_DEBUG=false
#上面命令生成的APP_KEY值
APP_KEY=base64:2g4tKBr2Knc8pW5fHNJPhge/q/s3bbVxsqCT2hnOt5I=
#设置网站访问地址
APP_URL=你的服务器ip:8000
APP_TIMEZONE='Asia/Shanghai'
APP_LOCALE=zh-CN
MAX_RESULTS=1000
#每分钟访问限制
API_THROTTLE_PER_MINUTE=2000
# --------------------------------------------
# REQUIRED: UPLOADED FILE STORAGE SETTINGS
# --------------------------------------------
PRIVATE_FILESYSTEM_DISK=local
PUBLIC_FILESYSTEM_DISK=local_public
# --------------------------------------------
# REQUIRED: DATABASE SETTINGS
# --------------------------------------------
#设置数据库
DB_CONNECTION=mysql
DB_HOST=mysql
DB_DATABASE=snipeit_data
DB_USERNAME=snipeit
DB_PASSWORD=123456789
DB_PREFIX=null
DB_DUMP_PATH='/usr/bin'
DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci
# --------------------------------------------
# OPTIONAL: SSL DATABASE SETTINGS
# --------------------------------------------
DB_SSL=false
DB_SSL_IS_PAAS=false
DB_SSL_KEY_PATH=null
DB_SSL_CERT_PATH=null
DB_SSL_CA_PATH=null
DB_SSL_CIPHER=null
# --------------------------------------------
# REQUIRED: OUTGOING MAIL SERVER SETTINGS
# --------------------------------------------
#设置邮箱
MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com
MAIL_PORT=25
MAIL_USERNAME=xxxxxxxx@163.com
MAIL_PASSWORD=xxxxxxxxxxxxxx
MAIL_ENCRYPTION=null
MAIL_FROM_ADDR=xxxxxxxxxxxxx@163.com
MAIL_FROM_NAME='Snipe-IT-From'
MAIL_REPLYTO_ADDR=xxxxxxxxxxx@163.com
MAIL_REPLYTO_NAME='Snipe-IT-Replyto'
MAIL_AUTO_EMBED_METHOD='attachment'
# --------------------------------------------
# REQUIRED: IMAGE LIBRARY
# This should be gd or imagick
# --------------------------------------------
IMAGE_LIB=gd
# --------------------------------------------
# OPTIONAL: BACKUP SETTINGS
# --------------------------------------------
MAIL_BACKUP_NOTIFICATION_DRIVER=null
MAIL_BACKUP_NOTIFICATION_ADDRESS=null
BACKUP_ENV=true
# --------------------------------------------
# OPTIONAL: SESSION SETTINGS
# --------------------------------------------
# 指定会话应保持有效的时间(以分钟为单位)。
SESSION_LIFETIME=12000
# 指定当用户关闭浏览器窗口时登录的会话是否应过期。
EXPIRE_ON_CLOSE=false
# 指定您是否希望在 Snipe-IT 会话中使用加密 cookie。
ENCRYPT=false
COOKIE_NAME=snipeit_session
COOKIE_DOMAIN=null
SECURE_COOKIES=false
API_TOKEN_EXPIRATION_YEARS=40
# --------------------------------------------
# OPTIONAL: SECURITY HEADER SETTINGS
# --------------------------------------------
APP_TRUSTED_PROXIES=192.168.1.1,10.0.0.1
ALLOW_IFRAMING=false
REFERRER_POLICY=same-origin
ENABLE_CSP=false
CORS_ALLOWED_ORIGINS=null
ENABLE_HSTS=false
# --------------------------------------------
# OPTIONAL: CACHE SETTINGS
# --------------------------------------------
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
CACHE_PREFIX=snipeit
# --------------------------------------------
# OPTIONAL: REDIS SETTINGS
# --------------------------------------------
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
# --------------------------------------------
# OPTIONAL: MEMCACHED SETTINGS
# --------------------------------------------
MEMCACHED_HOST=null
MEMCACHED_PORT=null
# --------------------------------------------
# OPTIONAL: PUBLIC S3 Settings
# --------------------------------------------
PUBLIC_AWS_SECRET_ACCESS_KEY=null
PUBLIC_AWS_ACCESS_KEY_ID=null
PUBLIC_AWS_DEFAULT_REGION=null
PUBLIC_AWS_BUCKET=null
PUBLIC_AWS_URL=null
PUBLIC_AWS_BUCKET_ROOT=null
# --------------------------------------------
# OPTIONAL: PRIVATE S3 Settings
# --------------------------------------------
PRIVATE_AWS_ACCESS_KEY_ID=null
PRIVATE_AWS_SECRET_ACCESS_KEY=null
PRIVATE_AWS_DEFAULT_REGION=null
PRIVATE_AWS_BUCKET=null
PRIVATE_AWS_URL=null
PRIVATE_AWS_BUCKET_ROOT=null
# --------------------------------------------
# OPTIONAL: AWS Settings
# --------------------------------------------
AWS_ACCESS_KEY_ID=null
AWS_SECRET_ACCESS_KEY=null
AWS_DEFAULT_REGION=null
# --------------------------------------------
# OPTIONAL: LOGIN THROTTLING
# --------------------------------------------
LOGIN_MAX_ATTEMPTS=5
LOGIN_LOCKOUT_DURATION=60
RESET_PASSWORD_LINK_EXPIRES=900
# --------------------------------------------
# OPTIONAL: MISC
# --------------------------------------------
LOG_CHANNEL=stderr
LOG_MAX_DAYS=10
APP_LOCKED=false
APP_CIPHER=AES-256-CBC
GOOGLE_MAPS_API=
LDAP_MEM_LIM=500M
LDAP_TIME_LIM=600
# 允许清除已删除信息
ALLOW_DATA_PURGE=true
# 允许删除备份
ALLOW_BACKUP_DELETE=true
#创建并启动 Snipe-IT 和 MySQL 两个容器
docker-compose up -d
登录配置:
打开浏览器,ip+端口的方式访问即可:
点击保存用户后,会退出到登录界面要求重新登陆验证下,成功登录后后台管理界面如下: