MongoDB 起動後の WARNING を消す

MongoDB 起動後の WARNING を消す

MongoDB 起動後の WARNING を消す

MongoDB を立ち上げてみましたら WARNING が出ます。消す方法です。

MongoDB を起動したら3つも WARNING が出た

** WARNING: Access control is not enabled for the database.  
**          Read and write access to data and configuration is unrestricted.


** WARNING: This server is bound to localhost.
**          Remote systems will be unable to connect to this server.
**          Start the server with --bind_ip <address> to specify which IP
**          addresses it should serve responses from, or with --bind_ip_all to
**          bind to all interfaces. If this behavior is desired, start the
**          server with --bind_ip 127.0.0.1 to disable this warning.
 
** WARNING: The file system cache of this machine is configured to be greater than 40% of the total memory.  
**          This can lead to increased memory pressure and poor performance.
**          See http://dochub.mongodb.org/core/wt-windows-system-file-cache

mongo シェルで試してみる

クライアント側にも同じようにサーバの WARNING が表示されます。試しに、データベースを作成してデータを登録してみます。

問題ありませんね。

Access control is not enabled for the database.

でも、気になりますのでどういうことか調べてみました。

WARNING の意味は「データベースがアクセス制御なしで実行されているよ」ということだと思います。MongoDB の Documentation にそれらしきものがありましたので試してみました。

Enable Auth — MongoDB Manual 3.6

  1. まず MongoDB をアクセス制御なしで起動する

     >mongod --port 27017 --dbpath c:\mongodb\data
    
  2. mongoシェルから接続する

     >mongo --port 27017
    
  3. 管理者を作成する

     > use admin
     switched to db admin
     > db.createUser(
     {
     user: "myUserAdmin",
     pwd: "password",
     roles: [{role: "userAdminAnyDatabase", db: "admin"}]
     }
     )
     Successfully added user: {
             "user" : "myUserAdmin",
             "roles" : [
                     {
                             "role" : "userAdminAnyDatabase",
                             "db" : "admin"
                     }
             ]
     }
    
  4. mongoシェルを終了する

     > exit
     bye
    
  5. MongoDB をアクセス制御付きで再起動する

     >mongod --auth --port 27017 --dbpath c:\mongodb\data
    

おお!「WARNING: Access control is not enabled for the database.」が消えました。

This server is bound to localhost.

これはメッセージ通りにやれば消えそうです。

>mongod --auth --port 27017 --bind_ip 127.0.0.1 --dbpath c:\mongodb\data

やはり消えました!

で、後は「The file system cache of this machine is configured to be greater than 40% of the total memory.」なんですが、これがなかなか消えません。

今のところ成功していませんので、次回です。