晶片短缺,福特密歇根工廠停產:主要生產野馬車型
阿新 • • 發佈:2022-04-01
配置yum源
sudo tee /etc/yum.repos.d/mongodb-org-4.4.repo<<'EOF'
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=0
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
EOF
關閉防火牆,禁用SELinux
# 關閉防火牆 systemctl stop firewalld && systemctl disable firewalld # 禁用SELinux setenforce 0 sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config getenforce ##檢查selinux狀態
安裝
sudo yum -y install mongodb-org
sudo yum -y remove mongodb* #解除安裝
開啟外網訪問許可權和登入驗證
sudo sed -i '/bindIp/{s/127.0.0.1/0.0.0.0/}' /etc/mongod.conf
sudo sed -i '/^#security/a\security:\n authorization: enabled' /etc/mongod.conf
啟動 MongoDB,並設定開機啟動
sudo systemctl start mongod sudo systemctl enable mongod # 設定開機啟動 sudo systemctl status mongod # 檢視 mongod 執行狀態,如果輸出中包含 active (running)字樣說明 mongod 成功啟動
檢視是否安裝成功
mongo --quiet "mongodb://127.0.0.1:27017"
建立管理員賬戶
$ mongo --quiet "mongodb://127.0.0.1:27017" Welcome to the MongoDB shell. > use admin switched to db admin > db.createUser({user:"root",pwd:"root",roles:["root"]}) Successfully added user: { "user" : "root", "roles" : [ "root" ] } > db.auth("root", "root") 1
刪除使用者,可以使用 db.dropUser("使用者名稱")
使用管理員賬戶登入,建立一個 iam 普通使用者來連線和操作 MongoDB
$ mongo --quiet mongodb://root:'root'@127.0.0.1:27017/tyk_analytics?authSource=admin
> use iam_analytics
switched to db iam_analytics
> db.createUser({user:"iam",pwd:"iam",roles:["dbOwner"]})
Successfully added user: { "user" : "iam", "roles" : [ "dbOwner" ] }
> db.auth("iam", "iam")
1
使用剛建立的普通賬戶登入
mongo --quiet mongodb://iam:'iam'@127.0.0.1:27017/iam_analytics?authSource=iam_analytics