Linux下Mongodb安装和启动配置
  fztgkkRjHIsV 2023年11月14日 85 0




  1. Mongodb的安装与启动
  2. 下载链接: http://www.mongodb.org/downloads----------------------------------------------------------------------------
    Linux安装第一步:下载安装包下载版本:2.0.2-rc2下载链接: http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.4.tgz首先在linux中解压缩安装程序通过命令操作:解压:[root@localhost soft]# tar -zxvf mongodb-linux-i686-2.0.1.tgz解压过程如下:

mongodb-linux-i686-2.0.1/
mongodb-linux-i686-2.0.1/THIRD-PARTY-NOTICES
mongodb-linux-i686-2.0.1/GNU-AGPL-3.0
mongodb-linux-i686-2.0.1/README
mongodb-linux-i686-2.0.1/bin/
mongodb-linux-i686-2.0.1/bin/mongofiles
mongodb-linux-i686-2.0.1/bin/mongostat
mongodb-linux-i686-2.0.1/bin/bsondump
mongodb-linux-i686-2.0.1/bin/mongos
mongodb-linux-i686-2.0.1/bin/mongotop
mongodb-linux-i686-2.0.1/bin/mongodump
mongodb-linux-i686-2.0.1/bin/mongoimport
mongodb-linux-i686-2.0.1/bin/mongosniff
mongodb-linux-i686-2.0.1/bin/mongo
mongodb-linux-i686-2.0.1/bin/mongod
mongodb-linux-i686-2.0.1/bin/mongoexport
mongodb-linux-i686-2.0.1/bin/mongorestore


我们把 mongodb-linux-i686-2.0.2-rc2重命名为mongodb

mv mongodb-linux-x86_64-2.0.4.tgz mongodb
  1. 然后定位到mongodb/bin目录中
cd /usr/local/mongodb/bin
  1. 启动命令 :
  2. ./mongod --dbpath=/usr/local/mongodb/mongodb_db --logpath=/usr/local/mongodb/mongodb_logs/mongodb.log --logappend&
  3. 检查mogodb端口
netstat -lanp  | grep 27017
  1. 使用默认账号,添加自己的账号
./mongo
MongoDB shell version: 2.0.4
connecting to: test
> db.system.users.find()
> db.system.users.find();
> use mongo_test
switched to db mongo_test
> db.createCollection("test")
{ "ok" : 1 }
//使用默认账号
> use admin
switched to db admin
//添加账号
> db.adduser('cl','cl')
//读写授权
> db.auth("zhixian","Zhixian123")
//添加成功
Mon Jun 20 22:43:13 TypeError: db.adduser is not a function (shell):1
//测试
> db.addUser('cl','cl')
{ "n" : 0, "connectionId" : 1, "err" : null, "ok" : 1 }
{
        "user" : "cl",
        "readOnly" : false,
        "pwd" : "1b8c3505b26a25291393e900e8c89f29",
        "_id" : ObjectId("5768018f62752737d5e06717")
}


> show collections
system.indexes
system.users
> db.system.users.find()
{ "_id" : ObjectId("5768018f62752737d5e06717"), "user" : "cl", "readOnly" : false, "pwd" : "1b8c3505b26a25291393e900e8c89f29" }
> exit
bye


linux下开机启动mongodb

vim /etc/rc.local


  1. 最后一行加入
/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/mongodb_db --fork --port 27017  --logpath=/usr/local/mongodb/mongodb_logs/mongodb.log--logappend --auth

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月14日 0

暂无评论

推荐阅读
fztgkkRjHIsV