虚拟机为centos6.5,mongodb安装成功,但是宿主级连接一直报connect refused。
解决方法:1、查询是否虚拟机防火墙没关
以下来自linux公社内容 https://www.linuxidc.com/Linux/2016-12/138979.htm
查看防火墙状态:$service iptable status
CentOS 6.5关闭防火墙
1 2 |
|
从centos7开始使用systemctl来管理服务和程序,包括了service和chkconfig。
1 2 |
|
或者
1 2 3 4 |
|
关闭防火墙:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
2、配置mogodb变量
自定义文件mongodb.conf
内容添加 :
bind_id = 0.0.0.0
意思是允许所有IP连接。也可以配置固定ip
mondodb启动命令:
* --dbpath 数据存放目录
* --port 端口号
* --config 自定义配置引入 mongodb.conf 添加 bind_id = 0.0.0.0
* --fork 后台运行,,配置后台运行必须配置logpath
* --logpath 日志地址
以下为启动命令:
* ./mongod --dbpath /usr/system/mongo/mongodb-linux-x86_64-4.0.9/data/ --port 27017
* --config /usr/system/mongo/mongodb-linux-x86_64-4.0.9/bin/mongodb.conf --fork
* --logpath /usr/system/mongo/mongodb-linux-x86_64-4.0.9/mongo.log
*/
mongodb停止服务:
方法一:查看进程,使用kill命令;不能使用kill -9
方法二:在客户端进去,使用shutdown命令
> use admin; switched to db admin > db.shutdownServer(); server should be down...