MongoDB用の開発環境が欲しくて余ってるRaspberry Pi 3を使って作ってみた。
目次
環境
今回の環境です。
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.2 LTS
Release: 22.04
Codename: jammy
前準備
パッケージ最新化
パッケージを最新化しておきます。
sudo apt update
sudo apt upgrade
MongoDBインストールしていないか確認
dpkg -l | grep mongo
インストールしていた場合は削除。
sudo apt purge mongo*
MongoDBをインストール
最新は6ですが、RaspberryPiのCPUにAVX命令がないので使用できません。
なので、4.4をインストールします。
4.4でも4.4.19はAVX対応になっているため、インストールして実行すると
Illegal instruction (core dumped)
というエラーメッセージが出て起動しません。
4.4.18をインストールしましょう。
GPG keyをインストール
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
aptソースリスト追加
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
apt更新
sudo apt update
インストール
4.4.18を指定してインストールする。
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
Ubuntu20.04はそのままインストール出来るが、Ubuntu22.04ではlibsslのバージョンが3になっていてインストール出来ない。
$ 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.
$ dpkg -l | grep libssl
ii libssl3:arm64 3.0.2-0ubuntu1.8 arm64 Secure Sockets Layer toolkit - shared libraries
パッケージの依存を解消
良いやり方ではないですがリポジトリにはlibssl1.1.1があるので、ダウンロードしてインストールする。
wget http://ports.ubuntu.com/ubuntu-ports/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.18_arm64.deb
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2.17_arm64.deb
再度、インストールする。
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
確認とサービスの起動
バージョン確認
$ 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"
}
}
サービスの起動
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: 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
ログ/var/log/mongodb/mongod.log
を見てみる。
{"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"}}
パーミッションがダメ。/tmp/mongodb-27017.sock
の所有者がmongodbになっていなかったので変更する。
sudo chown mongodb. /tmp/mongodb-27017.sock
再度、サービスを起動する。
$ 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.
後片付け
MongoDBをインストールしたソースリストは不要になるので削除します。
sudo rm /etc/apt/sources.list.d/mongodb-org-4.4.list
コメントを残す