Ubuntu 22.04にMongoDB5.0.8をインストールする

環境
OSバージョンの確認

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"
# cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=22.04 DISTRIB_CODENAME=jammy DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"

MongoDBのインストール
1.MongoDB APTリポジトリ署名キーを追加します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
# sudo wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add - Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). OK
# sudo wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK

2.MongoDB APTリポジトリをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse
# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse
# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse

3.システムのアップデートを行います

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo apt update
# sudo apt update
# sudo apt update

4.libssl1.1をインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# echo "deb http://security.ubuntu.com/ubuntu impish-security main" | sudo tee /etc/apt/sources.list.d/impish-security.list
deb http://security.ubuntu.com/ubuntu impish-security main
# sudo apt-get update
# sudo apt-get install libssl1.1
# echo "deb http://security.ubuntu.com/ubuntu impish-security main" | sudo tee /etc/apt/sources.list.d/impish-security.list deb http://security.ubuntu.com/ubuntu impish-security main # sudo apt-get update # sudo apt-get install libssl1.1
# echo "deb http://security.ubuntu.com/ubuntu impish-security main" | sudo tee /etc/apt/sources.list.d/impish-security.list
deb http://security.ubuntu.com/ubuntu impish-security main
# sudo apt-get update
# sudo apt-get install libssl1.1

5.MongoDBをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo apt install -y mongodb-org
# sudo apt install -y mongodb-org
# sudo apt install -y mongodb-org

6.MongoDBの自動起動を設定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo systemctl enable mongod
Created symlink /etc/systemd/system/multi-user.target.wants/mongod.service → /lib/systemd/system/mongod.service.
# sudo systemctl enable mongod Created symlink /etc/systemd/system/multi-user.target.wants/mongod.service → /lib/systemd/system/mongod.service.
# sudo systemctl enable mongod
Created symlink /etc/systemd/system/multi-user.target.wants/mongod.service → /lib/systemd/system/mongod.service.

7.MongoDBの起動、停止
MongoDBの起動

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo systemctl start mongod
# sudo systemctl start mongod
# sudo systemctl start mongod

MongoDBの停止

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo systemctl stop mongod
# sudo systemctl stop mongod
# sudo systemctl stop mongod

ステータスを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-04-29 12:07:33 JST; 1s ago
# sudo systemctl status mongod ● mongod.service - MongoDB Database Server Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-04-29 12:07:33 JST; 1s ago
# sudo systemctl status mongod
● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-29 12:07:33 JST; 1s ago

8.MongoDBに接続します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# mongo
MongoDB shell version v5.0.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
> use admin
switched to db admin
# mongo MongoDB shell version v5.0.8 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb 略 > use admin switched to db admin
# mongo
MongoDB shell version v5.0.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
略
> use admin
switched to db admin

MongoDBのバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
> db.version()
5.0.8
> db.version() 5.0.8
> db.version()
5.0.8

 

Ubuntu 22.04

Posted by arkgame