centos7安装单机
yum
安装
1、配置yum源
vim /etc/yum.repos.d/mongodb.repo
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc
2、下载安装包
yum install -y mongodb-org
3、启动
systemctl start mongod
4、查看服务情况
systemctl status mongod
5、检测是否能进入mongdb
mongosh
默认目录
- /var/lib/mongo(数据目录)
- /var/log/mongodb(日志目录)
卸载
shell
sudo service mongod stop
sudo yum remove mongodb-org*
配置密码
方式一:
https://www.jb51.net/database/2977061tr.htm#_label1
shell
// 连接到MongoDB数据库
mongosh
// 切换到admin数据库
use admin
// 创建用户
db.createUser({
user: "admin",
pwd: "helloAdmin",
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "dbAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" }
]
})