Centos 安裝MongoDB

1.用yum安裝
建立yum源文件:mongodb

#cd /etc/yum.repos.d vim

#vim mongodb-org.repo 阿里雲

添加如下內容:url

[mngodb-org]
name=MongoDB Repository baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.4/x86_64/ gpgcheck=0 enabled=1

這裏注意地址用的阿里雲的鏡像庫,比mongodb官方的會快不少。spa

保存後退出編輯,用repolist 命令檢查下repo文件是否生效code

而後就是yuman安裝blog

yum -y install mongodb-org

安裝好了,若是系統比較乾淨,會安裝的依賴比較多,有些慢,我這裏共安裝了11個應用ip

 

2.修改配置文件it

先找下mongodb 安裝到哪裏了class

whereis mongod

看下結果,找到 mongod.conf 配置文件

mongod: /usr/bin/mongod /etc/mongod.conf /usr/share/man/man1/mongod.1

編輯位置文件

vim /etc/mongod.conf

而後只改下bindip

 

 

 看到說明了,改爲 0.0.0.0 就是不限制ip綁定

 

3.啓動mongodb

啓動mongodb服務

systemctl start mongod.service

啓動後能夠用下面的命令查看狀態

systemctl status mongod.service

 

 也能夠經過http訪問來驗證,http://39.102.116.84:27017/,若是看到下面的提示表明啓動正常

It looks like you are trying to access MongoDB over HTTP on the native driver port.

 

4.設置開機自動啓動

systemctl enable mongod.service
相關文章
相關標籤/搜索