1.添加 yum repohtml
vi /etc/yum.repos.d/mongodb-org-4.0.repomongodb
添加以下內容 安全
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asctcp
保存退出url
2.查看 repolist.net
yum repolist all|grep mongodbrest
3.yum安裝server
yum install -y mongodb-orghtm
4.啓動/查看服務blog
systemctl start mongod.service
systemctl status mongod.service
5.查看端口狀態
netstat -ntlp
6.運行
mongo --host 127.0.0.1:27017
db
show dbs
7.配置遠程鏈接
編輯 mongod.conf 配置
cp /etc/mongod.conf /etc/mongod.conf.bak
vi /etc/mongod.conf
將 bindIp: 127.0.0.1 改爲 bindIp: 0.0.0.0,注意 tab 和空格對齊
開放端口
firewall-cmd --zone=public --add-port=27017/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --query-port=27017/tcp
重啓服務
systemctl restart mongod.service
8.設置登陸認證
建立管理員用戶
use admin
db.createUser(
{
user: "user",
pwd: "pwd",
roles: [ { role: "root", db: "admin" } ]
}
)
建立普通用戶
use demo
db.createUser(
{
user: "user",
pwd: "pwd",
roles: [ { role: "readWrite", db: "demo" } ]
}
)
建立訪客
use demo
db.createUser(
{
user: "guest",
pwd: "pwd",
roles: [ { role: "read", db: "demo" } ]
}
)
編輯 mongod.conf 配置,開啓認證
vi /etc/mongod.conf
找到 #security: ,改爲以下開啓安全認證:
security:
authorization: enabled
重啓服務
systemctl restart mongod.service
參考文章:
https://blog.csdn.net/u010279498/article/details/89556660 yum安裝及配置
https://blog.csdn.net/jianleking/article/details/79715097 開啓安全認證