centos 6.5 mongodb3.11安裝記,centosmongodb3.11

來源:互聯網
上載者:User

centos 6.5 mongodb3.11安裝記,centosmongodb3.11

http://www.mongodb.org/downloads


下載

curl -O -L https://fastdl.mongodb.org/linux/mongodb-linux-i686-3.0.2.tgz

解壓安裝

tar -xvzf mongodb-Liunix-xxxxx.tgz

啟動指令碼

[root@a1 bin]# cat start.sh
./mongod --dbpath /opt/mongodb-data/data --logpath /opt/mongodb-data/logs/mongodb.log --journal --fork


設定密碼

> use admin
switched to db admin
> db.createUser()
2015-04-18T15:39:05.402+0000 E QUERY    TypeError: Cannot read property 'user' of undefined
    at DB.createUser (src/mongo/shell/db.js:1056:23)
    at (shell):1:4 at src/mongo/shell/db.js:1056
> db.createUser({user:"sa",pwd:"123",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})
Successfully added user: {
 "user" : "sa",
 "roles" : [
  {
   "role" : "userAdminAnyDatabase",
   "db" : "admin"
  }
 ]
}
> show dbs
admin  0.078GB
local  0.078GB
> quit();


密碼設定完

啟動指令碼修改為

./mongod --dbpath /opt/mongodb-data/data --logpath /opt/mongodb-data/logs/mongodb.log --journal --fork  --auth

殺死進程重新啟動

[root@a1 bin]# ps -ef|grep mongo
root     10931     1  0 15:28 ?        00:00:11 ./mongod --dbpath /opt/mongodb-data/data --logpath /opt/mongodb-data/logs/mongodb.log --journal --fork
root     11038 10460  0 15:53 pts/0    00:00:00 grep mongo
[root@a1 bin]# kill -9 10931
[root@a1 bin]# ps -ef|grep mongo
root     11042 10460  0 15:54 pts/0    00:00:00 grep mongo
[root@a1 bin]# vi start.sh
[root@a1 bin]# ./start.sh
about to fork child process, waiting until server is ready for connections.
forked process: 11047
child process started successfully, parent exiting

用戶端登陸

[root@a1 bin]# ./mongo --port 27017 -u sa -p 123 --authenticationDatabase admin
MongoDB shell version: 3.1.1
connecting to: 127.0.0.1:27017/test
>



相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.