CentOS7 MongoDB远程连接步骤

  1. vim /etc/mongod.conf修改默认ip为0.0.0.0
    文件参考:
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0  # Listen to local interface only, comment to listen on all interfaces.


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

  1. 修改防火墙端口,开启MongoDB默认端口27017
    查看27017端口是否开启,yes表示已开启,如果为no需要手动开启端口
    firewall-cmd --query-port=27017/tcp
    如果20717端口未开启,将端口设置为永久开启
    firewall-cmd --zone=public --add-port=27017/tcp --permanent
    设置完成后,重启防火墙
    firewall-cmd --reload
    执行完成,可以重新执行查看命令来查看端口是否开启
  2. 执行mongo 10.0.10.237:27017/admin -u root -p test根据ip地址连接远程数据库

你可能感兴趣的:(Linux)