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