processone / docker-ejabberd

Set of ejabberd Docker images
95 stars 77 forks source link

Docker-compose, ejabberd with mysql #69

Closed juancar0505 closed 3 years ago

juancar0505 commented 3 years ago

Im trying to use mysql database on ejabberd with docker-compose.

My configuration file is this:

``` > ### > ### ejabberd configuration file > ### > ### The parameters used in this configuration file are explained at > ### > ### https://docs.ejabberd.im/admin/configuration > ### > ### The configuration file is written in YAML. > ### ******************************************************* > ### ******* !!! WARNING !!! ******* > ### ******* YAML IS INDENTATION SENSITIVE ******* > ### ******* MAKE SURE YOU INDENT SECTIONS CORRECTLY ******* > ### ******************************************************* > ### Refer to http://en.wikipedia.org/wiki/YAML for the brief description. > ### > > hosts: > - localhost > - sespa > > > loglevel: 4 > log_rotate_size: 10485760 > log_rotate_date: "" > log_rotate_count: 1 > log_rate_limit: 100 > > certfiles: > - /home/ejabberd/conf/server.pem > > ca_file: "/home/ejabberd/conf/cacert.pem" > > ## When using let's encrypt to generate certificates > ##certfiles: > ## - /etc/letsencrypt/live/localhost/fullchain.pem > ## - /etc/letsencrypt/live/localhost/privkey.pem > ## > ##ca_file: "/etc/letsencrypt/live/localhost/fullchain.pem" > > listen: > - > port: 5222 > ip: "::" > module: ejabberd_c2s > max_stanza_size: 262144 > shaper: c2s_shaper > access: c2s > starttls_required: true > - > port: 5269 > ip: "::" > module: ejabberd_s2s_in > max_stanza_size: 524288 > - > module: ejabberd_http > port: 5443 > tls: true > certfile: "/etc/ejabberd/example.com.pem" > request_handlers: > "": mod_http_upload > > - > port: 5280 > ip: "::" > module: ejabberd_http > request_handlers: > "/admin": ejabberd_web_admin > "/bosh": mod_bosh > "/ws": ejabberd_http_ws > > > - > port: 5281 > ip: "::" > module: ejabberd_http > request_handlers: > "/api": mod_http_api > "/oauth": ejabberd_oauth > > > - > port: 1883 > ip: "::" > module: mod_mqtt > backlog: 1000 > > ## > ## https://docs.ejabberd.im/admin/configuration/#stun-and-turn > ## ejabberd_stun: Handles STUN Binding requests > ## > ##- > ## port: 3478 > ## ip: "0.0.0.0" > ## transport: udp > ## module: ejabberd_stun > ## use_turn: true > ## turn_ip: "{{ IP }}" > ## auth_type: user > ## auth_realm: "example.com" > ##- > ## port: 3478 > ## ip: "0.0.0.0" > ## module: ejabberd_stun > ## use_turn: true > ## turn_ip: "{{ IP }}" > ## auth_type: user > ## auth_realm: "example.com" > ##- > ## port: 5349 > ## ip: "0.0.0.0" > ## module: ejabberd_stun > ## certfile: "/home/ejabberd/conf/server.pem" > ## tls: true > ## use_turn: true > ## turn_ip: "{{ IP }}" > ## auth_type: user > ## auth_realm: "example.com" > ## > ## https://docs.ejabberd.im/admin/configuration/#sip > ## To handle SIP (VOIP) requests: > ## > ##- > ## port: 5060 > ## ip: "0.0.0.0" > ## transport: udp > ## module: ejabberd_sip > ##- > ## port: 5060 > ## ip: "0.0.0.0" > ## module: ejabberd_sip > ##- > ## port: 5061 > ## ip: "0.0.0.0" > ## module: ejabberd_sip > ## tls: true > > s2s_use_starttls: optional > > > > default_db: sql > > sql_type: mysql > sql_server: "localhost" > sql_database: "EJABBERD_DB" > sql_username: "root" > sql_password: "root" > ## If you want to specify the port: > sql_port: 3306 > > acl: > local: > user_regexp: "" > loopback: > ip: > - "127.0.0.0/8" > - "::1/128" > - "::FFFF:127.0.0.1/128" > admin: > user: > - "admin@localhost" > > access: # add following lines in access section > soft_upload_quota: > all: 1000 # MiB > hard_upload_quota: > all: 1100 # MiB > > access_rules: > local: > allow: local > c2s: > deny: blocked > allow: all > announce: > allow: admin > configure: > allow: admin > muc_create: > allow: local > pubsub_createnode: > allow: local > trusted_network: > allow: loopback > > api_permissions: > "console commands": > from: > - ejabberd_ctl > who: all > what: "*" > "admin access": > who: > access: > allow: > acl: admin > oauth: > scope: "ejabberd:admin" > access: > allow: > acl: admin > what: > - "*" > - "!stop" > - "!start" > "public commands": > who: > - all > what: all > > > > commands_admin_access: > - allow: > - user: "admin@localhost" > commands: > - add_commands: [user, admin, open] > # Tokens are valid for a year as default: > oauth_expire: 31536000 > oauth_access: all > > shaper: > normal: 1000 > fast: 50000 > > shaper_rules: > max_user_sessions: 10 > max_user_offline_messages: > 5000: admin > 100: all > c2s_shaper: > none: admin > normal: all > s2s_shaper: fast > > max_fsm_queue: 10000 > > acme: > contact: "mailto:example-admin@example.com" > ca_url: "https://acme-v01.api.letsencrypt.org" > > modules: > mod_adhoc: {} > mod_admin_extra: {} > mod_announce: > access: announce > mod_avatar: {} > mod_blocking: {} > mod_bosh: {} > mod_caps: {} > mod_carboncopy: {} > mod_client_state: {} > mod_configure: {} > mod_disco: {} > mod_fail2ban: {} > mod_http_api: {} > mod_http_upload: > docroot: "/home/ejabberd/upload" > put_url: "http://@HOST@:5443" > mod_last: {} > mod_mam: > ## Mnesia is limited to 2GB, better to use an SQL backend > ## For small servers SQLite is a good fit and is very easy > ## to configure. Uncomment this when you have SQL configured: > ## db_type: sql > assume_mam_usage: true > default: always > > mod_mqtt: {} > mod_muc: > host: "conference.@HOST@" > access: > - allow > access_admin: > - allow: admin > access_create: muc_create > access_persistent: muc_create > access_mam: > - allow > default_room_options: > allow_subscription: true # enable MucSub > mam: false > > > mod_muc_admin: {} > mod_offline: > access_max_user_messages: max_user_offline_messages > mod_ping: {} > mod_privacy: {} > mod_private: {} > mod_proxy65: > access: local > max_connections: 5 > mod_pubsub: > access_createnode: pubsub_createnode > plugins: > - flat > - pep > force_node_config: > ## Avoid buggy clients to make their bookmarks public > storage:bookmarks: > access_model: whitelist > mod_push: {} > mod_push_keepalive: {} > mod_register: > ## Only accept registration requests from the "trusted" > ## network (see access_rules section above). > ## Think twice before enabling registration from any > ## address. See the Jabber SPAM Manifesto for details: > ## https://github.com/ge0rg/jabber-spam-fighting-manifesto > ip_access: trusted_network > mod_roster: > versioning: true > mod_sip: {} > mod_s2s_dialback: {} > mod_shared_roster: {} > > > mod_stream_mgmt: > resend_on_timeout: if_offline > mod_vcard: {} > > mod_vcard_xupdate: {} > mod_version: > show_os: false > > ### Local Variables: > ### mode: yaml > ### End: > ### vim: set filetype=yaml tabstop=8 ``` And my docker-compose is this: ``` > version: '3' > > services: > db: > image: "mysql_ejabberd" > container_name: "mysql_ejabberd_container" > restart: "unless-stopped" > environment: > MYSQL_ROOT_PASSWORD: "root" > ports: > - "3306:3306" > # volumes: > #preparar esto para que la BD se guardeFUERA del contenedor (ahora esta genial dentro) > > > xmpp-ejabberd: > image: "ejabberd/ecs" > container_name: "ejabberd_mysql_container" > restart: "unless-stopped" > ports: > - "5222:5222" > - "5269:5269" > - "5280:5280" > - "5281:5281" > depends_on: > - db > volumes: > - Path/conf:/home/ejabberd/conf > - Path/data:/home/ejabberd/database > - Path/logs:/home/ejabberd/logs > - Path/upload:/home/ejabberd/upload > ```

I clarify that my dockerfile from the mysql_ejabberd image is the following, only create the database of ejabberd:

> FROM ejabberd/ecs
> 
> #Añade nuestro fichero conf
> ADD --chown=ejabberd:ejabberd resources/conf/ejabberd.yml /home/ejabberd/conf/ejabberd.yml
> 
> When i docker-compose up i have this problem:
> 
> Failed connecting to "localhost":3306 : {error,
> ejabberd_mysql_container | "connect failed: connection refused"}
> ejabberd_mysql_container | 2021-05-13 08:10:38.520597+00:00 [warning] mysql connection failed:
> ejabberd_mysql_container | ** Reason: connect_failed
> ejabberd_mysql_container | ** Retry after: 30 seconds
> 

I dont know if i need to add something on my .yml or dockerfile Can u someone help me pls?

badlop commented 3 years ago

I haven't checked your files, because I prefer mi solution. I have a way to setup ejabberd, mysql, create the database, fill with example accounts, and setup MySQL web administration service. Try my example, and adapt it to your needs.

  1. Create a new docker-compose.yml with this content:
```yaml version: '3.7' volumes: main_conf: name: main_conf main_logs: name: main_logs main_data: name: main_data main_uplo: name: main_uplo mysql_data: name: mysql_data services: main: hostname: main container_name: main image: ejabberd/ecs:latest depends_on: mysql: condition: service_healthy environment: - CTL_ON_CREATE=register admin localhost asd ; register user1my mysql.localhost asd - CTL_ON_START=stats registeredusers ; status command: ["foreground"] healthcheck: test: netstat -nl | grep -q 5222 start_period: 5s interval: 5s timeout: 5s retries: 120 ports: - "5222:5222" - "5269:5269" - "5280:5280" - "5443:5443" volumes: - main_conf:/home/ejabberd/conf - main_data:/home/ejabberd/database - main_logs:/home/ejabberd/logs - main_uplo:/home/ejabberd/upload - ./ejabberd.yml:/home/ejabberd/conf/ejabberd.yml:ro mysql: image: mysql:latest container_name: mysql volumes: - mysql_data:/var/lib/mysql - ./mysql.sql:/docker-entrypoint-initdb.d/mysql.sql:ro command: --default-authentication-plugin=mysql_native_password restart: always healthcheck: test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD interval: 10s retries: 120 environment: MYSQL_ROOT_PASSWORD: example MYSQL_DATABASE: ejabberd_test MYSQL_USER: ejabberd_test MYSQL_PASSWORD: ejabberd_test adminer: image: adminer container_name: adminer restart: always depends_on: mysql: condition: service_healthy main: condition: service_healthy ports: - 8080:8080 ```
  1. Download ejabberd.yml and setup those lines at the beginning:
hosts:
  - localhost
  - mysql.localhost

host_config:
  mysql.localhost:
    sql_port: 3306
    sql_type: mysql
    sql_server: "mysql"
    sql_database: "ejabberd_test"
    sql_username: "ejabberd_test"
    sql_password: "ejabberd_test"
    sql_pool_size: 1
    auth_method: sql
    default_db: sql
  1. Download ejabberd's mysql.sql file, as it will be used to prepare the database.

  2. Start docker-compose. It takes several minutes to fully start MySQL, be patient

sudo docker-compose up
  1. After some minutes, the console will show this:
Creating network "ecs_default" with the default driver
Creating volume "main_conf" with default driver
Creating volume "main_logs" with default driver
Creating volume "main_data" with default driver
Creating volume "main_uplo" with default driver
Creating volume "mysql_data" with default driver
Creating mysql ... done
Creating main  ... done
Creating adminer ... done
Attaching to mysql, main, adminer
...
main       | 2021-05-13 10:23:54.208771+00:00 [info] ejabberd 21.4.0 is started in the node ejabberd@main in 11.25s
main       | 2021-05-13 10:23:54.215446+00:00 [info] Start accepting TCP connections at [::]:5269 for ejabberd_s2s_in
main       | 2021-05-13 10:23:54.216246+00:00 [info] Start accepting TLS connections at [::]:5443 for ejabberd_http
main       | 2021-05-13 10:23:54.216604+00:00 [info] Start accepting TCP connections at [::]:5280 for ejabberd_http
main       | 2021-05-13 10:23:54.217225+00:00 [info] Start accepting TCP connections at [::]:1883 for mod_mqtt
main       | 2021-05-13 10:23:54.217693+00:00 [info] Start accepting TCP connections at [::]:5222 for ejabberd_c2s
main       | 2021-05-13 10:23:54.218102+00:00 [warning] No HTTP listeners for ACME challenges are configured, automatic certificate requests are aborted. Hint: configure the listener and restart/reload ejabberd. Or set acme->auto option to `false` to suppress this warning.
main       | 2021-05-13 10:23:54.235688+00:00 [info] Start accepting TCP connections at 172.21.0.3:7777 for mod_proxy65_stream
main       | :> ejabberdctl register admin localhost asd
main       | User admin@localhost successfully registered
main       | :> ejabberdctl register user1my mysql.localhost asd
main       | User user1my@mysql.localhost successfully registered
main       | :> ejabberdctl stats registeredusers
main       | 2
main       | :> ejabberdctl status
main       | The node ejabberd@main is started with status: started
main       | ejabberd 21.4.0 is running in that node
  1. Now you can:
juancar0505 commented 3 years ago

I m trying to execute this but its appear this error ... I dowoload mysql.sql file and i have it in the same proyect. The files that i have in my proyect are ejabberd.yml, mysql.sql and docker-compose.yml. I need something more ?

ERROR: Named volume "mysql.sql:/docker-entrypoint-initdb.d:rw" is used in service "mysql" but no declaration was found in the volumes section.

badlop commented 3 years ago

ERROR: Named volume "mysql.sql:/docker-entrypoint-initdb.d:rw" is used in service "mysql" but no declaration was found in the volumes section.

Ah, right, instead of - mysql.sql it should be - ./mysql.sql

I've updated my example for mysql.sql and also for ejabberd.yml

The files that i have in my proyect are ejabberd.yml, mysql.sql and docker-compose.yml.

Right, those three files in the same directory, they should be enough.