processone / docker-ejabberd

Set of ejabberd Docker images
94 stars 77 forks source link

How to configure vhost docker configuration for Ejabberd cluster #106

Closed skrleo closed 6 months ago

skrleo commented 1 year ago

I have two servers [192.168.10.1, 192.168.10.2]. I need to deploy clusters on the two servers. Now I have the following problems

I am in 192.168.10.1 and the following error occurred:

~ $ bin/ejabberdctl join_cluster ejabberd@192.168.10.2
Error: error
Error: {no_ping,'ejabberd@192.168.10.2'}

I checked the information and found that the configuration in ejabberdctl.cfg was missing. After changing the ejabberdctl.cfg file, the following error occurred: INET_DIST_INTERFACE=192.168.10.2

~ $ vi conf/ejabberdctl.cfg 
~ $ bin/ejabberdctl restart
init terminating in do_boot (cannot expand $RELEASE_LIB in bootfile)

Crash dump is being written to: erl_crash.dump...done
{"could not start kernel pid",application_controller,"{bad_environment_value,\"{\\"init\"}"}
=ERROR REPORT==== 13-Sep-2023::09:09:52.098183 ===
application_controller: unterminated string starting with "init": {"init

could not start kernel pid (application_controller) ({bad_environment_value,"{\"init"})

The following is my docker-composer configuration file, please tell me how to configure a cluster service

version: '3.7'

services:
  ejabberd:
    image: ejabberd/ecs
    container_name: ejabberd
    ports:
      - "5222:5222"
      - "5269:5269"
      - "5280:5280"
      - "5443:5443"
    environment:
      - ERLANG_NODE_ARG=ejabberd@192.168.10.1
      - ERLANG_COOKIE=dummycookie123
    volumes:
      - ./ejabberd/conf/ejabberd.yml:/home/ejabberd/conf/ejabberd.yml:ro
      - ./ejabberd/conf/ejabberdctl.cfg:/home/ejabberd/conf/ejabberdctl.cfg
      - ./ejabberd/logs:/home/ejabberd/logs
      - ./ejabberd/database:/home/ejabberd/database
    restart: always
version: '3.7'

services:
  ejabberd:
    image: ejabberd/ecs
    container_name: ejabberd
    ports:
      - "5222:5222"
      - "5269:5269"
      - "5280:5280"
      - "5443:5443"
    environment:
      - ERLANG_NODE_ARG=ejabberd@192.168.10.2
      - ERLANG_COOKIE=dummycookie123
    volumes:
      - ./ejabberd/conf/ejabberd.yml:/home/ejabberd/conf/ejabberd.yml:ro
      - ./ejabberd/conf/ejabberdctl.cfg:/home/ejabberd/conf/ejabberdctl.cfg
      - ./ejabberd/logs:/home/ejabberd/logs
      - ./ejabberd/database:/home/ejabberd/database
    restart: always

I could not get through this error. Any help is greatly appreciated.

badlop commented 1 year ago

I have two servers [192.168.10.1, 192.168.10.2]. I need to deploy clusters on the two servers.

Let's use the correct concepts: You have two servers, and you want to deploy two ejabberd nodes (one ejabberd node in each server), and setup them to become one cluster. Right?

Error: {no_ping,'ejabberd@192.168.10.2'}

Are both nodes running, and does "ejabberdctl status" work on each one of them?

Maybe the problem connecting is related to ports not yet opened.

    ports:
      - "5222:5222"
      - "5269:5269"
      - "5280:5280"
      - "5443:5443"

5222 is for XMPP clients, 5269 for XMPP servers, 5280 and 5443 are for your admin, HTTP tasks... How can both nodes connect between them, if you didn't open the required ports for them to connect?

There is a full list of relevant ports in https://docs.ejabberd.im/admin/guide/security/#firewall-settings

More specifically to this container, the list is https://github.com/processone/docker-ejabberd/blob/master/ecs/README.md#ports

In your case, you probably need to open the ports range from 4369 to 4399.

Look at this example composer file: https://github.com/processone/docker-ejabberd/blob/master/ecs/README.md#clustering-example It starts two ejabberd nodes in the same machine, and they become a cluster. Docker automatically takes care to setup both nodes in the same network, there are not port restrictions between both nodes, and consequently there is no need to explicitily open the ports 4369-4399. In your case, you have separate machines, so obviously you should tell each of the dockers to open the corresponding ports.

I don't have experience in docker-compose: is it possible to open a range of ports? Or it is only possible to open ports one by one?

skrleo commented 12 months ago
~ $ bin/ejabberdctl status
Failed RPC connection to the node ejabberd@cluster1: nodedown

Commands to start an ejabberd node:
  start      Start an ejabberd node in server mode
  debug      Attach an interactive Erlang shell to a running ejabberd node
  iexdebug   Attach an interactive Elixir shell to a running ejabberd node
  live       Start an ejabberd node in live (interactive) mode
  iexlive    Start an ejabberd node in live (interactive) mode, within an Elixir shell
  foreground Start an ejabberd node in server mode (attached)

Optional parameters when starting an ejabberd node:
  --config-dir dir   Config ejabberd:    /home/ejabberd/conf
  --config file      Config ejabberd:    /home/ejabberd/conf/ejabberd.yml
  --ctl-config file  Config ejabberdctl: /home/ejabberd/conf/ejabberdctl.cfg
  --logs dir         Directory for logs: /home/ejabberd/logs
  --spool dir        Database spool dir: /home/ejabberd/database/ejabberd@cluster1
  --node nodename    ejabberd node name: ejabberd@cluster1

~ $ bin/ejabberdctl --node ejabberd@cluster1 start
ERROR: The ejabberd node 'ejabberd@cluster1' is already running.

I have another trouble now. I set the name of the container node, and I went into the container to query the node status and told me that the node is nodedown. When I specify a node, it prompts me that the node is already running in the execution state. Please tell me. what should be done

badlop commented 12 months ago

I have another trouble now.

And did you solve the previous problem?

skrleo commented 12 months ago

And did you solve the previous problem?

Not yet, but there are some clues. need to set up hosts, but I need to solve this problem before you can deal with the following problems. clues case

badlop commented 12 months ago

Ok, I have that same problem when using your first example docker-compose.yml, because the variable ERLANG_NODE_ARG=ejabberd@192.168.10.1 does not match the hostname of the container where it is running.

One solution is to put in that variable the IP that the container will get.

Another solution that works for me too is to set as container_name the hostname that I will use in the ejabberd node name. Try it:

  1. Write in the file docker-compose.yml this:

    version: '3.7'
    services:
    ejabberd:
    image: ejabberd/ecs
    container_name: cluster1
    ports:
      - "5222:5222"
      - "5269:5269"
      - "5280:5280"
      - "5443:5443"
    environment:
      - ERLANG_NODE_ARG=ejabberd@cluster1
      - ERLANG_COOKIE=dummycookie123
    restart: always
  2. Start the container:

    $ docker-compose up
  3. And in another window check that ejabberdctl works correctly:

    
    $ docker exec -it cluster1 bin/ejabberdctl status
    The node ejabberd@cluster1 is started with status: started
    ejabberd 23.4.0 is running in that node

$ docker exec -it cluster1 bin/ejabberdctl register someaccount localhost somepass User someaccount@localhost successfully registered

skrleo commented 12 months ago

First of all, thank you very much for your reply to me. I have a very serious problem now and need your help. Setting INET_DIST_INTERFACE parameter in ejabberdctl.cfg makes ejabberd crash Edit the file ejabberd-23.04/bin/ejabberdctl. In line 80 it says:

INET_DIST_INTERFACE2=$("$ERL" -noshell ...

Add $ERLANG_OPTS. That variable includes arguments to tell erlang where to find the bootfile. For example:

INET_DIST_INTERFACE2=$("$ERL" $ERLANG_OPTS -noshell ...

I followed this method, but the error still occurred

~ $ bin/ejabberdctl reload_config
init terminating in do_boot (cannot expand $RELEASE_LIB in bootfile)

Crash dump is being written to: erl_crash.dump...done
{"could not start kernel pid",application_controller,"{bad_environment_value,\"{\\"init\"}"}
=ERROR REPORT==== 15-Sep-2023::01:03:31.349530 ===
application_controller: unterminated string starting with "init": {"init

could not start kernel pid (application_controller) ({bad_environment_value,"{\"init"})

Crash dump is being written to: /home/ejabberd/logs/erl_crash_20230915-010329.dump...done

What I want to add is that I use this solution to build the container. Thank you again for your generous answer.

badlop commented 12 months ago

Aha. The problem in ejabberdctl that you try to fix manually, was already solved in git. If you use the ejabberd container image instead of the docker/ejabberd/ecs image, you can use the most recent code, and you don't need to fix ejabberdctl yourself.

For example, to use the most recent ejabberd:master image:

version: '3.7'
services:
  ejabberd:
    image: ghcr.io/processone/ejabberd:master
    container_name: cluster1
    ports:
      - "5222:5222"
      - "5269:5269"
      - "5280:5280"
      - "5443:5443"
    environment:
      - ERLANG_NODE_ARG=ejabberd@cluster1
      - ERLANG_COOKIE=dummycookie123
    restart: always

This container image has a few differences, usually they are improvements. In your case, please notice that to use it, oyu may need to change a few path in your configuration files:

For example, with that container, ejabberdctl is used like this:

$ docker exec -it cluster1 ejabberdctl status
The node ejabberd@cluster1 is started with status: started
ejabberd 23.4.102 is running in that node
skrleo commented 12 months ago

ghcr.io/processone/ejabberd:master

May I ask which version of the code this container is? Because I have made some basic changes on the original basis, I can only build the container myself. My version is 23.04

badlop commented 12 months ago

That container is built based in ejabberd git master for every commit. If you have a branch in your local git with your customizations, you can build the image yourself, as explained in CONTAINER.md Direct build

skrleo commented 12 months ago

That container is built based in ejabberd git master for every commit. If you have a branch in your local git with your customizations, you can build the image yourself, as explained in CONTAINER.md Direct build

Thank you very much for your reply, you solved a big problem for me.

skrleo commented 12 months ago

ghcr.io/processone/ejabberd:master

Setting INET_DIST_INTERFACE parameter in ejabberdctl.cfg makes ejabberd crash

~ $ ejabberdctl reload_config
Protocol 'inet_tcp': register/listen error: eaddrnotavail
badlop commented 12 months ago

Address not available... maybe you configured ejabberd to use an IP address that does not exist in the machine, or that it is already being used by another program, maybe a running container?

badlop commented 6 months ago

Hi @skrleo , I guess by now you already found a solution or a workaround, right?

skrleo commented 6 months ago

Yes thank you very much for your help and wish you a happy life @badlop

你好@skrleo,我想现在您已经找到了解决方案或解决方法,对吧?