配置MongoDB的yum源
tee /etc/yum.repos.d/mongodb-org-3.4.repo <<-'EOF'
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=0
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
#这里可以修改 gpgcheck=0, 省去gpg验证
EOF
刷新缓存
[root@localhost ~]# yum makecache
安装
yum -y install mongodb-org
查找配置文件
whereis mongod
注释掉mongod.conf中的bindIp
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
启动mongodb :
systemctl start mongod.service
加入开机启动
systemctl enable mongod.service
防火墙开端口
firewall-cmd --permanent --add-port=27017/tcp
firewall-cmd --reload
进入数据库添加用户
mongo;
use admin;
db.createUser(
{
user: "admin",
pwd: "123456",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]</code>
}
);
修改配置文件,启用身份认证
#打开注释
security:
#加入这句
authorization: enabled
重启mongo
systemctl restart mongod
网友评论