MongoDB 最新バージョン 4.2 RC版を Amazon Linux 2 にインストールする

2019.06.30

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、菊池です。

先週開催されたMongoDB WORLD 2019では、MongoDBの新しい機能/サービスが多数発表されました。その中で、次期メジャーバージョンであるMongoDB 4.2のリリースも期待されていましたが、その時点ではベータとしての機能紹介にとどまりました。

 

現在、次期メジャーバージョンである4.2の製品候補版である、4.2RC(Release Candidates)が利用可能になっていますので、Amazon Linux 2にインストールしてみました。なお、公式ドキュメントにも記載の通り、RC版は評価目的でのみの利用とし、プロダクション環境での利用はしないようにしましょう。

MongoDB 4.2RCのインストール

MongoDB 4.2RCの入手は、ダウンロードセンターからパッケージのダウンロードの他、主要なLinuxディストリビューションではyumなどのパッケージマネージャでのインストールにも対応しています。

公式ドキュメントは、次期バージョン4.2についてもすでに参照可能です。

リポジトリの追加

まずはyumでインストールするために、/etc/yum.repos.d/mongodb-org-4.2.repo を作成します。なお、公式ドキュメントではディレクトリパスがrepo.mongodb.org/yum/amazon/2/mongodb-org/4.2/x86_64/と記載されていますが、現時点ではrepo.mongodb.org/yum/amazon/2/mongodb-org/testing/x86_64/となることにご注意ください。

$ cat /etc/yum.repos.d/mongodb-org-4.2.repo
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/testing/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

インストールと起動

それではインストールです。

$ sudo yum install -y mongodb-org

設定を確認します。最低限、バインドIPを設定すれば利用可能です。

$ cat /etc/mongod.conf
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
# mongod.conf
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

起動してみます。

$ sudo systemctl start mongod
$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since 日 2019-06-30 00:27:59 UTC; 5s ago
     Docs: https://docs.mongodb.org/manual
  Process: 2686 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
  Process: 2683 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 2680 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 2678 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 2689 (mongod)
   CGroup: /system.slice/mongod.service
           └─2689 /usr/bin/mongod -f /etc/mongod.conf

 6月 30 00:27:58 ip-172-31-27-251.ap-northeast-1.compute.internal systemd[1]: Starting MongoDB Database Server...
 6月 30 00:27:58 ip-172-31-27-251.ap-northeast-1.compute.internal mongod[2686]: about to fork child process, waitin....
 6月 30 00:27:58 ip-172-31-27-251.ap-northeast-1.compute.internal mongod[2686]: forked process: 2689
 6月 30 00:27:59 ip-172-31-27-251.ap-northeast-1.compute.internal systemd[1]: Started MongoDB Database Server.
Hint: Some lines were ellipsized, use -l to show in full.

無事起動し、シェルで接続できました。

$ mongo localhost
MongoDB shell version v4.2.0-rc2
connecting to: mongodb://127.0.0.1:27017/localhost?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("86a98236-a413-47ab-a4cd-a0788fa9f699") }
MongoDB server version: 4.2.0-rc2
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
Server has startup warnings:
2019-06-30T00:27:59.687+0000 I  CONTROL  [initandlisten]
2019-06-30T00:27:59.687+0000 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-06-30T00:27:59.687+0000 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-06-30T00:27:59.687+0000 I  CONTROL  [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

>

さいごに

最新バージョンのリリース候補版である、MongoDB 4.2RCの利用準備ができました。これから新機能を検証していきたいと思います。