环境信息
- EMQ X 版本:4.3.5
- 操作系统及版本:macos
- 其他: docker-compose
问题描述
我试了容器宿主机地址,如:
http://host.docker.internal:8089/index.php
或者是宿主机局域网地址,还有百度,都不行。。
不过, 在emqx容器里这些地址用 curl 命令是都能访问的。
webhook 插件启动不起来,emqx启动后,点界面里的启动报:
{emqx_web_hook,{bad_return,{{emqx_web_hook_app,start,[normal,[]]},{'EXIT',{badarg,[{erlang,binary_to_existing_atom,[<<"client_disconnect">>,utf8],[]},{emqx_web_hook,parse_rule,2,[{file,"emqx_web_hook.erl"},{line,353}]},{emqx_web_hook,load,0,[{file,"emqx_web_hook.erl"},{line,75}]},{emqx_web_hook_app,start,2,[{file,"emqx_web_hook_app.erl"},{line,35}]},{application_master,start_it_old,4,[{file,"application_master.erl"},{line,277}]}]}}}}}
当然,日志里也会先报
配置文件及日志
docker-compose
version: '3.1'
services:
db:
image: mysql:5
container_name: mysql
# for mysql 8.0
# command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: "xxxxxxxxxx"
volumes:
- ./data/mysql:/var/lib/mysql
adminer:
image: adminer
container_name: adminer
restart: always
ports:
- 8088:8080
nginx:
image: nginx:latest
container_name: nginx
restart: always
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/conf.d:/etc/nginx/conf.d
ports:
- "1883:1883"
- "8083:8083"
- "8883:8883"
- "8084:8084"
- "18083:18083"
emqx:
image: emqx/emqx:latest
container_name: emqx
environment:
- "EMQX_NAME=emqx"
# - "EMQX_HOST=node1.emqx.io" 如果指定HOST需要启动docker networks
# 集群模式时使用
# - "EMQX_CLUSTER__DISCOVERY=static"
# - "EMQX_CLUSTER__STATIC__SEEDS=emqx@node1.emqx.io, emqx@node2.emqx.io"
# 插件管理
- "EMQX_LOADED_PLUGINS=emqx_auth_mysql,emqx_management,emqx_recon,emqx_retainer,emqx_rule_engine,emqx_dashboard,emqx_web_hook"
# 禁用匿名认证
- "EMQX_ALLOW_ANONYMOUS=false"
# dashboard默认密码 dashboard.default_user.password = public 暂时无效,注意,只有.才用__替换,单个的_不要替换
- "EMQX_DASHBOARD__DEFAULT_USER__PASSWORD=xxxxxxx"
# mysql 认证
- "EMQX_AUTH__MYSQL__SERVER=192.168.0.11:3306"
- "EMQX_AUTH__MYSQL__POOL=8"
- "EMQX_AUTH__MYSQL__USERNAME=xxxx"
- "EMQX_AUTH__MYSQL__PASSWORD=sxxxxx"
- "EMQX_AUTH__MYSQL__DATABASE=xxdb"
- "EMQX_AUTH__MYSQL__PASSWORD_HASH=sha256"
- "EMQX_AUTH__MYSQL__QUERY_TIMEOUT=5s"
- "EMQX_AUTH__MYSQL__AUTH_QUERY=select password from mqtt_user where username = '%u' limit 1"
- "EMQX_AUTH__MYSQL__SUPER_QUERY=select is_superuser from mqtt_user where username = '%u' limit 1"
- "EMQX_AUTH__MYSQL__ACL_QUERY=select allow, ipaddr, username, clientid, access, topic from mqtt_acl where ipaddr = '%a' or username = '%u' or username = '$all' or clientid = '%c'"
# webhook 配置。不用启动后手动配置
- 'EMQX_WEB__HOOK__API__URL="http://host.docker.internal:8089/index.php"'
- 'EMQX_WEB__HOOK__RULE__CLIENT__CONNECTED__1={"action": "on_client_connect"}'
- 'EMQX_WEB__HOOK__RULE__CLIENT__DISCONNECTED__1={"action": "on_client_disconnect"}'
# - 'EMQX_WEB__HOOK__RULE__CLIENT__SUBSCRIBE__1={"on_client_subscribed"}'
# - 'EMQX_WEB__HOOK__RULE__CLIENT__UNSUBSCRIBE__1={"on_client_unsubscribed"}'
# # - 'EMQX_WEB__HOOK__RULE__SESSION_SUBSCRIBED_1={"action": "on_session_subscribed"}'
# # - 'EMQX_WEB__HOOK__RULE__SESSION_UNSUBSCRIBED_1={"action": "on_session_unsubscribed"}'
# - 'EMQX_WEB__HOOK__RULE__MESSAGE_PUBLISH_1={"action": "on_message_publish", "topic": "#/update"}'
# - 'EMQX_WEB__HOOK__RULE__MESSAGE_ACKED_1={"action": "on_message_acked"}'
# - 'EMQX_WEB__HOOK__RULE__MESSAGE_DROPPED_1={"action": "on_message_dropped"}'
volumes:
# 解决容器时区问题
- /etc/localtime:/etc/localtime
depends_on:
- db
links:
- db
日志
emqx | allow_anonymous = "false"
emqx | listener.ssl.external.acceptors = "32"
emqx | listener.ssl.external.max_connections = "102400"
emqx | listener.tcp.external.acceptors = "64"
emqx | listener.tcp.external.max_connections = "1024000"
emqx | listener.ws.external.acceptors = "16"
emqx | listener.ws.external.max_connections = "102400"
emqx | listener.wss.external.acceptors = "16"
emqx | listener.wss.external.max_connections = "102400"
emqx | log.to = "console"
emqx | node.max_ets_tables = "2097152"
emqx | node.max_ports = "1048576"
emqx | node.name = "emqx@192.168.0.5"
emqx | node.process_limit = "2097152"
emqx | rpc.port_discovery = "manual"
emqx | Exec: /opt/emqx/erts-11.1.8/bin/erlexec -noshell -noinput +Bd -boot /opt/emqx/releases/4.3.5/start -mode embedded -boot_var ERTS_LIB_DIR /opt/emqx/erts-11.1.8/../lib -mnesia dir "/opt/emqx/data/mnesia/emqx@192.168.0.5" -config /opt/emqx/data/configs/app.2021.07.09.14.49.01.config -args_file /opt/emqx/data/configs/vm.2021.07.09.14.49.01.args -vm_args /opt/emqx/data/configs/vm.2021.07.09.14.49.01.args -start_epmd false -epmd_module ekka_epmd -proto_dist ekka -- foreground
emqx | Root: /opt/emqx
emqx | Starting emqx on node emqx@192.168.0.5
emqx | Start http:management listener on 8081 successfully.
emqx | Start http:dashboard listener on 18083 successfully.
emqx | 2021-07-09T14:49:05.360724+08:00 [error] crasher: initial call: application_master:init/4, pid: <0.1869.0>, registered_name: [], exit: {{bad_return,{{emqx_web_hook_app,start,[normal,[]]},{'EXIT',{badarg,[{erlang,binary_to_existing_atom,[<<"client_disconnect">>,utf8],[]},{emqx_web_hook,parse_rule,2,[{file,"emqx_web_hook.erl"},{line,353}]},{emqx_web_hook,load,0,[{file,[...]},{line,...}]},{emqx_web_hook_app,start,2,[{file,...},{...}]},{application_master,start_it_old,4,[{...}|...]}]}}}},[{application_master,init,4,[{file,"application_master.erl"},{line,138}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}, ancestors: [<0.1868.0>], message_queue_len: 1, messages: [{'EXIT',<0.1870.0>,normal}], links: [<0.1868.0>,<0.1431.0>], dictionary: [], trap_exit: true, status: running, heap_size: 610, stack_size: 28, reductions: 244; neighbours:
emqx | 2021-07-09T14:49:05.369975+08:00 [error] [Plugins] Load plugin emqx_web_hook failed, cannot start plugin emqx_web_hook for {bad_return,{{emqx_web_hook_app,start,[normal,[]]},{'EXIT',{badarg,[{erlang,binary_to_existing_atom,[<<"client_disconnect">>,utf8],[]},{emqx_web_hook,parse_rule,2,[{file,"emqx_web_hook.erl"},{line,353}]},{emqx_web_hook,load,0,[{file,"emqx_web_hook.erl"},{line,75}]},{emqx_web_hook_app,start,2,[{file,[...]},{line,...}]},{application_master,start_it_old,4,[{file,...},{...}]}]}}}}
emqx | Start mqtt:tcp:internal listener on 127.0.0.1:11883 successfully.
emqx | Start mqtt:tcp:external listener on 0.0.0.0:1883 successfully.
emqx | Start mqtt:ws:external listener on 0.0.0.0:8083 successfully.
emqx | Start mqtt:ssl:external listener on 0.0.0.0:8883 successfully.
emqx | Start mqtt:wss:external listener on 0.0.0.0:8084 successfully.
emqx | EMQ X Broker 4.3.5 is running now!