我从mongdb开始
然后按照说明安装了mongdb
https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-centos-7
在不丢失任何步骤的情况下,我也导入了数据
但是当我连接到数据时,出现以下错误
MongoNetworkError: failed to connect to server 149.28.156.203:27017 on first connect
MongoNetworkError: connect EHOSTUNREACH 149.28.156.203:27017
https://i.stack.imgur.com/FdSGA.png
我为数据测试创建了另一个用户
db.createUser({ user: "username", pwd: "password", roles: [ { role: "readWrite", db: "test" } ] })
信息
Mongodb正在运行
# systemctl status mongod
mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since T5 2019-02-21 08:47:02 UTC; 3min 55s ago
Docs: https://docs.mongodb.org/manual
Process: 26534 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
Process: 26532 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 26530 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 26528 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Main PID: 26537 (mongod)
CGroup: /system.slice/mongod.service
└─26537 /usr/bin/mongod -f /etc/mongod.conf
连接时的用户,密码,数据名和IP没错
mongodb://username:password@149.28.156.203:27017/?authSource=test
#mongo
MongoDB shell version v3.4.19
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.19
Server has startup warnings:
2019-02-21T08:47:02.120+0000 I STORAGE [initandlisten]
2019-02-21T08:47:02.120+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-02-21T08:47:02.120+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-02-21T08:47:02.687+0000 I CONTROL [initandlisten]
2019-02-21T08:47:02.687+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-02-21T08:47:02.687+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-02-21T08:47:02.687+0000 I CONTROL [initandlisten]
2019-02-21T08:47:02.687+0000 I CONTROL [initandlisten]
2019-02-21T08:47:02.687+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-02-21T08:47:02.687+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-02-21T08:47:02.687+0000 I CONTROL [initandlisten]
2019-02-21T08:47:02.687+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-02-21T08:47:02.687+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-02-21T08:47:02.687+0000 I CONTROL [initandlisten]
文件/etc/mongo.conf
# 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: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
Mongo日志
2019-02-21T09:23:36.131+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-02-21T09:23:36.131+0000 I CONTROL [initandlisten]
2019-02-21T09:23:36.131+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-02-21T09:23:36.131+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-02-21T09:23:36.131+0000 I CONTROL [initandlisten]
2019-02-21T09:23:36.134+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongo/diagnostic.data'
2019-02-21T09:23:36.139+0000 I NETWORK [thread1] waiting for connections on port 27017
2019-02-21T09:24:03.773+0000 I NETWORK [thread1] connection accepted from 127.0.0.1:54348 #1 (1 connection now open)
2019-02-21T09:24:03.774+0000 I NETWORK [conn1] received client metadata from 127.0.0.1:54348 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.19" }, os: { type: "Linux", name: "CentOS Linux release 7.6.1810 (Core) ", architecture: "x86_64", version: "Kernel 3.10.0-957.1.3.el7.x86_64" } }
2019-02-21T09:29:00.515+0000 I - [conn1] end connection 127.0.0.1:54348 (1 connection now open)
那原因在哪里?