質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
MongoDB

MongoDBはオープンソースのドキュメント指向データベースの1つです。高性能で、多くのリトルエンディアンシステムを利用することができます。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

Q&A

解決済

1回答

2898閲覧

MongoDBの設定ファイルを編集後、restartができない。

takaoS

総合スコア9

MongoDB

MongoDBはオープンソースのドキュメント指向データベースの1つです。高性能で、多くのリトルエンディアンシステムを利用することができます。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

0グッド

0クリップ

投稿2020/06/16 06:56

編集2020/06/16 07:51

前提・実現したいこと

Amazon Linux 2のEC2にMongoDBをインストールし、ローカルマシンにインストールしたMongoDB CompassからアクセスしてCRUD操作がしたいです。

そのために、/etc/mongod.confを編集して、localhost以外からのアクセスを許可したいです。

MongoDBをインストールするEC2は、デフォルトで用意されているVPC領域のパブリックサブネット上に構築しました。

そのインスタンスに、以下のURLを参考にMongoDBをインストールし、起動しました。
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-amazon/

以下にバージョン情報を記します。

EC2のOS:Amazon Linux 2
MongoDBのバージョン:MongoDB 4.2 Community Edition
Compassのバージョン:1.12.2
Mac OS:MacOS Catalina 10.15.5

発生している問題・エラーメッセージ

ローカルからEC2のMongoDBへのアクセスを許可するために、EC2にログインし、以下のように/etc/mongod.confを編集しました。

// 編集前 # 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.
// 編集後 # network interfaces net: port: 27017 bindIp: 0.0.0.0,:: # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

その後、設定を反映させるためにrestartをしようとすると、以下のようなエラーが出て実行されません。

[ec2-user@ip-hogehoge etc]$ sudo service mongod restart Redirecting to /bin/systemctl restart mongod.service Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.

言われた通りにstatusを実行してみると、以下のような結果が表示されます。

[ec2-user@ip-hogehoge etc]$ sudo systemctl status mongod.service ● mongod.service - MongoDB Database Server Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since 火 2020-06-16 06:36:39 UTC; 14s ago Docs: https://docs.mongodb.org/manual Process: 6622 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=2) Process: 6619 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 6616 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 6614 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS) Main PID: 6559 (code=exited, status=0/SUCCESS) 6月 16 06:36:39 ip-hogehoge.ap-northeast-1.compute.internal systemd[1]: Starting MongoDB Database Server... 6月 16 06:36:39 ip-hogehoge.ap-northeast-1.compute.internal mongod[6622]: Error parsing YAML config file: yaml-cpp: error at line 29, ...alue 6月 16 06:36:39 ip-hogehoge.ap-northeast-1.compute.internal mongod[6622]: try '/usr/bin/mongod --help' for more information 6月 16 06:36:39 ip-hogehoge.ap-northeast-1.compute.internal systemd[1]: mongod.service: control process exited, code=exited status=2 6月 16 06:36:39 ip-hogehoge..ap-northeast-1.compute.internal systemd[1]: Failed to start MongoDB Database Server. 6月 16 06:36:39 ip-hogehoge.ap-northeast-1.compute.internal systemd[1]: Unit mongod.service entered failed state. 6月 16 06:36:39 ip-hogehoge.ap-northeast-1.compute.internal systemd[1]: mongod.service failed. Hint: Some lines were ellipsized, use -l to show in full.

この結果の上から5行目が、

Process: 6622 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=2)

となっており、これが原因で

6月 16 06:36:39 ip-hogehoge..ap-northeast-1.compute.internal systemd[1]: Failed to start MongoDB Database Server.

となるのではないかと推測し調べてみたところ、以下のサイトを見つけました。
https://stackoverflow.com/questions/43589290/mongo-service-start-or-restart-always-fail/48122382

これの通りに、以下のように編集し、

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

再度、再起動をかけてみましたが、結局できませんでした。
そして、以下のようにエラーが変わりました(status=2からstatus=14)。

[ec2-user@ip-hogehoge etc]$ sudo systemctl status mongod.service ● mongod.service - MongoDB Database Server Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since 火 2020-06-16 07:16:53 UTC; 14s ago Docs: https://docs.mongodb.org/manual Process: 6894 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14) Process: 6891 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 6888 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 6887 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS) Main PID: 6559 (code=exited, status=0/SUCCESS) 6月 16 07:16:45 ip-hogehoge.ap-northeast-1.compute.internal systemd[1]: Starting MongoDB Database Server... 6月 16 07:16:53 ip-hogehoge.ap-northeast-1.compute.internal mongod[6894]: src/third_party/gperftools-2.7/dist/src/central_freelist.cc:...8192 6月 16 07:16:53 ip-hogehoge.ap-northeast-1.compute.internal mongod[6894]: 2020-06-16T07:16:53.696+0000 F - [main] out of memory. 6月 16 07:16:53 ip-hogehoge.ap-northeast-1.compute.internal systemd[1]: mongod.service: control process exited, code=exited status=14 6月 16 07:16:53 ip-hogehoge.ap-northeast-1.compute.internal systemd[1]: Failed to start MongoDB Database Server. 6月 16 07:16:53 ip-hogehoge.ap-northeast-1.compute.internal systemd[1]: Unit mongod.service entered failed state. 6月 16 07:16:53 ip-hogehoge.ap-northeast-1.compute.internal systemd[1]: mongod.service failed. Hint: Some lines were ellipsized, use -l to show in full.

現在も調査中ですが、解決方法が分かりません。

以上、ご教授いただけると助かります。

試したこと

/etc/mongod.conf を編集前に戻すと、問題なく再起動できます。

[ec2-user@ip-hogehoge etc]$ sudo service mongod restart Redirecting to /bin/systemctl restart mongod.service

参考にしたサイト

https://stackoverflow.com/questions/49285525/connect-to-ec2-via-mongodb-compass-community

https://docs.mongodb.com/manual/reference/configuration-options/#net-options

https://teratail.com/questions/130790

https://docs.mongodb.com/manual/reference/exit-codes/
↑ステータスコードについて

https://stackoverflow.com/questions/57380491/mongodb-status-failed-after-editing-mongo-conf-code-exited-status-2

https://superuser.com/questions/1397079/mongo-cant-start-service

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

再現確認してませんが

Online YAML Parser
で見る限り
::は文法エラーになるようですね

bindIp: 0.0.0.0,::

bindIpAll: true
にしてみたらいかがでしょう

投稿2020/06/16 08:03

rururu3

総合スコア5545

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

takaoS

2020/06/16 08:06

ご教授いただいた内容で試したところ、解決いたしました。 素早いご回答、ありがとうございました、大変助かりました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問