mogodb 连接异常记录

 

虚拟机为centos6.5,mongodb安装成功,但是宿主级连接一直报connect refused。

解决方法:1、查询是否虚拟机防火墙没关

以下来自linux公社内容    https://www.linuxidc.com/Linux/2016-12/138979.htm

查看防火墙状态:$service iptable status

CentOS 6.5关闭防火墙

1

2

[root@localhost ~]#servcie iptables stop                    --临时关闭防火墙

[root@localhost ~]#chkconfig iptables off                    --永久关闭防火墙

从centos7开始使用systemctl来管理服务和程序,包括了service和chkconfig。

1

2

[root@localhost ~]#systemctl list-unit-files|grep firewalld.service            --防火墙处于关闭状态

firewalld.service                          disabled

  或者

1

2

3

4

[root@localhost ~]#systemctl status firewalld.service

● firewalld.service - firewalld - dynamic firewall daemon

   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)

   Active: inactive (dead)

   关闭防火墙:

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...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值