mongDB的本地化安装(快速启动mongo服务器)

快速启动mongo服务器:./mongod   --config   mongodb.conf

=========================================================

1、yum install libcurl openssl

2、wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.4.tgz

3、tar zxvf   mongodb-linux-x86_64-rhel70-3.2.4.tgz

4、cd  mongodb-linux-x86_64-rhel70-3.2.4/bin/

5、vi   mongodb.conf

dbpath = /root/soft999/mongoDB306/db   (文件夹)
logpath = /root/soft999/mongoDB306/mongdb.log   (文件)
port = 27017   
fork = true  
auth = true

nohttpinterface=true

------------------------------------

启动服务器:

./mongod   --config   mongodb.conf

启动mongo服务

./mongo

================================================

1、use admin 创建超级管理员用户

db.createUser(
  {
    user: "adminUser",
    pwd: "adminPass",
    roles: [ { role: "root", db: "admin" } ]
  }
)

2、必须先认证,不然什么都做不了 

  db.auth("adminUser","adminPass")

--------------------------------------------------------------------

3、创建普通用户

db.createUser(
  {
    user: "ceshi",
    pwd: "xyz123",
    roles: [ { role: "readWrite", db: "hadoop" } ]
  }
)

4、写入测试

插入 :db.ceshi.insertOne({name:"sue",age:19,status:'p'})

查找: db.hadoop.find({name:"sue"})                  or   查找所有:db.hadoop.find()

5、远程连接

mongo --host 127.0.0.1 -u "ceshi" --authenticationDatabase "hadoop" -p'xyz123'

=====================================================

直接登入mongo----顺序下面方法确认是成功操作的(写入数据一定要db.auth,不然是不成功的)

use admin

db.auth("adminUser","adminPass")  

use hadoop005

db.createUser(
  {
    user: "ceshi005",
    pwd: "xyz123",
    roles: [ { role: "readWrite", db: "hadoop005" }]
  }

db.auth("ceshi005","xyz123")
)
    
   

你可能感兴趣的:(mongDB)