今日もシュクシュクと! Season2

一人前のエンジニアを目指して修行中の日々。何事も誠実にコツコツと。そして粛々と。

mongodbのインストールからサービス開始

1.homebrewでインストール

$brew install mongodb 

 

2.DBパスを作成する

$sudo mkdir /var/lib/mongodb

 

3.ログの出力先を作成する

 $sudo touch /var/log/mongodb.log

 

4.DBを開始する

$sudo mongod --dbpath /var/lib/mongodb --logpath /var/log/mongodb.log

 

5.動作確認

$ mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
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:
2017-12-01T16:18:23.070+0900 I CONTROL [initandlisten]
2017-12-01T16:18:23.070+0900 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-12-01T16:18:23.070+0900 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-12-01T16:18:23.070+0900 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-12-01T16:18:23.070+0900 I CONTROL [initandlisten]

 

 

※ちなみにサービスを開始せずにmongoコマンドを実行すると以下のエラーが出力される

$ mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
2017-12-01T11:02:37.936+0900 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-12-01T11:02:37.936+0900 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed