cd /usr/local/src/wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.7.1.tgztar -zxvf mongodb-linux-x86_64-3.7.1.tgzmv mongodb-linux-x86_64-3.7.1 /usr/local/mongodbecho "PATH=/usr/local/mongodb/bin:$PATH" >> /etc/profilesource /etc/profilegroupadd mongouseradd -rg mongo mongomkdir -p /data/dbchown -R mongo mongo /usr/local/mongodbcat >> /usr/local/mongodb/bin/mongodb.conf <<EOFfork = trueport = 27017bind_ip = 0.0.0.0dbpath = /data/dblogpath = /data/db/mongodb.logEOF##启动mongod --config /usr/local/mongodb/bin/mongodb.conf
> use adminswitched to db admin> db.createUser({user:"admin",pwd:"password",roles:["root"]})Successfully added user: { "user" : "admin", "roles" : [ "root" ] }> db.getCollectionNames()[ "system.users", "system.version" ]echo auth = true >> /usr/local/mongodb/bin/mongodb.conf ##重启mongodb##登录账号密码> db.auth("admin", "password")
#创建库> use autoops > db.createUser({user: "autoops", pwd: "autoops", roles: [{ role: "dbOwner", db: "autoops" }]})Successfully added user: { "user" : "autoops", "roles" : [ { "role" : "dbOwner", "db" : "autoops" } ]}
mongo -u admin -p password 127.0.0.1:27017/admin
MongoDB 3.7.1 Installation