linux安装mongodb

in Linux with 19 comments

1、添加repo

centos7:

vi /etc/yum.repos.d/mongodb.repo

[MongoDB]
name=MongoDB Repository
baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

debian:
apt install dirmngr gnupg apt-transport-https software-properties-common ca-certificates curl
curl -fsSL https://www.mongodb.org/static/pgp/server-4.2.asc |apt-key add -
add-apt-repository 'deb https://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main'
apt update -y

2、安装

centos7:
yum install mongodb-org -y

debian:
apt install mongodb-org

3、启动

systemctl start mongod.service
systemctl enable mongod.service #开机启动

4、创建root用户。
执行mongo

use admin;
db.createUser({user: "root", pwd: "password", roles: [{role: "root", db: "admin"}]});
创建普通用户:

use test2db
db.createUser({user: "test2", pwd: "test2", roles: [{role: "readWrite", db: "test2db" }]})
Comments are closed.