Centos7 安装mongodb3.2.9 过程

时间:2024-11-06 14:33:32

1:wget --no-check-certificate  https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.2.9.tgz
2:tar vzxf mongodb-linux-x86_64-amazon-3.2.9.tgz
3:mv mongodb-linux-x86_64-amazon-3.2.9 /usr/local/mongodb
4:cd /usr/local/mongodb
5:mkdir -p ./data/db
6:mkdir logs
"""

8:启动:(开启验证)
/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data/db --logpath=/usr/local/mongodb/logs/mongod.log --fork

9:启动mongodb时,报如下错误:child process failed, exited with error number 100
这是因为非正常关闭mongodb引起的错误,解决办法如下:
删掉以下文件即可:/usr/local/mongodb/mongod.lock

10:设置权限:

  1:创建root权限:在shell下

    use admin

    db.createUser({"user":"root","pwd":"password","role":roles: [ { role: "root", db: "admin" } ]}) #创建root用户,用于用户的管理

    db.createUser({"user":"admin","pwd":"password","role":roles: [ { role: "readWrite", db: "admin" } ]}) #创建数据库用户,并且赋予读写权限

    

10:创建一个sh脚本来启动服务
vi serverStart.sh
"""
/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs/mongod.log --auth --fork
echo "mongodb start success!"
"""