Linux安装MongoDB

本文基于centos6安装mongod 3

添加repo

vim /etc/yum.repos.d/mongodb-org-3.6.repo

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

安装

sudo yum install -y mongodb-org

开放端口

SELinux

如果安装了SELinux

semanage port -a -t mongod_port_t -p tcp 27017

或者直接关闭 /etc/selinux/config

SELINUX=disabled

mongodb配置绑定ip

默认绑定端口为本机,可以指定ip,也可以开放所有。下面开放所有

vim /etc/mongod.conf

net:
  port: 27017
  bindIp: 0.0.0.0

如果指定ip

net:
  port: 27017
  bindIp: 127.0.0.1,192.168.1.100

重启

service mongod restart

centos6开放ip端口

vim /etc/sysconfig/iptables 添加

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

重启

service iptables restart

测试启动

启动

sudo service mongod start

重启

sudo service mongod restart

本机连接

mongo

远程连接

mongo --host 192.168.2.125:27017

查看db

> show dbs;
admin   0.000GB
config  0.000GB
local   0.000GB

进入db

> use config
switched to db config

查看当前db

> db
config

查看集合

> show collections
system.sessions

参考

http://www.cnblogs.com/woshimrf/p/5503228.html

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

posted @ 2018-05-28 19:18  Ryan.Miao  阅读(1325)  评论(0编辑  收藏  举报