前提
环境
- ubuntu22.04(不重要)
- 安装好 docker
- 安装好 docker-compose
拉去镜像
也可以部署的时候拉取
- mysql
- snipe-it
docker pull mysql:8.0
docker pull snipe/snipe-it:v6.1.0
这里咱们拉去的是最新版本
参考文档链接
下载官方源码包
https://github.com/snipe/snipe-it/releases/tag/v6.1.0
下载源码包,然后解压,找到其中的 .env.docker 文件
其实最主要就是要这个文件
部署
填写 .env.docker 文件中的变量
这里直接贴出来
# --------------------------------------------
# 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=111111
MYSQL_ROOT_PASSWORD=111111
# --------------------------------------------
# REQUIRED: BASIC APP SETTINGS
# --------------------------------------------
#环境需要设置成生产环境
APP_ENV=production
#需要关掉debug
APP_DEBUG=false
# please regenerate the APP_KEY value by calling `docker-compose run --rm snipeit bash` and then `php artisan key:generate --show` and then copy paste the value here
#需要生成这个给key 一会儿下面会说到
APP_KEY=base64:UpVD6wvSwM1Zy99Vh/UPmqRWyC5w6OzXGlY4BegiOnc=
#设置链接,这个要设置宿主机的IP地址,如果是域名,也需要把域名解析到宿主机上
APP_URL=http://192.168.140.240
APP_TIMEZONE='Asia/Shanghai'
APP_LOCALE=zh-CN
MAX_RESULTS=500
# --------------------------------------------
# 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=111111
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
[email protected]
MAIL_PASSWORD=xxxxxxxxxxxxxx
MAIL_ENCRYPTION=null
[email protected]
MAIL_FROM_NAME='Snipe-IT-From'
[email protected]
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
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
生成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:UpVD6wvSwM1Zy99Vh/UPmqRWyC5w6OzXGlY4BegiOnc=
docker-compose.yaml 资源清单文件
version: '3'
services:
snipeit:
container_name: snipeit
image: snipe/snipe-it:v6.1.0
ports:
- "80:80"
volumes:
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
- ./logs:/var/www/html/storage/logs
- ./snipe-vol:/var/lib/snipeit
depends_on:
- mysql
env_file:
- .env.docker
networks:
- snipeit-backend
mysql:
image: mysql:8.0
container_name: mysql
ports:
- 3306:3306
restart: always
volumes:
- ./db:/var/lib/mysql
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
environment:
MYSQL_ROOT_PASSWORD: 111111
#允许空密码
#MYSQL_ALLOW_EMPTY_PASSWORD: yes
#新建数据库
MYSQL_DATABASE: snipeit_data
#新建用户
MYSQL_USER: snipeit
#设置用户密码
MYSQL_PASSWORD: 111111
command:
- --default-authentication-plugin=mysql_native_password
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
networks:
- snipeit-backend
networks:
snipeit-backend:
.env.docker文件需要与docker-compose.yaml文件保持在同目录下
部署
docker-compose up -d
注意事项
建表问题
当我们第一次运行docker-compose.yaml文件的时候,数据库能过够完成初始化,但是 snipe-it 无法正常初始化,所以也就无法创建表。
解决办法
重启一下容器就好了
#查看日志
docker-compose logs -f
#mysql已经初始化好了,就可以重启了
```bash
docker-compose restart
修改权限
需要到容器中执行
docker-compose exec snipeit bash
chmod -R 777 storage
chmod -R 777 public/uploads
chmod -R 777 bootstrap/cache
备份无法执行的问题
当我们点击备份的时候,会红一片,稍微看下错误后,会发现是用户权限不足
进入数据库,修改用户权限
mysql5.7版本的和8.0版本的略有区别
这里以8.0举例
GRANT RELOAD, LOCK TABLES ON *.* TO 'snipeit'@'%';
FLUSH PRIVILEGES;
标签:compose,AWS,DB,--------------------------------------------,snipeit,docker,null,
From: https://www.cnblogs.com/guangdelw/p/17496598.html