Docker搭建自动售货系统-独角数卡

自动售货系统-独角数卡 dujiaoka

有什么用

自动售货系统-独角数卡;佰阅发卡kamifaka
尝试按教材和视频搭建失败了(详见章节:搭建失败的历史记录),
鼓起勇气,重新选用新的方案:https://blog.dov.moe/posts/49102/

举个🌰例子:https://dovshop.net/ https://ayangshop.com/buy/38

由于本人无法解决,反代以后的页面中链接没有自动携带端口好问题。放弃使用dujiaoka。

启用:佰阅发卡kamifaka,Carl Notes 小店:https://bestbuy.carlzeng.com:3/

实现方法

1
2
3
4
5
6
7
8
9
cd /www/server/panel/data/compose/dujiaoka/template

mkdir Shop && cd Shop
mkdir storage uploads
chmod 777 storage uploads
❗注意此处文件夹权限一定要给!

chmod -R 777 env.conf
# 重要步骤
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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

1
2
3
docker-compose+如何使用代理提速
https://neucrack.com/p/286
workaournd:手动让OpenClash不停在线(不在线就重新刷新取获取最新节点信息)

终于下载成功后,启动失败

1
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

注释掉那几个自定义的文件映射,就好了

1
2
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 看看具体是哪里写错了。

1
2
3
4
5
6
7
8
   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

搭配frpc

20231203 NPM反代失败,几周后;终于找到解决方案了:发现可以用frpc反代出去就好

配置完成frpc -c frpc.ini, 可是依旧是点击的链接没有携带端口号;非常郁闷



踩坑记录及解决办法

独角数卡
开源式站长自动化售货解决方案、高效、稳定、快速!

徒手搭建独角数发卡网站 经营自己的小店! - 六月 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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

修改了独角数卡的端口

申请证书, 下载证书;

1
2
3
4
5
直接去NPM中下载证书解压缩后重命名放到debian的目录:
/home/web/certs
key.pem
cert.pem

继续配置nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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.com;

# Redirect all HTTP requests to HTTPS
return 301 https://$host$request_uri;
}

# HTTPS server
server {
listen 443 ssl http2;
server_name shop.carlzeng.com;

# 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扩展

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
解决:
检测: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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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

1
2
3
4
5
6
7
安装成功后 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.com:4443/ 导致问题:所有的图片那些指向的链接 没有加端口号,导致图片全部失效, buy链接也没有端口号…

重命名install.lock 重装

重装后数据重新配置,导致设置的商品等等全部清零;上面问题待测试
URL自动携带端口,没有解决。

NEXT:

参见文章:搭建图床 切换本站图片至自建服务 的解决方案:

​ * 静态资源加载失败 #317

​ * https+域名+端口的访问问题,NginxProxyManager反代 #607

Debian Manual 手动安装步骤

写在前面

  • 此教程专为有洁癖的宝宝们准备。不使用任何一键安装脚本。面板党可以退散了!!
  • 本人测试环境是 Debian 11 其他的没测试。

手动安装lnmp

  • 更新源
1
2
apt update  
apt upgrade
  • 安装Nginx
    1
    apt install nginx
  • 安装Mariadb
    1
    apt install mariadb-server
  • 配置Mariadb
    1
    mysql_secure_installation
    根据提示操作即可。
  • 创建数据库
    1
    mariadb
    之后会显示
    1
    2
    3
    4
    5
    6
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 74
    Server version: 10.3.15-MariaDB-1 Debian 10
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    MariaDB [(none)]>
    接下来输入命令
    1
    2
    3
    4
    CREATE DATABASE [这里替换为数据库名] ;
    GRANT ALL ON [这里替换为数据库名].* TO '[这里替换为用户名]'@'localhost' IDENTIFIED BY '[这里替换为密码]' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    EXIT
  • 安装PHP7.4
    1
    apt install php php-fpm php-mysql php-gd php-zip php-opcache php-curl php-mbstring php-intl php-dom php-bcmath php-redis php-fileinfo
  • 安装redis
    1
    apt install redis
  • 启用函数
    nano /etc/php/7.4/fpm/php.ini,ctrl+w 搜索 putenvproc_openpcntl_signalpcntl_alarmdisable_functions 一行 有就去掉。
    之后 /etc/init.d/php7.4-fpm reload

下载源代码

1
2
3
4
cd /var/www/dujiaoka
apt install git
git clone https://github.com/assimon/dujiaoka.git
chmod 777 -R /var/www/dujiaoka

配置 nginx

  • 假设你的域名是:domain.com
  • 假设你的网站目录是:/home/wwwroot/dujiaoka
  • 配置文件的存放目录是:/usr/local/nginx/conf/vhost
  • 按下文教程配置时,注意修改演示配置中的域名和目录
1
nano /etc/nginx/sites-enabled/dujiaoka 

你可以参考我的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
server
{
listen 80;
listen [::]:80;
server_name domain.com ;
return 301 https://$server_name$request_uri;
}

server
{
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domain.com ;
index index.html index.htm index.php default.html default.htm default.php;
root /var/www/dujiaoka/public;
ssl_certificate /etc/nginx/sslcert/cert.crt;
ssl_certificate_key /etc/nginx/sslcert/key.key;
# openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
#ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

location / {
try_files $uri $uri/ /index.php?$query_string;
}
#error_page 404 /404.html;

# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

location ~ [^/]\.php(/|$)
{

fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

include snippets/fastcgi-php.conf;
}


location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

location ~ /.well-known {
allow all;
}

location ~ /\.
{
deny all;
}

access_log off;
}

/etc/nginx/sslcert/ 上传你的https证书 之后 nginx -t 没有报错就重启nginx /etc/init.d/nginx restart

composer 安装

1
2
3
4
5
6
7
8
9
10
cd /var/www/dujiaoka
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
adduser user
su user
composer install
composer update
su

访问安装页面

访问你的域名,进行安装

  • MySQL 数据库名:dujiaoka
  • MySQl 密码:你设置的密码
  • Redis 密码:无需填写
  • 网站URL:你的域名,如 https://domain.com

##编辑配置文件

编辑 /var/www/dujiaoka/.env

  • APP_DEBUG=true 改为 APP_DEBUG=false
  • 另起一行,添加 ADMIN_HTTPS=true
  • 尝试登入后台。如果提示 0 error ,刷新页面即可

配置 Supervisor

先安装

1
apt install supervisor

创建配置文件

1
nano /etc/supervisor/conf.d/dujiaoka.conf

写入配置文件

  • 注意修改网站目录
    1
    2
    3
    4
    5
    6
    7
    8
    9
    [program:laravel-worker]
    process_name=%(program_name)s_%(process_num)02d
    command=php /home/wwwroot/dujiaoka/artisan queue:work
    autostart=true
    autorestart=true
    user=www
    numprocs=1
    redirect_stderr=true
    stdout_logfile=/home/wwwlogs/worker.log
    启动
    1
    2
    3
    supervisorctl reread
    supervisorctl update
    supervisorctl start laravel-worker:*

参考来源

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mariadb-php-lemp-stack-on-debian-10
https://github.com/assimon/dujiaoka/wiki/2.x_linux_install

docker部署佰阅发卡kamifaka

1
docker run --name kmfaka -itd -v /volume1/docker/kamifaka:/usr/src/app/public  -p 9200:8000 baiyuetribe/kamifaka:latest
1
2
3
4
5
6
7
8
9
10
11
12
13
version: "3"
services:
kamifaka:
container_name: kmfaka
stdin_open: true
tty: true
volumes:
- ./:/usr/src/app/public
# - ./user/js/app.20ca6680.js:/usr/src/app/dist/static/user/js/app.20ca6680.js
ports:
- 4445:8000
image: baiyuetribe/kamifaka:latest
restart: always

后台地址ip地址:4445/admin。默认管理员账号admin@qq.com,密码:123456。

NEXT:

  • 支付设置,支付接口设置(已完成)
  • 邮件通知,SMTP服务器地址或搭建

支付设置之支付宝当面付

  1. 开通:点击 立即开通,按要求填写并提交产品开通申请,点此查询 产品开通情况

    开发:点此查询 开发文档

  2. 申请成功以后,填写APPID, alipay_public_key, app_private_key

    1. APPID, 提交启用‘当面付’产品(应用状态:审核中 您的应用审核已提交,平台将在1天内完成审核)。第二天获得成功的状态,应用状态:已上线 ;图标下方复制APPID即可
    2. alipay_public_key,容易获取,每个人都是一样的
    3. app_private_key,使用“支付宝开放平台密钥工具”,生成用户公钥和私钥(就是这个app private key)
  3. 成功,可正常使用支付宝的方式支付:https://bestbuy.carlzeng.com:3/#/1/detail

从容器中拷贝文件到宿主机

1
docker cp kmfaka:/usr/src/app/dist/static/user/js/ ./user/                                                      

Reference

NAS用docker部署佰阅发卡卡密发卡系统kamifaka

球推荐一个发卡程序,除了独角风铃荔枝

个性化需求沟通 扫客服加V加群: