LoginSignup
2
2

More than 3 years have passed since last update.

Raspberry4(Ubuntu21.04)にMongoDB4.4導入

Last updated at Posted at 2021-05-16

MongoDB4.4 インストール

MongoDBは標準パッケージにはないのでMongoDBの公式リポジトリを追加する

作業はThe MongoDB 4.4 Manualを読みながら進めるといい。

  • 公開鍵の登録
$ wget -O - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
  • ソースリストへ追加
$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
  • パッケージの再読み込み
$ sudo apt-get update

正しくできていると、MongoDBが追加されてるのが確認できる。
image.png

  1. パッケージインストール
$ sudo apt-get install mongodb-org
  • インストール確認
$ mongo -version

以下のように表示されていれば正しくインストールできてる
image.png

  • 自動起動追加
$ sudo systemctl enable mongod
  • MongoDB起動、状態確認
$ sudo systemctl start mongod
$ sudo systemctl status mongod

動作していれば以下のようになっている。
image.png

外部接続許可

Raspberry4だけで完結するだけならここまででよいが、リモートからもアクセスしたりしたいので設定を変えて外部からアクセスできるするために /etc/mongod.conf を編集する。

設定できるのは、127.0.0.10.0.0.0のみみたいで、ほかのアドレスいれて、やってみたらエラーがでた。これは公式マニュアルの Configuration File Optionsの net.bindIp の項に書いてある。

 5月 15 19:08:30 raspberrypi4 systemd[1]: Started MongoDB Database Server.
 5月 15 19:08:30 raspberrypi4 systemd[1]: mongod.service: Main process exited, code=exited, status=48/n/a
 5月 15 19:08:30 raspberrypi4 systemd[1]: mongod.service: Failed with result 'exit-code'.

自分で使う分には何も問題ないので、0.0.0.0で設定しておく

/etc/mongod.conf
# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0
2
2
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
2
2