日期:2014-05-16  浏览次数:20430 次

mongodb 安装 启动
下载链接: http://www.mongodb.org/downloads
1、下载
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.8.tgz
tar -zxvf mongodb-linux-x86_64-2.4.8.tgz
mv mongodb-linux-x86_64-2.4.8 mongodb 重命名目录
[root@localhost mongodb]# mkdir log
[root@localhost mongodb]# mkdir data
[root@localhost mongodb]# cd log
[root@localhost log]# touch mongodb.log
创建目录文件
2、启动
通过配置文件启动
[root@localhost mongodb]# vi mongodb.conf

port=10001
dbpath=data/
logpath=log/mongodb.log
logappend=true    //追加日志
fork=true      //后台运行
auth=true  //开启认证
bind_ip=192.168.11.0/24,127.0.0.1

启动
[root@localhost mongodb]# ./bin/mongod -f mongodb.conf
all output going to: log/mongodb.log

开机启动
vi /etc/rc.d/rc.local
加入 /root/mongodb/bin/mongod -f /root/mongodb/mongodb.conf

添加用户
    > use admin
    switched to db admin
    > db.addUser("lee1","lee1")
    {
        "user" : "lee1",
        "readOnly" : false,
        "pwd" : "48117ef640dfd3e9097beda195584a95",
        "_id" : ObjectId("51610a3d16abc5abe0f29870")
    }
    > db.auth("lee1","lee1")
    1
    > db.system.users.find()
    { "_id" : ObjectId("51610168951f92160cfa5606"), "user" : "root", "readOnly" : false, "pwd" : "2a8025f0885adad5a8ce0044070032b3" }
    { "_id" : ObjectId("51610a3d16abc5abe0f29870"), "user" : "lee1", "readOnly" : false, "pwd" : "48117ef640dfd3e9097beda195584a95" }