10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mongod が起動しなかったときにしたこと

Last updated at Posted at 2017-10-13

プロローグ

$ mongod とか $ sudo mongod とかやれば起動するらしいけど、これ完全に起動してないな。。

なに、--dbpath うんたらかんたらとか --repairとかつけなきゃいけないのか。やってみる。

$ sudo mongod --dbpath /var/db/mongo/
2017-10-09T16:36:59.649+0900 I CONTROL  [initandlisten] MongoDB starting : pid=37314 port=27017 dbpath=/var/db/mongo/ 64-bit host=**********
2017-10-09T16:36:59.649+0900 I CONTROL  [initandlisten] db version v3.4.7
2017-10-09T16:36:59.649+0900 I CONTROL  [initandlisten] git version: cf38c1b8a0a8dca4a11737581beafef4fe120bcd
2017-10-09T16:36:59.649+0900 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2l  25 May 2017
2017-10-09T16:36:59.649+0900 I CONTROL  [initandlisten] allocator: system
2017-10-09T16:36:59.649+0900 I CONTROL  [initandlisten] modules: none
2017-10-09T16:36:59.649+0900 I CONTROL  [initandlisten] build environment:
2017-10-09T16:36:59.649+0900 I CONTROL  [initandlisten]     distarch: x86_64
2017-10-09T16:36:59.649+0900 I CONTROL  [initandlisten]     target_arch: x86_64
2017-10-09T16:36:59.649+0900 I CONTROL  [initandlisten] options: { storage: { dbPath: "/var/db/mongo/" } }
2017-10-09T16:36:59.651+0900 E NETWORK  [initandlisten] listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-10-09T16:36:59.651+0900 E NETWORK  [initandlisten]   addr already in use
2017-10-09T16:36:59.651+0900 E NETWORK  [initandlisten] Failed to set up sockets during startup.
2017-10-09T16:36:59.651+0900 E STORAGE  [initandlisten] Failed to set up listener: InternalError: Failed to set up sockets
2017-10-09T16:36:59.651+0900 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-10-09T16:36:59.651+0900 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-10-09T16:36:59.651+0900 I CONTROL  [initandlisten] now exiting
2017-10-09T16:36:59.651+0900 I CONTROL  [initandlisten] shutting down with code:48

意味わからんーーー。途中から Failed とか shutdown とか now exiting とか言ってるし。諦めないでよ!
--repair つけてもなんかよくわからんエラーで止まる。)

てかそもそも起動に成功したらどんな反応をするんだ。。。

そもそもインストールできてるか確認

$ mongod --version
db version v3.4.9
git version: 876ebee8c7dd0e2d992f36a848ff4dc50ee6603e
OpenSSL version: OpenSSL 1.0.2l  25 May 2017
allocator: system
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

できてた。

インストールされてなければする

$ brew install mongodb

でインストール。
==> Summary🍺 みたいな感じが出ればOK。

ついでに $ brew upgrade mongodb でアップグレード(?)もしたけど、これが最終的に意味があったのかどうかは分からない。

brew 上で mongodb が動いてるか確認

$ brew services list
Name     Status  User Plist
mongodb stopped   

とのこと。えー止まってるんかい!

動かす

$ brew services start mongodb
==> Successfully started `mongodb` (label: homebrew.mxcl.mongodb)

おっ!

$ brew services list
Name     Status  User Plist
mongodb  started mori /Users/mori/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

おおっ!動いた。

/data/db の所有権を変更

$ ls -l /data/ # before: 所有者は root
total 0
drwxr-xr-x  38 root  wheel  1258 10 13 14:55 db

$ sudo chown mori /data/db # /data/db の所有者を mori に変更

$ ls -l /data/ # after: 所有者は mori (私の名前は mori)
total 0
drwxr-xr-x  37 mori  wheel  1292 10 13 14:58 db

※ この操作が必要だったのかどうかが怪しい。

ついに $ mongod

ではなく $ sudo mongod
すると、ついに動いてるっぽい感じに!

$ sudo mongod
Password:
2017-10-13T15:10:42.915+0900 I CONTROL  [initandlisten] MongoDB starting : pid=83975 port=27017 dbpath=/data/db 64-bit host=***********.local
2017-10-13T15:10:42.916+0900 I CONTROL  [initandlisten] db version v3.4.9
2017-10-13T15:10:42.916+0900 I CONTROL  [initandlisten] git version: 876ebee8c7dd0e2d992f36a848ff4dc50ee6603e
2017-10-13T15:10:42.916+0900 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2l  25 May 2017
2017-10-13T15:10:42.916+0900 I CONTROL  [initandlisten] allocator: system
2017-10-13T15:10:42.916+0900 I CONTROL  [initandlisten] modules: none
2017-10-13T15:10:42.916+0900 I CONTROL  [initandlisten] build environment:
2017-10-13T15:10:42.916+0900 I CONTROL  [initandlisten]     distarch: x86_64
2017-10-13T15:10:42.916+0900 I CONTROL  [initandlisten]     target_arch: x86_64
2017-10-13T15:10:42.916+0900 I CONTROL  [initandlisten] options: {}
2017-10-13T15:10:42.917+0900 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-10-13T15:10:42.917+0900 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-10-13T15:10:44.320+0900 I CONTROL  [initandlisten] 
2017-10-13T15:10:44.320+0900 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-10-13T15:10:44.320+0900 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-10-13T15:10:44.320+0900 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-10-13T15:10:44.320+0900 I CONTROL  [initandlisten] 
2017-10-13T15:10:44.320+0900 I CONTROL  [initandlisten] 
2017-10-13T15:10:44.320+0900 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-10-13T15:10:44.362+0900 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2017-10-13T15:10:44.363+0900 I NETWORK  [thread1] waiting for connections on port 27017

嬉しい。

どうやら 27017ポート で起動してるらしい。ブラウザでhttp://localhost:27017/ を見てみる。

It looks like you are trying to access MongoDB over HTTP on the native driver port.

と表示された。そう!そうなんだよ!ありがとう!

感想

ぜんぜんわからない。
どの操作が意味を成したのか、どれが無駄な操作だったのか。
俺たちは雰囲気で $ mongod をやっている。

これを読んでくださった先輩方はいろいろコメントしてくれると嬉しいです。

追記

いつもなら起動できるのに今回はできない っていうとき、

$ ps -ef | grep mongod
    0 13061     1   0 土06PM ??         0:00.02 sudo mongod
    0 13062 13061   0 土06PM ??         4:47.14 mongod
  501 46095 45067   0  7:11PM ttys006    0:00.01 grep mongod

で確認できたすでに mongodで使っているポートのプロセスを強制で殺せば、うまく起動できた。つまり、すでに mongodは動いていたってことなんですかね。多分そうだった。

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?