centos7安装mongodb4.2.15教程
环境:centos 7
版本:mongodb 4.2.15
1、下载安装
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.15.tgz
tar -xzf mongodb-linux-x86_64-rhel70-4.2.15.tgz
mv mongodb-linux-x86_64-rhel70-4.2.15 /usr/local/mongodb
2、创建目录
mkdir -p /data/mongodb/{db,logs}
3、配置文件
vim /data/mongodb/27017.conf
systemLog:
destination: file
logAppend: true
path: /data/mongodb/logs/27017.log
storage:
dbPath: /data/mongodb/db
journal:
enabled: true
processManagement:
fork: true
pidFilePath: /data/mongodb/27017.pid
net:
port: 27017
bindIp: 0.0.0.0
security:
authorization: enabled #认证
fork: false 前台启动
fork: true 放入后台启动
4、启动
/usr/local/mongodb/bin/mongod -f /data/mongodb/27017.conf
登录后关闭
/usr/local/mongodb/bin/mongo 127.0.0.1:27010
> use admin
switched to db admin
> db.shutdownServer()
直接关闭
kill <mongod process ID>
5、给admin授权并登录
shell> use admin;
shell> db.createUser({user:'admin',pwd:'admin123', roles:[{role:'root', db:'admin'}]});
修改admin密码
> db.changeUserPassword('admin','123456')
登录:
/usr/local/mongodb/bin/mongo 127.0.0.1:27017 -u admin -p 123456 --authenticationDatabase admin