解决MongoDB登录的WARNING

解决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.
posted @ 2019-01-17 16:16  叨客厨子  阅读(3321)  评论(0编辑  收藏  举报