在CentOS上選擇并安裝MongoDB時,您需要考慮以下幾個關鍵因素:
sudo vi /etc/yum.repos.d/mongodb-org-6.0.repo
[mongodb-org-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
sudo yum install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongod
/etc/mongod.conf
,將 bindIp
從 127.0.0.1
改為 0.0.0.0
以允許所有IP訪問。net:
bindIp: 0.0.0.0
sudo systemctl restart mongod
sudo firewall-cmd --zone=public --add-port=27017/tcp --permanent
sudo firewall-cmd --reload
通過以上步驟,您應該能夠在CentOS上成功安裝并配置MongoDB。選擇合適的版本并正確配置,可以確保您的系統穩定運行,并滿足業務需求。