Linux服务器未启用MongoDB身份验证 [英] MongoDB Authentication not enabled on Linux Server

查看:291
本文介绍了Linux服务器未启用MongoDB身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Linux Server-Ubuntu 16.04上安装了mongodb.正如我通过putty进行的测试一样,它已经启动并正在运行.因此,我接下来要做的是在mongodb上设置身份验证.

I have installed mongodb on Linux Server - Ubuntu 16.04. It is up and running, as I have tested it through putty. So, next thing I wanted to do was setup authentication on mongodb.

我创建了具有以下角色的用户博客.

I have created users with roles following this blog.

这是我的etc/mongodb.conf

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1
security:
  authorization: enabled

我在system.users集合的db中具有两个具有角色的dbs的设置用户,并在服务器上重新启动了mongod.

I have setup user in db in system.users collection for two dbs with roles and restarted mongod on server.

这里是脚本test.sh,用于测试mongodb的身份验证状态.引用来自此处.

Here, is the script test.sh to test the authentication status of mongodb. Ref was taken from here.

#!/bin/bash

# Connect to MongoDB address (host:port/dbname) specified as first parameter
# If no address specified, `mongo` default will be localhost:27017/test
isAuth=`mongo --eval "db.getUsers()" $1 | grep "not auth"`

if [ -z "$isAuth" ] ;
then
   echo "mongod auth is NOT enabled"
   exit 1
else
   echo "mongod auth is ENABLED"
   exit 0
fi

当我运行脚本时,我得到了mongod auth is NOT enabled.而且,我也不会在插入或查看数据库表单外壳时遇到问题.

When I run the script I got mongod auth is NOT enabled. Moreover, I am also not having problem inserting or viewing database form shell.

所以,我的总结问题是:

So, my questions in summary are:

  1. 我在/etc/mongodb.conf上进行身份验证所做的正确吗?如果不是,什么是正确的方法?
  2. 如何测试是否在MongoDb上启用了身份验证?
  1. Is what I have done for authentication on /etc/mongodb.conf correct? If not what might be the right way?
  2. How can I test if authentication is enabled on MongoDb?

P.S:如果有帮助,我可以从Azure创建Linux Server.

推荐答案

很抱歉,但这是我正在做的错字systemctl start mongodb,实际上是mongod.

Sorry to say but it was a typo I was doing systemctl start mongodb, it was actually mongod.

systemctl start mongod

使其启动并运行.我希望我用于在Mongodb和Bash Script上启用authorization来检查授权是否有效的资源,对于开始使用MongoDB进行开发的开发人员来说,将是一个很好的资源.

made it up and running. I hope the resources I used for enabling authorization on Mongodb and Bash Script to check if authorization is working, will be a good resources for developers starting to develop using MongoDB.

这篇关于Linux服务器未启用MongoDB身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆