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 #注意冒號與ip之間需要一個空格
3.啟動稍味,停止烛愧,查看狀態(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開機(jī)啟動
5.設(shè)置開機(jī)啟動
systemctl enable mongod.service
6.啟動Mongo shell,查看數(shù)據(jù)庫
mongo
show dbs
7.需要的話啟用權(quán)限控制:
編輯mongod.conf注釋bindIp,并重啟mongodb
vim /etc/mongod.conf
systemctl restart mongod.service
8.springboot測試代碼
https://github.com/gzz2017gzz/spring-boot2-example/tree/master/58-spring-boot-MongoTemplate