解決MongoDB登錄的WARNING
1.安裝完成運行mongodb警告內容如下:
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten]
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten]
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten]
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten]
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
警告一:
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten]
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
1.原因自查--解決:
# 在系統 /etc/rc.local 設置 transparent_hugepage 為 never
[root@server_node01#>> /data/db]#cat /etc/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
2.添加該文件的可執行權限:
[root@server_node01#>> /usr/local/mongodb]#chmod +x /etc/rc.d/rc.local
3.重啟下系統:
reboot
警告二:
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2019-01-17T15:41:50.578+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
設置允許訪問該mongodb的地址 --bind_ip:
# 配置文件 添加 --bind_ip 指定可連接的主機
# 數據指定位置
dbpath = /data/db
# 日志指定位置
logpath = /data/db/logs/mongodb.log
# 每個數據庫將被保存在一個單獨的目錄
directoryperdb = true
# 日志追加形式寫入
logappend = true
port = 27017
# 守護進程啟動
fork = true
# 指定可連接的主機
bind_ip = 0.0.0.0
# 啟動驗證 [配置完驗證用戶后啟用]
# auth = true
警告三:
WARNING: Access control is not enabled for the database.
Read and write access to data and configuration is unrestricted.
設置密碼訪問auth=True:
1.登錄mongo設置admin 密碼
[root@server_node01#>> /usr/local/mongodb]#mongo
> use admin
> db.createUser({user:"root",pwd:"root",roles:[{role:'root',db:'admin'}]})
2.將配置文件 auth 認證打開
# 數據指定位置
dbpath = /data/db
# 日志指定位置
logpath = /data/db/logs/mongodb.log
# 每個數據庫將被保存在一個單獨的目錄
directoryperdb = true
# 日志追加形式寫入
logappend = true
port = 27017
# 守護進程啟動
fork = true
# 指定可連接的主機
bind_ip = 0.0.0.0
# 啟動驗證 [配置完驗證用戶后啟用]
auth = true
重啟mongodb 服務
[root@server_node01#>> /data/db]#mongod --shutdown
[root@server_node01#>> /data/db]#mongod -f /usr/local/mongodb/conf/mongodb.conf
登錄:
[root@server_node01#>> /data/db]#mongo 127.0.0.1:27017/admin -u root -p
警告四:不要用root用戶啟動 MongoDB服務
2019-01-17T16:13:10.778+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.