Setting up MQTT Mosquitto broker in Ubuntu Linux - HelloMorningStar/HomeAssistant GitHub Wiki

try these, it's ok run on raspberry pi 2b with ubuntu 18.04

Prerequisites

Open port TCP:1883 on firewall

Install Mosquitto Broker

sudo apt-get update
sudo apt-get install mosquitto

Install the Clients and Test

sudo apt-get install mosquitto-clients

Secure with a Password

sudo mosquitto_passwd -c /etc/mosquitto/passwd mqtt_user_name
Password: mqtt_password

Create a configuration file for Mosquitto pointing to the password file we have just created.

sudo nano /etc/mosquitto/conf.d/default.conf
allow_anonymous false
password_file /etc/mosquitto/passwd

Final

sudo systemctl restart mosquitto