当前位置: 首页 > 知识库问答 >
问题:

IPTables问题:无法连接到mongoDB w/mongo shell-CentOS

高迪
2023-03-14

我在连接mongo shell时遇到问题。当我从iptable中删除所有指令时,我可以成功连接。CentOS 6.5,mongod正在运行。这是我得到的错误:

[samir@core ~]$ mongo 127.0.0.1:27017
MongoDB shell version: 2.4.9
connecting to: 127.0.0.1:27017/test
Wed Mar 12 00:42:12.193 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:147
exception: connect failed

我也试着从蒙哥开始。

Mongod正在运行:

[samir@core ~]$ sudo service mongod start
Starting mongod: about to fork child process, waiting until server is ready for connections.
forked process: 2104
all output going to: /var/log/mongo/mongod.log
child process started successfully, parent exiting
                                                           [  OK  ]

mongo日志也没有给出任何指向:

***** SERVER RESTARTED *****


Wed Mar 12 00:44:30.634 [initandlisten] MongoDB starting : pid=2104 port=27017 dbpath=/var/lib/mongo 64-bit host=core.datafit.io
Wed Mar 12 00:44:30.634 [initandlisten] db version v2.4.9
Wed Mar 12 00:44:30.634 [initandlisten] git version: 52fe0d21959e32a5bdbecdc62057db386e4e029c
Wed Mar 12 00:44:30.634 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Wed Mar 12 00:44:30.634 [initandlisten] allocator: tcmalloc
Wed Mar 12 00:44:30.634 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", pidfilepath: "/var/run/mongodb/mongod.pid" }
Wed Mar 12 00:44:30.639 [initandlisten] journal dir=/var/lib/mongo/journal
Wed Mar 12 00:44:30.640 [initandlisten] recover : no journal files present, no recovery needed
Wed Mar 12 00:44:30.725 [FileAllocator] allocating new datafile /var/lib/mongo/local.ns, filling with zeroes...
Wed Mar 12 00:44:30.725 [FileAllocator] creating directory /var/lib/mongo/_tmp
Wed Mar 12 00:44:30.738 [FileAllocator] done allocating datafile /var/lib/mongo/local.ns, size: 16MB,  took 0.011 secs
Wed Mar 12 00:44:30.738 [FileAllocator] allocating new datafile /var/lib/mongo/local.0, filling with zeroes...
Wed Mar 12 00:44:30.753 [FileAllocator] done allocating datafile /var/lib/mongo/local.0, size: 64MB,  took 0.014 secs
Wed Mar 12 00:44:30.755 [initandlisten] waiting for connections on port 27017
Wed Mar 12 00:44:30.756 [websvr] admin web console waiting for connections on port 28017

我的 IPTables 如下所示:

Chain INPUT (policy DROP 49 packets, 3315 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 1665  130K ACCEPT     all  --  eth0   any     anywhere             anywhere            state RELATED,ESTABLISHED 
    2   128 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:ssh 
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:http 
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:https 
   18  1080 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:27017 
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:28017 

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 987 packets, 156K bytes)
 pkts bytes target     prot opt in     out     source               destination         

如果我将输入指令设置为ACCEPT,mongo shell会工作:

[samir@core db]$ sudo mongo
MongoDB shell version: 2.4.9
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
> 

Netstat -pln | rep 27017:

[samir@core db]$ sudo netstat -pln | grep 27017 
tcp        0      0 0.0.0.0:27017               0.0.0.0:*                   LISTEN      2178/mongod         
unix  2      [ ACC ]     STREAM     LISTENING     12125  2178/mongod         /tmp/mongodb-27017.sock

我的 iptables 输入策略一定有问题。有什么想法吗?

共有1个答案

温举
2023-03-14

你也许想试试,替换这条线

iptables -A INPUT -s 127.0.0.1 -j ACCEPT

随着

iptables -A INPUT -i lo -j ACCEPT
 类似资料:
  • 刚刚在centos 6上安装了mongodb。尝试用命令“mongo”连接mongo sh却得到这个错误消息:2015-09-26T07:07:35.309 0000 W网络在5000毫秒后连接127.0.0.1:27017失败,放弃。2015-09-26T07:07:35.316 0000 E查询错误:无法连接到服务器127.0.0.1:27017 (127.0.0.1),连接尝试在连接时失败(

  • 在与docker和kafka的基础上磕磕绊绊,无法获得客户端连接 到目前为止我所做的 docker-机器活动,不返回活动主机 我的groovy类(从一个示例中剪切和粘贴,连接如下所示 当我运行这个init时,我得到的错误是它不能解析连接,因为java.io.ioException:不能解析地址:7BF9F9278E64:9092,这是内部容器端口。(我的脚本正在从我的普通IDE桌面环境中调用) 感

  • 它正在显示这个,看这里的图像。

  • 我正在尝试运行以下示例代码段 当我运行这段代码时,出现以下错误。 45000 ms后无法连接到端口7055上的主机127.0.0.1。Firefox控制台输出: Firfox版本是48.0 Jar,eclipse中添加的是selenium-java-2.53.0、selenium-java-2.53.0-srcs。 谁能帮我解决这个问题。

  • Hbase运行不完美,我在尝试在Hbase上创建表时遇到问题,当然我无法访问上的Hbase状态UI。请帮助!! 以下是我的所有配置文件: (hadoop conf)core-site.xml:(主服务器和从服务器配置相同)

  • 问题内容: 我正在尝试使用Ruby on Rails运行Selenium的示例脚本。我必须使用代理运行它。这是我的代码: 我收到以下错误: 有人能帮我吗…?我已经尝试了好几个小时,却找不到问题…真的不知道该怎么办。 环境: Ubuntu 16.04 LTS,Firefox 45.0,rbenv 2.3.1 另一个问题:有人知道Selenium + Ruby on Rails的示例吗?我找不到真正好