Hivemq community edition installation in ubuntu using AWS EC2 instance

Hello @sanjmeh

What do you see in hivemq logs? It is located at hivemq-<ce version>/logs/ Can you share your hivemq.log?

Kind regards,
Sheetal from HiveMQ team

Oh yes… so I see there are 3 log files. First I am giving you the tail of the hivemq.2022-04-20.log , which is what I guess you are asking:

root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq/log# tail hivemq.2022-04-20.log 
# You can download security extensions from the HiveMQ Marketplace (https://www.hivemq.com/extensions/).       #
################################################################################################################
2022-04-20 07:29:09,019 INFO  - Extension "Allow All Extension" version 1.0.0 started successfully.
2022-04-20 07:29:09,083 INFO  - Starting TCP listener on address 0.0.0.0 and port 1883
2022-04-20 07:29:09,152 INFO  - Started TCP Listener on address 0.0.0.0 and on port 1883
2022-04-20 07:29:09,152 INFO  - Started HiveMQ in 4206ms
2022-04-20 12:44:31,577 INFO  - Shutting down HiveMQ. Please wait, this could take a while...
2022-04-20 12:44:33,604 INFO  - Shutting down extension system
2022-04-20 12:44:33,606 INFO  - Extension "Allow All Extension" version 1.0.0 stopped successfully.
2022-04-20 12:44:36,020 INFO  - Shutdown completed.

And here is the tail of the event.log file.

2022-04-20 08:14:49,190 - Client ID: MqttClient session has expired at 2022-04-20 08:03:33. All persistent data for this client has been removed.
2022-04-23 06:32:12,110 - Client ID: UNKNOWN, IP: 49.205.128.126 was disconnected. reason: Sent other message before CONNECT.
2022-04-23 06:32:13,146 - Client ID: UNKNOWN, IP: 49.205.128.126 was disconnected. reason: Sent other message before CONNECT.
2022-04-23 06:32:13,150 - Client ID: UNKNOWN, IP: 49.205.128.126 was disconnected. reason: Sent other message before CONNECT.
2022-04-23 06:32:13,157 - Client ID: UNKNOWN, IP: 49.205.128.126 was disconnected. reason: Sent other message before CONNECT.
2022-04-23 06:37:47,852 - Client ID: UNKNOWN, IP: 49.205.128.126 was disconnected. reason: Sent other message before CONNECT.
2022-04-23 09:42:43,103 - Client ID: macmini, IP: 49.205.128.126, Clean Start: true, Session Expiry: 0 connected.
2022-04-23 09:49:56,094 - Client ID: macmin2, IP: 49.205.128.126, Clean Start: true, Session Expiry: 0 connected.
2022-04-23 10:19:16,799 - Client ID: macmini, IP: 49.205.128.126 disconnected ungracefully.
2022-04-23 10:19:16,800 - Client ID: macmin2, IP: 49.205.128.126 disconnected ungracefully.
root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq/log# 

As you see the MQTT broker was connected from my local macmini successfully when I tried using the hivemq CLI… but in the end the broker stopped because I guess it ran on the shell (./bin/run.bat) and when it got aborted (shell command) the server stopped working. I am unable to get the hivemq broker daemon up. Seems a trivial problem, about to be solved…if you help. I may have mixed up the daemon commands.

Thanks a lot for responsing fast.

By the way if you want to see the migration log here is the tail of the log:

root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq/log# tail migration.log 
2022-04-20 07:29:07,739 INFO  - Finished migration.
2022-04-23 06:29:46,840 INFO  - Checking for migrations (HiveMQ version 2021.3).
2022-04-23 06:29:46,858 INFO  - Read metadata file: MetaInformation{hivemqVersion='2021.3', clientSessionPersistenceVersion='040000', queuedMessagesPersistenceVersion='040500', subscriptionPersistenceVersion='040000', retainedMessagesPersistenceVersion='040500_R', publishPayloadPersistenceVersion='040500_R', retainedMessagesPersistenceType='FILE_NATIVE', publishPayloadPersistenceType='FILE_NATIVE'}
2022-04-23 06:29:46,912 INFO  - Nothing to migrate found.
2022-04-23 06:29:46,912 INFO  - Checking for value migrations (HiveMQ version 2021.3).
2022-04-23 06:29:46,912 INFO  - Read metadata file: MetaInformation{hivemqVersion='2021.3', clientSessionPersistenceVersion='040000', queuedMessagesPersistenceVersion='040500', subscriptionPersistenceVersion='040000', retainedMessagesPersistenceVersion='040500_R', publishPayloadPersistenceVersion='040500_R', retainedMessagesPersistenceType='FILE_NATIVE', publishPayloadPersistenceType='FILE_NATIVE'}
2022-04-23 06:29:46,913 INFO  - Nothing to migrate found.
2022-04-23 06:29:49,343 INFO  - Read metadata file: MetaInformation{hivemqVersion='2021.3', clientSessionPersistenceVersion='040000', queuedMessagesPersistenceVersion='040500', subscriptionPersistenceVersion='040000', retainedMessagesPersistenceVersion='040500_R', publishPayloadPersistenceVersion='040500_R', retainedMessagesPersistenceType='FILE_NATIVE', publishPayloadPersistenceType='FILE_NATIVE'}
2022-04-23 06:29:49,344 INFO  - Write metadata file: MetaInformation{hivemqVersion='2021.3', clientSessionPersistenceVersion='040000', queuedMessagesPersistenceVersion='040500', subscriptionPersistenceVersion='040000', retainedMessagesPersistenceVersion='040500_R', publishPayloadPersistenceVersion='040500_R', retainedMessagesPersistenceType='FILE_NATIVE', publishPayloadPersistenceType='FILE_NATIVE'}
2022-04-23 06:29:49,344 INFO  - Finished migration.
root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq/log# 

UPDATE:
Here is my attempt to start the hivemq as a daemon, and although it appears it started, it shows failed.

root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq# /etc/init.d/hivemq start
Starting hivemq (via systemctl): hivemq.service.
root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq# systemctl status hivemq
● hivemq.service - HiveMQ Community Edition
     Loaded: loaded (/etc/systemd/system/hivemq.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2022-04-25 08:47:59 UTC; 11s ago
    Process: 184896 ExecStart=/opt/hivemq/bin/run.sh (code=exited, status=200/CHDIR)
   Main PID: 184896 (code=exited, status=200/CHDIR)
root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq# netstat -an | grep 1883
root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq# # there is NO OUTPUT

@sanjmeh

Thanks for sharing the information. However, the logs shared by you are not recent ones. We would need the latest hivemq.log to check.

It is not clear why do you think ( ./bin/run.bat ) was run. What happens when you try to run HiveMQ manually by running ./bin/run.sh? Do you still observe the same behaviour?

Kind regards,
Sheetal

The HiveMQ starts on run.bat

root@ubuntu-s-1vcpu-1gb-blr1-01:~# /opt/hivemq/bin/run.sh 
-------------------------------------------------------------------------

                  _    _  _              __  __   ____
                 | |  | |(_)            |  \/  | / __ \ 
                 | |__| | _ __   __ ___ | \  / || |  | |
                 |  __  || |\ \ / // _ \| |\/| || |  | |
                 | |  | || | \ V /|  __/| |  | || |__| |
                 |_|  |_||_|  \_/  \___||_|  |_| \___\_\

-------------------------------------------------------------------------

  HiveMQ Start Script for Linux/Unix v1.13

-------------------------------------------------------------------------

  HIVEMQ_HOME: /opt/hivemq

  JAVA_OPTS:  -Djava.net.preferIPv4Stack=true --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED --add-exports java.base/jdk.internal.misc=ALL-UNNAMED -Djava.security.egd=file:/dev/./urandom -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -XX:+CrashOnOutOfMemoryError -XX:+HeapDumpOnOutOfMemoryError

  JAVA_VERSION: 11

-------------------------------------------------------------------------

2022-04-25 10:29:38,054 INFO  - Starting HiveMQ Community Edition Server
2022-04-25 10:29:38,061 INFO  - HiveMQ version: 2021.3
2022-04-25 10:29:38,061 INFO  - HiveMQ home directory: /opt/hivemq
2022-04-25 10:29:38,063 INFO  - Log Configuration was overridden by /opt/hivemq/conf/logback.xml
2022-04-25 10:29:38,631 INFO  - This HiveMQ ID is TSthY
2022-04-25 10:29:40,997 INFO  - Starting with file persistence mode.
2022-04-25 10:29:42,171 INFO  - Starting HiveMQ extension system.
2022-04-25 10:29:42,259 WARN  - 
################################################################################################################
# This HiveMQ deployment is not secure! You are lacking Authentication and Authorization.                      #
# Right now any MQTT client can connect to the broker with a full set of permissions.                          #
# For production usage, add an appropriate security extension and remove the hivemq-allow-all extension.       #
# You can download security extensions from the HiveMQ Marketplace (https://www.hivemq.com/extensions/).       #
################################################################################################################
2022-04-25 10:29:42,268 INFO  - Extension "Allow All Extension" version 1.0.0 started successfully.
2022-04-25 10:29:42,325 INFO  - Starting TCP listener on address 0.0.0.0 and port 1883
2022-04-25 10:29:42,400 INFO  - Started TCP Listener on address 0.0.0.0 and on port 1883
2022-04-25 10:29:42,401 INFO  - Started HiveMQ in 4352ms

And the log says:

root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq/log# tail hivemq.log
################################################################################################################
# This HiveMQ deployment is not secure! You are lacking Authentication and Authorization.                      #
# Right now any MQTT client can connect to the broker with a full set of permissions.                          #
# For production usage, add an appropriate security extension and remove the hivemq-allow-all extension.       #
# You can download security extensions from the HiveMQ Marketplace (https://www.hivemq.com/extensions/).       #
################################################################################################################
2022-04-25 10:29:42,268 INFO  - Extension "Allow All Extension" version 1.0.0 started successfully.
2022-04-25 10:29:42,325 INFO  - Starting TCP listener on address 0.0.0.0 and port 1883
2022-04-25 10:29:42,400 INFO  - Started TCP Listener on address 0.0.0.0 and on port 1883
2022-04-25 10:29:42,401 INFO  - Started HiveMQ in 4352ms

So all looks well.

However the daemon has not yet started.
Because when I check status using systemctl it gives code=exited, status=200/CHDIR error

root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq/log# systemctl status hivemq
● hivemq.service - HiveMQ Community Edition
     Loaded: loaded (/etc/systemd/system/hivemq.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2022-04-25 10:34:22 UTC; 51s ago
    Process: 187374 ExecStart=/opt/hivemq/bin/run.sh (code=exited, status=200/CHDIR)
   Main PID: 187374 (code=exited, status=200/CHDIR)
root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq/log# 

And when the shell is killed, the broker stops with following message:

022-04-25 10:37:23,709 INFO  - Shutting down HiveMQ. Please wait, this could take a while...
2022-04-25 10:37:25,733 INFO  - Shutting down extension system
2022-04-25 10:37:25,735 INFO  - Extension "Allow All Extension" version 1.0.0 stopped successfully.
2022-04-25 10:37:28,164 INFO  - Shutdown completed.
root@ubuntu-s-1vcpu-1gb-blr1-01:~# 

@SShet could you please see the above logs? I am under pressure to start the server by today midnight. Will it be possible for you to respond today? Thanks

Hi @sanjmeh ,

You have the following error in the output of systemctl status hivemq:

Please double-check that you set permissions accordingly, steps 5,6,7 from these instructions: https://github.com/hivemq/hivemq-community-edition/wiki/Installing-HiveMQ#installation-on-unix-based-systems-linux-bsd-macos-x-unix
Note, that you need to run those steps with sudo.

In the output of systemctl status hivemq you can see only a piece of the error log. Please check the whole error log with journalctl -u hivemq.service

Thanks,
Dasha from HiveMQ team

@sanjmeh , you logs above are incomplete.
In order to get whole error log after failed start of the service, please run journalctl -u hivemq.service.

Starting from above I am seeing the same errorr.

Few more things that may be useful for the diagnosis.
I am signed in as root and I have done all installations in the root.
I surely have create hivemq user and I did do a sudo chown for all files to hivemq.
This also means the directory of /opt/hivemq is a sym link into the /root

Here are the files as they look in my system under /opt

root@ubuntu-s-1vcpu-1gb-blr1-01:/opt# ls -lt
total 8
lrwxrwxrwx  1 hivemq           hivemq   22 Apr 20 08:13 hivemq -> /root/hivemq-ce-2021.3
drwxrwxr-x 10 hivemq           hivemq 4096 Mar 28 19:27 hivemq-community-edition
drwxr-xr-x  5 systemd-coredump root   4096 Mar 28 17:59 digitalocean

Inside the /opt/hivemq the files look like these:

root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq# ls -lt
total 28
drwxr-xr-x 2 hivemq hivemq 4096 Apr 25 10:29 log
drwxr-xr-x 3 hivemq hivemq 4096 Apr 20 08:20 conf
drwxr-xr-x 4 hivemq hivemq 4096 Apr 20 07:29 data
-rw-r--r-- 1 hivemq hivemq  760 Nov 19 14:23 README.txt
drwxr-xr-x 3 hivemq hivemq 4096 Nov 19 14:23 bin
drwxr-xr-x 3 hivemq hivemq 4096 Nov 19 14:23 extensions
drwxr-xr-x 2 hivemq hivemq 4096 Nov 19 14:23 third-party-licenses

No journal log found this time.

Last login: Mon May  2 12:47:56 2022 from 49.205.128.126
root@ubuntu-s-1vcpu-1gb-blr1-01:~# journalctl -u hivemq.service
No journal files were found.

As you may see the run.bat is successful every time I run it, and the hivemq broker works fine (tested it too) but only while the bat file is running. As soon as the shell program is killed the broker is killed. So the problem is I think in the daemon not starting.

I still get the same error while starting the server using daemon.

Active: failed (Result: exit-code) since Mon 2022-04-25 10:34:22 UTC; 1 weeks 0 days ago
   Main PID: 187374 (code=exited, status=200/CHDIR)

Update:
I suspect the home directory of the hivemq could be an issue. So I changed it to /opt/hivemq by usermod -d /opt/hivemq but when now I do su hivemq get a permission denied on .bashrc which does not even exist in /opt/hivemq.

root@ubuntu-s-1vcpu-1gb-blr1-01:/opt/hivemq# su hivemq
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

bash: /opt/hivemq/.bashrc: Permission denied

Seems I have messed up the directory structure. Shall I copy all hidden files from /home/hivemq to /opt/hivemq?

Hi @sanjmeh ,

It seems that you have not configured the service, because you are stuck with previous steps.

First make sure you have Java OpenJDK 11 installed.

You need to download the zip file and unzip it to the /opt directory:

sudo unzip hivemq-ce-<version>.zip -d /opt

– This should create a folder /opt/hivemq-ce-<version>.

Now, in the /opt directory you create symbolic link to /opt/hivemq-ce-<version>:

sudo ln -s /opt/hivemq-ce-<version> /opt/hivemq

– Now you have in the /opt directory both the hivemq folder and the symbolic link to it:

ls -la /opt
total 0
drwxr-xr-x   5 root  wheel  160 May  3 15:22 .
drwxr-xr-x  20 root  wheel  640 Mar 26 08:21 ..
lrwxr-xr-x   1 root  wheel   17 May  3 15:22 hivemq -> /opt/hivemq-4.7.1
drwxr-xr-x@ 13 root  wheel  416 Sep 28  2021 hivemq-4.7.1

Next add the hivemq user:

sudo useradd -d /opt/hivemq hivemq

Make scripts executable and change owner to hivemq user

sudo chown -R hivemq:hivemq /opt/hivemq-ce-<version> 
sudo chown -R hivemq:hivemq /opt/hivemq 
cd /opt/hivemq 
sudo chmod +x ./bin/run.sh

Check if your OS is using systemd to handle services, for example:

ps --no-headers -o comm 1

– Output :

# Running systemd
systemd
# Not running systemd
init

If you are on systemd, then your next step to create the service is For linux systems using systemd:

cp /opt/hivemq/bin/init-script/hivemq.service /etc/systemd/system/hivemq.service

Enabling the service:

systemctl enable hivemq

This is it. Once you reboot , your service should start. If it fails, you will find error logs in the journalctl -u hivemq.service and can share them with me.

Kind regards,
Dasha from HiveMQ team

I think the server is UP :right_anger_bubble:
Am testing it.

1 Like