Windows
Linux
- (1)使用安装包安装
- 安装前我们需要安装各个 Linux 平台依赖包。
- Red Hat/CentOS:
sudo yum install libcurl openssl
- Ubuntu 18.04 LTS ("Bionic")/Debian 10 "Buster":
sudo apt-get install libcurl4 openssl
- Ubuntu 16.04 LTS ("Xenial")/Debian 9 "Stretch":
sudo apt-get install libcurl3 openssl
- (2)创建数据目录
- (3)运行 MongoDB 服务
mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork
- 打开 /var/log/mongodb/mongod.log 文件看到以下信息,说明启动成功。
# tail -10f /var/log/mongodb/mongod.log
2020-07-09T12:20:17.391+0800 I NETWORK [listener] Listening on /tmp/mongodb-27017.sock
2020-07-09T12:20:17.392+0800 I NETWORK [listener] Listening on 127.0.0.1
2020-07-09T12:20:17.392+0800 I NETWORK [listener] waiting for connections on port 27017
- (4)客户端连接 MongoDB
cd /usr/local/mongodb4/bin
./mongo
设置用户名、密码
> use admin
switched to db admin
> db.createUser({"user":"root","pwd":"root","roles":[{"role":"userAdminAnyDatabase","db":"admin"}]})
Successfully added user: {
"user" : "root",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
>