Docker搭建自动售货系统-独角数卡
有什么用
自动售货系统-独角数卡
尝试按教材和视频搭建失败了(详见章节:搭建失败的历史记录),
鼓起勇气,重新选用新的方案:https://blog.dov.moe/posts/49102/
举个🌰例子:https://dovshop.net/
实现方法
cd /www/server/panel/data/compose/dujiaoka/template
mkdir Shop && cd Shop
mkdir storage uploads
chmod 777 storage uploads
❗注意此处文件夹权限一定要给!
chmod -R 777 env.conf
# 重要步骤
version: "3"
services:
faka:
image: ghcr.io/apocalypsor/dujiaoka:latest
# 国内服务器可以用 hkccr.ccs.tencentyun.com/apocalypsor/dujiaoka:latest
container_name: faka
environment:
# - INSTALL=false
- INSTALL=true
# - MODIFY=true
volumes:
- ./env.conf:/dujiaoka/.env
- ./uploads:/dujiaoka/public/uploads
- ./storage:/dujiaoka/storage
- ./start-hook.sh:/dujiaoka/start-hook.sh
# 网站图标 32X32 favicon.ico 4kb,默认模版只需第一处,其他模版需要第二处
- ./favicon.ico:/dujiaoka/public/favicon.ico:ro
- ./favicon.ico:/dujiaoka/public/assets/style/favicon.ico:ro
# 默认商品图片 512x512 default.jpg 18kb(网站 LOGO 共享此图,与后台自定义 LOGO 和商品图片不冲突)
- ./default.png:/dujiaoka/public/assets/common/images/default.jpg:ro
# Luna 主题网站背景 1920x1224 background.png 198kb
- ./background.png:/dujiaoka/public/assets/luna/img/background.png:ro
ports:
- 4444:80
restart: always
db:
image: mariadb:focal
container_name: faka-data
restart: always
environment:
- MYSQL_ROOT_PASSWORD=mariadb
- MYSQL_DATABASE=dujiaoka
- MYSQL_USER=dujiaoka
- MYSQL_PASSWORD=dujiaokapassword
volumes:
- ./data:/var/lib/mysql
redis:
image: redis:alpine
container_name: faka-redis
restart: always
volumes:
- ./redis:/data
编辑 .env 文件
APP_NAME=Carl的小店
APP_ENV=local
APP_KEY=base64:hDVkYhfkUjaePiaI1tcBT7G8bh2A8RQxwWIGkq7BO18=
APP_DEBUG=false
APP_URL=http://192.168.6.116:4444
#ADMIN_HTTPS=true
LOG_CHANNEL=stack
# 数据库配置
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=dujiaoka
DB_USERNAME=dujiaoka
DB_PASSWORD=dujiaokapassword
# redis 配置
REDIS_HOST=redis
REDIS_PASSWORD=
REDIS_PORT=6379
BROADCAST_DRIVER=log
SESSION_DRIVER=file
SESSION_LIFETIME=120
# 缓存配置
# file 为磁盘文件 redis 为内存级别
# redis 为内存需要安装好 redis 服务端并配置
CACHE_DRIVER=redis
# 异步消息队列
# sync 为同步 redis 为异步
# 使用 redis 异步需要安装好 redis 服务端并配置
QUEUE_CONNECTION=redis
# 后台语言
## zh_CN 简体中文
## zh_TW 繁体中文
## en 英文
DUJIAO_ADMIN_LANGUAGE=zh_CN
# 后台登录地址
ADMIN_ROUTE_PREFIX=/admin
一直无法下载成功......
修改使用:stilleshan/dujiaoka
docker-compose+如何使用代理提速
https://neucrack.com/p/286
workaournd:手动让OpenClash不停在线(不在线就重新刷新取获取最新节点信息)
终于下载成功后,启动失败
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/www/server/panel/data/compose/dujiaoka/template/Shop/favicon.ico" to rootfs at "/dujiaoka/public/favicon.ico": mount /www/server/panel/data/compose/dujiaoka/template/Shop/favicon.ico:/dujiaoka/public/favicon.ico (via /proc/self/fd/6), flags: 0x5001: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
注释掉那几个自定义的文件映射,就好了
faka | The environment file is invalid!
faka | Failed to parse dotenv file due to unexpected whitespace. Failed at [Carl Shop].
返回修改把前后加上引号。
修改了端口映射出4444后,错误:
500
Server Error
❗注意环境变量如果写的不对可能导致 500,可以开 APP_DEBUG=true 看看具体是哪里写错了。
throw new RuntimeException('The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.');
解决办法:修改APP_KEY=base64:hDVkYhfkUjaePiaI1tcBT7G8bh2A8RQxwWIGkq7BO18=
--------------
file_put_contents(/dujiaoka/.env): failed to open stream: Permission denied
本地访问成功:http://192.168.6.116:4444
参考资料
https://hub.docker.com/r/stilleshan/dujiaoka
https://hub.docker.com/r/jiangjuhong/dujiaoka
搭建失败的历史记录
独角数卡
开源式站长自动化售货解决方案、高效、稳定、快速!
徒手搭建独角数发卡网站 经营自己的小店! - 六月 26, 2023
https://kejilion.blogspot.com/2023/06/blog-post_26.html
配置docker-compose
https://github.com/kejilion/docker/blob/main/LNMP-docker-compose.yml
version: '3.8'
services:
nginx:
image: nginx:1.22
container_name: nginx
restart: always
ports:
- 882:80
- 4444:443
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./certs:/etc/nginx/certs
- ./html:/var/www/html
php:
image: php:7.4.33-fpm
container_name: php
restart: always
volumes:
- ./html:/var/www/html
mysql:
image: mysql:5.7.42
container_name: mysql
restart: always
volumes:
- ./mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=webroot
- MYSQL_DATABASE=web
- MYSQL_USER=carlZeng
- MYSQL_PASSWORD=carlZengYYDS
redis:
image: redis:latest
container_name: redis
restart: always
volumes:
- ./redis:/data
修改了独角数卡的端口
申请证书, 下载证书;
直接去NPM中下载证书解压缩后重命名放到debian的目录:
/home/web/certs
key.pem
cert.pem
继续配置nginx.conf
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_max_body_size 1000m;
#上传限制参数1G以内文件可上传
# HTTP server
server {
listen 80;
server_name shop.carlzeng.top;
# Redirect all HTTP requests to HTTPS
return 301 https://$host$request_uri;
}
# HTTPS server
server {
listen 443 ssl http2;
server_name shop.carlzeng.top;
# http2 on;
ssl_certificate /etc/nginx/certs/cert.pem;
ssl_certificate_key /etc/nginx/certs/key.pem;
root /var/www/html/dujiaoka/public/;
index index.php;
try_files $uri $uri/ /index.php?$query_string;
# PHP-FPM configuration
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
cd /home/web/html && wget https://ghproxy.com/https://github.com/assimon/dujiaoka/releases/download/2.0.6/2.0.6-antibody.tar.gz && apt install -y tar && tar -zxvf 2.0.6-antibody.tar.gz && rm 2.0.6-antibody.tar.gz
安装PHP扩展
docker exec php apt update && docker exec php apt install -y libmariadb-dev-compat libmariadb-dev libzip-dev libmagickwand-dev imagemagick
卡死在这一步,分解如下:
docker exec php apt install -y libmariadb-dev-compat
docker exec php apt install -y libmariadb-dev
docker exec php apt install -y libzip-dev
docker exec php apt install -y libmagickwand-dev
libmagickwand-dev is already the newest version (8:6.9.11.60+dfsg-1.3+deb11u1).
docker exec php apt install -y imagemagick
Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20190902/redis.so'
install ok: channel://pecl.php.net/redis-6.0.2
configuration option "php_ini" is not set to php.ini location
You should add "extension=redis.so" to php.ini
docker exec php docker-php-ext-install pdo_mysql zip bcmath gd intl opcache && docker exec php pecl install redis && docker exec php sh -c 'echo "extension=redis.so" > /usr/local/etc/php/conf.d/docker-php-ext-redis.ini'
如果登录时报错再使用该命令,解除HTTPS限制
sed -i 's/ADMIN_HTTPS=false/ADMIN_HTTPS=true/g' /home/web/html/dujiaoka/.env
错误以及解决办法
不同时期再网页页面,点击安装后出现的错误
数据库配置错误 :could not find driver (SQL: select 1 limit 1)
解决:修改了nginx.conf,确保80和443端口(docker中的端口占用,默认即可)
确认了php docker中的PHP扩展,确保所有插件都安装成功
Redis配置错误 :php_network_getaddresses: getaddrinfo failed: Name or service not known
解决:sed -i 's/ADMIN_HTTPS=false/ADMIN_HTTPS=true/g' /home/web/html/dujiaoka/.env
核查了php docker中 安装PHP拓展部分于redis相关的;
docker-php-ext-redis.ini(已包含内容:extension=redis.so)
原来是redis 写成了radis,纠正后重试
数据库配置错误 :SQLSTATE[HY000] [1045] Access denied for user 'carlZEng'@'172.24.0.5' (using password: YES) (SQL: select 1 limit 1)
解决:MySQL用户名填写错误,纠正后重试
数据库配置错误 :could not find driver (SQL: select 1 limit 1)
解决:
检测:docker exec -it php php -i |grep mysqlnd 排查是否启用了mysql驱动
mysqlnd
mysqlnd => enabled
Version => mysqlnd 7.4.3
docker exec -it php /bin/bash
docker-php-ext-install pdo pdo_mysql
docker-compose restart php
这个好像没有被永久保存住,这导致每次docker-compose restart php都会出现这个错误,
按照上面解决好以后,紧接着就是下面这个Redis错误
这次是修正后,最后是通过docker restart php 解决了错误
测试 docker-compose restart 会不会把数据在继续破坏了,重新拉取?
也是正常的! 那下一次怎么办?继续如此修复即可
Please make sure the PHP Redis extension is installed and enabled.
docker exec -it php /bin/bash
pecl install redis
checking for igbinary includes... configure: error: Cannot find igbinary.h
ERROR: `/tmp/pear/temp/redis/configure --with-php-config=/usr/local/bin/php-config --enable-redis-igbinary=yes --enable-redis-lzf=yes --enable-redis-zstd=yes --enable-redis-msgpack=yes --enable-redis-lz4=yes --with-liblz4' failed
Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20190902/redis.so'
install ok: channel://pecl.php.net/redis-6.0.2
configuration option "php_ini" is not set to php.ini location
You should add "extension=redis.so" to php.ini
解决:docker exec php docker-php-ext-install pdo_mysql zip bcmath gd intl opcache && docker exec php pecl install redis && docker exec php sh -c 'echo "extension=redis.so" > /usr/local/etc/php/conf.d/docker-php-ext-redis.ini'
解决分解,并逐一确认执行成功
docker exec -it php /bin/bash
docker-php-ext-install pdo_mysql zip bcmath gd intl opcache
pecl install redis
sh -c 'echo "extension=redis.so" > /usr/local/etc/php/conf.d/docker-php-ext-redis.ini'
在 bash 下,一一执行,检查结果
最后,需要docker-compose restart
之前都是重启php容器docker restart php 无法解决问题。需要的是:docker-compose restart
0 error
安装成功后 redirect https://192.168.6.116:4444/admin/auth/login
# 后台登录出现0err或者其他登录异常问题,大概率是开启了https而后台没有开启,把下面的false改为true即可
ADMIN_HTTPS=false
解决:sed -i 's/ADMIN_HTTPS=false/ADMIN_HTTPS=true/g' /home/web/html/dujiaoka/.env
成功了,本地局域网可访问。
下一步是为何无法NPM反代https://192.168.6.116:4444
[outstanding]创建订单出错 Symfony\Component\Debug\Exception\FatalThrowableError
Call to undefined function App\Service\bcmul()
https://192.168.6.116:4444/create-order
[outstanding]npm更换二级域名后反代成功 https://buy.carlzeng.top:4443/ 导致问题:所有的图片那些指向的链接 没有加端口号,导致图片全部失效, buy链接也没有端口号...
重命名install.lock 重装
重装后数据重新配置,导致设置的商品等等全部清零;上面问题待测试
URL自动携带端口,没有解决。