Centos 使用yum安装MongoDB 4.0

it2022-05-05  128

Centos 使用yum安装MongoDB 4.0

1.配置MongoDB的yum源

创建yum源文件:

#cd /etc/yum.repos.d 

#vim mongodb-org-4.0.repo 

添加以下内容:(我们这里使用阿里云的源)

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

这里可以修改 gpgcheck=0, 省去gpg验证

安装之前先更新所有包 :

# yum update

2.安装MongoDB安装命令:yum -y install mongodb-org

安装完成后

查看mongo安装位置 whereis mongod

查看修改配置文件 : vim /etc/mongod.conf

 bindIp: 172.0.0.1  改为 bindIp: 0.0.0.0

(注意冒号与ip之间需要一个空格)

3.启动MongoDB 启动mongodb :systemctl start mongod.service停止mongodb :systemctl stop mongod.service

查到mongodb的状态:systemctl status mongod.service

4.外网访问需要关闭防火墙:CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。关闭firewall:systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启动

 vim /etc/sysconfig/iptables

iptables文件添加

-A INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT

(注意:-A INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT要加在-A INPUT -j REJECT --reject-with icmp-host-prohibited之前,不然启动无效)

重启iptables

service iptables restart

 5.设置开机启动systemctl enable mongod.service

6.启动Mongo shell 命令:mongo 

查看数据库:show dbs

7.需要的话启用权限控制: 编辑mongod.conf注释bindIp,并重启mongodb. vim /etc/mongod.conf

重启mongodb:systemctl restart mongod.service

 8、下载Robo 3T 

 

       

 

posted on 2018-10-29 11:19 tianyamoon 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/tianyamoon/p/9860656.html


最新回复(0)