Centos 7.6 使用yum安裝MongoDB 4.2

1.創(chuàng)建yum源文件

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

內(nèi)容
[mngodb]
name=MongoDB Repository
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.2/x86_64/
gpgcheck=0
enabled=1

2.安裝并修改配置

yum  install -y vim  mongodb
vim /etc/mongod.conf

bindIp: 172.0.0.1 改為 bindIp: 0.0.0.0 #注意冒號(hào)與ip之間需要一個(gè)空格

3.啟動(dòng),停止,查看狀態(tài),重啟

systemctl start mongod.service
systemctl stop mongod.service
systemctl status mongod.service
systemctl restart mongod.service

4.關(guān)閉firewall:

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開(kāi)機(jī)啟動(dòng)

5.設(shè)置開(kāi)機(jī)啟動(dòng)

systemctl enable mongod.service

6.啟動(dòng)Mongo shell,查看數(shù)據(jù)庫(kù)

mongo 
show dbs

7.需要的話(huà)啟用權(quán)限控制:

編輯mongod.conf注釋bindIp,并重啟mongodb

vim /etc/mongod.conf
systemctl restart mongod.service

8.springboot測(cè)試代碼

https://github.com/gzz2017gzz/spring-boot2-example/tree/master/58-spring-boot-MongoTemplate

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容