9
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UbuntuにMosquittoをインストールしてMQTTブローカーを構築

Last updated at Posted at 2015-12-18

Ubuntu 14.04上でMosquittoをインストールしてMQTTブローカー(サーバ)を自前で構築してみます。

Mosquitto
http://mosquitto.org/

#パッケージリストにリポジトリを追加

kyoro@iot:~$ sudo add-apt-repository ppa:mosquitto-dev/mosquitto-ppa
[sudo] password for kyoro:

More info: https://launchpad.net/~mosquitto-dev/+archive/ubuntu/mosquitto-ppa
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpmtjlhsxh/secring.gpg' created
gpg: keyring `/tmp/tmpmtjlhsxh/pubring.gpg' created
gpg: requesting key 262C4500 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpmtjlhsxh/trustdb.gpg: trustdb created
gpg: key 262C4500: public key "Launchpad mosquitto" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK

#パッケージリストの更新

kyoro@iot:~$ sudo apt-get update

#クライアントの導入

sudo apt-get install mosquitto-clients

#ブローカー(サーバ)の導入

sudo apt-get install mosquitto

Mosquitto導入完了!

#接続テスト

##クライアントでtestを購読

kyoro@iot:~$ mosquitto_sub -d -t test
Client mosqsub/12779-iot sending CONNECT
Client mosqsub/12779-iot received CONNACK
Client mosqsub/12779-iot sending SUBSCRIBE (Mid: 1, Topic: test, QoS: 0)
Client mosqsub/12779-iot received SUBACK
Subscribed (mid: 1): 0

##ターミナルを別に開いてメッセージをpublish

kyoro@iot:~$ mosquitto_pub -d -t test -m "Hello world!"
Client mosqpub/12852-iot sending CONNECT
Client mosqpub/12852-iot received CONNACK
Client mosqpub/12852-iot sending PUBLISH (d0, q0, r0, m1, 'test', ... (12 bytes))
Client mosqpub/12852-iot sending DISCONNECT

##クライアント側で受信されます

Client mosqsub/12779-iot received PUBLISH (d0, q0, r0, m0, 'test', ... (12 bytes))
Hello world!

これでMQTTブローカーの出来上がりです!
再起動時にもサービスが自動で立ち上がるようになっているので、serviceコマンドでよしなに運用してください。

9
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?