MongoDB用の開発環境が欲しくて余ってるRaspberry Pi 3を使って作ってみた。
目次
環境
今回の環境です。
Plaintext
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.2 LTS
Release: 22.04
Codename: jammy
Plaintext前準備
パッケージ最新化
パッケージを最新化しておきます。
ShellScript
sudo apt update
sudo apt upgrade
ShellScriptMongoDBインストールしていないか確認
ShellScript
dpkg -l | grep mongo
ShellScriptインストールしていた場合は削除。
ShellScript
sudo apt purge mongo*
ShellScriptMongoDBをインストール
最新は6ですが、RaspberryPiのCPUにAVX命令がないので使用できません。
なので、4.4をインストールします。
4.4でも4.4.19はAVX対応になっているため、インストールして実行すると
Illegal instruction (core dumped)
というエラーメッセージが出て起動しません。
4.4.18をインストールしましょう。
GPG keyをインストール
ShellScript
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
ShellScriptaptソースリスト追加
ShellScript
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
ShellScriptapt更新
ShellScript
sudo apt update
ShellScriptインストール
4.4.18を指定してインストールする。
ShellScript
sudo apt install mongodb-org=4.4.18 mongodb-org-shell=4.4.18 mongodb-org-server=4.4.18 mongodb-org-mongos=4.4.18 mongodb-org-database-tools-extra=4.4.18 mongodb-org-tools=4.4.18
ShellScriptUbuntu20.04はそのままインストール出来るが、Ubuntu22.04ではlibsslのバージョンが3になっていてインストール出来ない。
Plaintext
$ sudo apt install mongodb-org=4.4.18 mongodb-org-shell=4.4.18 mongodb-org-server=4.4.18 mongodb-org-mongos=4.4.18
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
mongodb-org-mongos : Depends: libssl1.1 (>= 1.1.0) but it is not installable
mongodb-org-server : Depends: libssl1.1 (>= 1.1.0) but it is not installable
mongodb-org-shell : Depends: libssl1.1 (>= 1.1.0) but it is not installable
E: Unable to correct problems, you have held broken packages.
PlaintextPlaintext
$ dpkg -l | grep libssl
ii libssl3:arm64 3.0.2-0ubuntu1.8 arm64 Secure Sockets Layer toolkit - shared libraries
Plaintextパッケージの依存を解消
良いやり方ではないですがリポジトリにはlibssl1.1.1があるので、ダウンロードしてインストールする。
ShellScript
wget http://ports.ubuntu.com/ubuntu-ports/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.19_arm64.deb
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2.17_arm64.deb
ShellScript再度、インストールする。
ShellScript
sudo apt install mongodb-org=4.4.18 mongodb-org-shell=4.4.18 mongodb-org-server=4.4.18 mongodb-org-mongos=4.4.18 mongodb-org-database-tools-extra=4.4.18 mongodb-org-tools=4.4.18
ShellScript確認とサービスの起動
バージョン確認
Plaintext
$ mongod --version
db version v4.4.18
Build Info: {
"version": "4.4.18",
"gitVersion": "8ed32b5c2c68ebe7f8ae2ebe8d23f36037a17dea",
"openSSLVersion": "OpenSSL 1.1.1f 31 Mar 2020",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu2004",
"distarch": "aarch64",
"target_arch": "aarch64"
}
}
Plaintextサービスの起動
ShellScript
sudo systemctl start mongod
ShellScriptサービスが起動しない
Plaintext
$ sudo systemctl status mongod
× mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2023-03-21 09:15:44 JST; 1s ago
Docs: https://docs.mongodb.org/manual
Process: 6095 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=14)
Main PID: 6095 (code=exited, status=14)
CPU: 270ms
Plaintextログ/var/log/mongodb/mongod.log
を見てみる。
Plaintext
{"t":{"$date":"2023-03-21T09:15:44.316+09:00"},"s":"E", "c":"NETWORK", "id":23024, "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Operation not permitted"}}
Plaintextパーミッションがダメ。/tmp/mongodb-27017.sock
の所有者がmongodbになっていなかったので変更する。
ShellScript
sudo chown mongodb. /tmp/mongodb-27017.sock
ShellScript再度、サービスを起動する。
Plaintext
$ sudo systemctl start mongod
$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2023-03-21 09:25:34 JST; 1s ago
Docs: https://docs.mongodb.org/manual
Main PID: 6169 (mongod)
Memory: 12.5M
CPU: 1.892s
CGroup: /system.slice/mongod.service
└─6169 /usr/bin/mongod --config /etc/mongod.conf
Mar 21 09:25:34 meimei systemd[1]: Started MongoDB Database Server.
Plaintext後片付け
MongoDBをインストールしたソースリストは不要になるので削除します。
ShellScript
sudo rm /etc/apt/sources.list.d/mongodb-org-4.4.list
ShellScript
助かりました。
オフィシャルサイトの説明を読んでも、
https://www.mongodb.com/developer/products/mongodb/mongodb-on-raspberry-pi/
バージョン4.4を入れろとしか書いていなく、Ubuntu22.04ではエラーが発生して途方に暮れていましたが、ここの説明で4.4.18を指定すれば良いことがわかり、無事にインストールできました。オフィシャルの説明は、Ubuntu20.04に対応したものなので、はやく更新してほしいです。
はーべすたーしゃの説明のお陰で、時間を無駄に浪費せずにすみました。ありがとうございました。