mongodb服务器连接不上怎么解决?
mongodb服务器连接不上问题如下:
下载好mongodb-linux-x86_64-ubuntu1604-3.4.10.tgz并解压到 /usr/local/mongodb
在根目录下创建路径 /data/db
$ sudo mkdir -p /data/db$ export PATH= /usr/local/mongodb/bin:$PATH
$ mongod
$ mongo
运行报错如下所示:
$ mongod2017-12-04T14:56:11.473+0800 I CONTROL [initandlisten] MongoDB starting : pid=25238 port=27017 dbpath=/data/db 64-bit host=haiyoung
2017-12-04T14:56:11.473+0800 I CONTROL [initandlisten] db version v3.4.10
2017-12-04T14:56:11.473+0800 I CONTROL [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2017-12-04T14:56:11.473+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2017-12-04T14:56:11.473+0800 I CONTROL [initandlisten] allocator: tcmalloc
2017-12-04T14:56:11.473+0800 I CONTROL [initandlisten] modules: none
2017-12-04T14:56:11.473+0800 I CONTROL [initandlisten] build environment:
2017-12-04T14:56:11.473+0800 I CONTROL [initandlisten] distmod: ubuntu1604
2017-12-04T14:56:11.473+0800 I CONTROL [initandlisten] distarch: x86_64
2017-12-04T14:56:11.473+0800 I CONTROL [initandlisten] target_arch: x86_64
2017-12-04T14:56:11.473+0800 I CONTROL [initandlisten] options: {}
2017-12-04T14:56:11.474+0800 I STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2017-12-04T14:56:11.474+0800 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-12-04T14:56:11.474+0800 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-12-04T14:56:11.474+0800 I CONTROL [initandlisten] now exiting
2017-12-04T14:56:11.474+0800 I CONTROL [initandlisten] shutting down with code:100
$ mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
2017-12-04T14:56:21.303+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-12-04T14:56:21.303+0800 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed
问题原因:
原因是,手动创建路径时,没有修改权限。
解决方法:
运行如下命令修改权限:
$ sudo chmod -vR 777 /data
重新启动,连接成功。
二、远程连接不上解决方法
1、mongodb的配置文件中的bind_ip 默认为127.0.0.1,默认只有本机可以连接。 此时,需要将bind_ip配置为0.0.0.0,表示接受任何IP的连接。
2、防火墙阻止了27017端口。
于是,先修改mongodb配置文件,并重启mongod服务。
关闭防火墙或者设置防火墙27017端口可访问。
以上是 mongodb服务器连接不上怎么解决? 的全部内容, 来源链接: utcz.com/z/538965.html