CentOS7安装MongoDB企业版

参考 MongoDB 官方网站:https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-red-hat/

1.配置 yum 源

  • 创建yum源文件

      touch /etc/yum.repos.d/mongodb-enterprise.repo

  • 修改配置文件

      vim /etc/yum.repos.d/mongodb-enterprise.repo

[mongodb-enterprise]
name=MongoDB Enterprise Repository
baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/4.0/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

2.使用 yum 安装MongoDB

  yum install -y mongodb-enterprise

3.配置SELinux

  • 安装semanage命令

      yum -y install policycoreutils-python

  • 如果SELinux处于enforcing模式,则启用对MongoDB部署将使用的相关端口的访问(例如27017)

      semanage port -a -t mongod_port_t -p tcp 27017

  • 将SELINUX配置文件设置为 disabled 模式,禁用SELinux

      vim /etc/selinux/config  SELINUX=disabled

  • 将SELinux配置文件设置为 permissive 模式,解除限制

      vim /etc/selinux/config  SELINUX=permissive

  • 修改完配置文件后,需要重启使设置生效

      reboot

4.MongoDB的使用

  • 启用/停止/重启 MongoDB 服务

      systemctl start mongod.service

      systemctl stop mongod.service

      ssystemctl restart mongod.service

  • 使MongoDB伴随系统启动

      systemctl enable mongod.service

  • 在本机使用MongoDB

      mongo

  • 退出MongoDB

      exit

  •  远程连接MongoDB

   首先修改MongoDB的监听地址,将配置文件内把 bind_ip=127.0.0.1 这一行注释掉或者是修改成 bind_ip=0.0.0.0

  vim /etc/mongodb.conf

   确保MongoDB的程序启动时,使用以下命令连接使用

  mongo IP:PORT

评论

暂无评论