一、背景描述:

我在linux  RED7上安装了mongodb,并没有修改mongodb的配置文件。然后通过另外一台电脑用pymongo连接mongodb时,报错:timeout。

ping IP 是成功的。 telnet IP 27017 的时候,提示:27017端口连接不上。

二、解决过程:

各种百度,远程连接mongodb失败,网上资料显示原因有两个:

1、mongodb的配置文件中的bind_ip 默认为127.0.0.1,默认只有本机可以连接。  此时,需要将bind_ip配置为0.0.0.0,表示接受任何IP的连接。

2、防火墙阻止了27017端口。

于是,先修改mongodb配置文件,并重启mongod服务。

各种百度关闭防火墙。

-----------但是试了很久很久,仍然telnet时提示:27017端口连接不上。

使用google,发现如下文章:http://shaurong.blogspot.com/2014/07/centos-70-x64.html

解决了我的问题。重点是由于在RED7中,关闭防火墙的命令改为:systemctl stop firewalld

这样后,便可以真正关闭防火墙功能。远程连接mongodb成功!

上述连接:http://shaurong.blogspot.com/2014/07/centos-70-x64.html 内容如下(需翻 墙才可访问,所以就把原文复制过来了。望原作者莫见怪!):

 [研究] CentOS 7.0 x64 的 iptables 與 firewall-cmd 防火牆
[研究] CentOS 7.0 x64 的 iptables 與 firewall-cmd 防火牆 --
-- 修訂 CentOS 7.0 開始,服務的管理使用變成用 systemctl,例如 httpd 的使用可用下面幾種方式 # systemctl status|start|stop|restart|reload httpd
OR
# service httpd status|start|stop|restart|reload
OR
# apachectl configtest| graceful service httpd 會自動重導指令到 systemctl 命令,問題不大。 但是防火牆就有問題了,因為架網站時本機測試正常,遠端關了防火牆卻仍連不上,所以做了點研究測試。 [root@localhost ~]# yum -y install httpd
[root@localhost ~]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service
[root@localhost ~]# service httpd status
Redirecting to /bin/systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
Active: active (running) since Fri -- :: CST; 21s ago
Main PID: (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
? ? /usr/sbin/httpd -DFOREGROUND
? ? /usr/sbin/httpd -DFOREGROUND
? ? /usr/sbin/httpd -DFOREGROUND
? ? /usr/sbin/httpd -DFOREGROUND
? ? /usr/sbin/httpd -DFOREGROUND
? ? /usr/sbin/httpd -DFOREGROUND Jul :: localhost.localdomain systemd[]: Starting The Apache HTTP Se...
Jul :: localhost.localdomain httpd[]: AH00558: httpd: Could not...
Jul :: localhost.localdomain systemd[]: Started The Apache HTTP Ser...
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# ps aux | grep httpd
root 0.0 0.2 ? Ss : : /usr/sbin/http -DFOREGROUND
apache 0.0 0.1 ? S : : /usr/sbin/http -DFOREGROUND
apache 0.0 0.1 ? S : : /usr/sbin/http -DFOREGROUND
apache 0.0 0.1 ? S : : /usr/sbin/http -DFOREGROUND
apache 0.0 0.1 ? S : : /usr/sbin/http -DFOREGROUND
apache 0.0 0.1 ? S : : /usr/sbin/http -DFOREGROUND
root 0.0 0.0 pts/ R+ : : grep --color=auto httpd
[root@localhost ~]# [root@localhost ~]# service iptables stop
Redirecting to /bin/systemctl stop iptables.service (下圖) 本機上測試正常 (下圖) 遠端去連失敗 檢查防火牆狀態,是 inactive 的 [root@localhost ~]# service iptables -L
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl. [root@localhost ~]# service iptables status
Redirecting to /bin/systemctl status iptables.service
iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled)
Active: inactive (dead) Jul :: localhost.localdomain systemd[]: Stopped IPv4 firewall with ...
Hint: Some lines were ellipsized, use -l to show in full. 列出防火牆 rules,居然仍有 [root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
INPUT_direct all -- anywhere anywhere
INPUT_ZONES_SOURCE all -- anywhere anywhere
INPUT_ZONES all -- anywhere anywhere
ACCEPT icmp -- anywhere anywhere
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
FORWARD_direct all -- anywhere anywhere
FORWARD_IN_ZONES_SOURCE all -- anywhere anywhere
FORWARD_IN_ZONES all -- anywhere anywhere
FORWARD_OUT_ZONES_SOURCE all -- anywhere anywhere
FORWARD_OUT_ZONES all -- anywhere anywhere
ACCEPT icmp -- anywhere anywhere
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)
target prot opt source destination
OUTPUT_direct all -- anywhere anywhere Chain FORWARD_IN_ZONES ( references)
target prot opt source destination
FWDI_public all -- anywhere anywhere [goto]
FWDI_public all -- anywhere anywhere [goto] Chain FORWARD_IN_ZONES_SOURCE ( references)
target prot opt source destination Chain FORWARD_OUT_ZONES ( references)
target prot opt source destination
FWDO_public all -- anywhere anywhere [goto]
FWDO_public all -- anywhere anywhere [goto] Chain FORWARD_OUT_ZONES_SOURCE ( references)
target prot opt source destination Chain FORWARD_direct ( references)
target prot opt source destination Chain FWDI_public ( references)
target prot opt source destination
FWDI_public_log all -- anywhere anywhere
FWDI_public_deny all -- anywhere anywhere
FWDI_public_allow all -- anywhere anywhere Chain FWDI_public_allow ( references)
target prot opt source destination Chain FWDI_public_deny ( references)
target prot opt source destination Chain FWDI_public_log ( references)
target prot opt source destination Chain FWDO_public ( references)
target prot opt source destination
FWDO_public_log all -- anywhere anywhere
FWDO_public_deny all -- anywhere anywhere
FWDO_public_allow all -- anywhere anywhere Chain FWDO_public_allow ( references)
target prot opt source destination Chain FWDO_public_deny ( references)
target prot opt source destination Chain FWDO_public_log ( references)
target prot opt source destination Chain INPUT_ZONES ( references)
target prot opt source destination
IN_public all -- anywhere anywhere [goto]
IN_public all -- anywhere anywhere [goto] Chain INPUT_ZONES_SOURCE ( references)
target prot opt source destination Chain INPUT_direct ( references)
target prot opt source destination Chain IN_public ( references)
target prot opt source destination
IN_public_log all -- anywhere anywhere
IN_public_deny all -- anywhere anywhere
IN_public_allow all -- anywhere anywhere Chain IN_public_allow ( references)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ctstate NEW Chain IN_public_deny ( references)
target prot opt source destination Chain IN_public_log ( references)
target prot opt source destination Chain OUTPUT_direct ( references)
target prot opt source destination
[root@localhost ~]# 經過研究發現,應該要改用 firewall-cmd 命令 要暫時開放 http port,可執行
# firewall-cmd --add-service=http 要永久開放 http port,可執行
# firewall-cmd --permanent --add-service=http
# systemctl restart firewalld 要停掉
[root@localhost ~]# systemctl stop firewalld 下面確認一下,真的停掉了 [root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination Chain FORWARD (policy ACCEPT)
target prot opt source destination Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost ~]# (下圖) 再從遠端連上網站看看,成功了 也就是 service iptables stop 無法停掉防火牆了 ( 看下面訊息該有支援,Bug 嗎 ?) [root@localhost ~]# service iptables
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl. 設定 httpd 隨作業系統啟動
systemctl enable httpd 其他常用 firewall-cmd 命令 # firewall-cmd --state
# firewall-cmd --list-all
# firewall-cmd --list-interfaces
# firewall-cmd --get-service
# firewall-cmd --query-service service_name
# firewall-cmd --add-port=/tcp (完) 相關 [研究] CentOS 7.0 x64 的網站架設與防火牆
http://shaurong.blogspot.tw/2014/07/centos-linux-701406.html Installing LAMP (Linux, Apache, MariaDB, PHP/PhpMyAdmin) in RHEL/CentOS 7.0
http://www.tecmint.com/install-lamp-in-centos-7/

点击查看文章内容

三、RED7中通过yum安装mongodb的官方步骤:

http://docs.mongodb.org/master/tutorial/install-mongodb-on-red-hat/?_ga=1.11182708.1945386581.1439519252

四、关于RED 7中关闭防火墙命令的描述如下:

http://linux.it.net.cn/CentOS/fast/2014/1102/7635.html

远程连接mongodb时,27017端口连接不上的解决办法的更多相关文章

  1. 远程连接Windows2008R2时服务器报Terminal Services错误的解决办法

    症状: 使用终端服务客户端连接到Windows Server2008 R2的机器时,如果客户端选项中选择了打印机(注1)时,它可能会在在系统事件日志中记录一个TerminalServices打印机错误 ...

  2. 关于在运行java连接MongoDB时遇到的连接超时问题

    在linux虚拟机里运行创建集合的时候,遇到了以下问题: 这里我最开始时使用的虚拟机IP地址进行连接,因此就出现了错误,连接超时. 在网上查了一些类似的问题,说要改驱动,后来才发现不是这个问题. 在本 ...

  3. 使用mysql连接django时,需要的步骤以及错误解决办法

    django默认使用的sqlite3,更改为SQL时需要按照如下操作进行 1.在settings.py中的78行进行更改 DATABASES = { 'default': { 'ENGINE': 'd ...

  4. centos7 远程连接mongodb时,27017端口连接不上的解决办法

    一.问题描述:centos 7 上安装mongogdb,然后通过另外一台电脑用pymongo连接mongodb时,报错:连接拒绝 解决过程: 1.修改mongo.conf文件 命令:sudo  vi  ...

  5. Vue中使用echarts,ajax请求的远程数据赋值给图表不刷新的问题和解决办法

    问题: vue-cli搭建的项目,在mounted钩子函数里面创建echarts图表,本地模拟数据可以正常显示,但是当将ajax请求的远程数据赋值给图表时,图表并不会刷新. 解决办法: 刚开始以为是v ...

  6. VMware下ubuntu与win8共享文件时/mnt/hgfs目录为空的解决办法

    VMware下ubuntu(guest)与win8共享文件时/mnt/hgfs目录为空的解决办法 环境:VMware-player-5.0.2-1031769 + ubuntu13.04 1.安装vm ...

  7. vs调试windows mobile程序时布署时间太长的解决办法

    vs调试windows mobile程序时布署时间太长的解决办法 1.VS平台上,选工具-选项-项目和解决方案-MS BUILD项目生成输出详细信息中选择“诊断”,目的是在调试窗口中看出哪个过程编译的 ...

  8. Apache 80 端口被占用无法重启解决办法

    原文出处 Apache 80 端口被占用无法重启解决办法 www.111cn.net 编辑:tiger 来源:转载使用WEB服务器的朋友都知道80端口是一个用来对外让用户访问的一个端口了,像apach ...

  9. 向SDE图层中添加大量数据时,出现ORA-00604以及ORA-01000的解决办法

    转自原文 向SDE图层中添加大量数据时,出现ORA-00604以及ORA-01000的解决办法 写了一个小程序,从一个列表中读取坐标串,每个坐标串生成一个IPolygon,然后将这些Polygon添加 ...

随机推荐

  1. 2018微软实习笔试一道dp题目总结

    题意大概是说在一维数轴上起点和终点的距离是d,现在我们要从起点走到终点.每走一个单位长度消耗一个单位能量,初始时有K单位能量.同时在起点和终点之间分布一些加油站a1,a2,...an,给你加油站数量. ...

  2. postgresql版sde(10.4.1)安装说明

    从ArcGIS 10.3开始,彻底没有了sde的安装包,安装sde数据库需要先安装arcgis desktop,通过arccatalog建数据库,同时也不能建sde服务,只能使用直连 以下演示在sde ...

  3. (转)在编写Spring框架的配置文件时,标签无提示符的解决办法

    http://blog.csdn.net/yerenyuan_pku/article/details/52831618 问题描述 初学者在学习Spring框架的过程中,大概会碰到这样一个问题:在编写S ...

  4. Android(java)学习笔记160:开发一个多界面的应用程序之清单文件

    清单文件的重要参数:     <intent-filter>             代表的应用程序的入口界面           <action android:name=&quo ...

  5. 【软件构造】第三章第三节 抽象数据型(ADT)

    第三章第三节 抽象数据型(ADT) 3-1节研究了“数据类型”及其特性 ; 3-2节研究了方法和操作的“规约”及其特性:在本节中,我们将数据和操作复合起来,构成ADT,学习ADT的核心特征,以及如何设 ...

  6. myBatis参数处理 myBatis佟刚课程笔记

    单个参数:myBatis不会做特殊处理 #{参数名}: 取出参数值 多个参数: myBatis会做特殊处理 多个参数会被封装成一个MAP key:param1 param2.... param10,或 ...

  7. 《3+1团队》【Alpha】Scrum meeting 1

    项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 3+1团队 团队博客地址 https://home.cnblogs.com/u/3-1group ...

  8. 2019西安多校联训 Day5

    T1 光哥为了不让某初二奆佬恶心到我们而留下的火种 (貌似没这题平均分就100-了) 思路:就一横一竖让后就gztopa嘛 #include <bits/stdc++.h> using n ...

  9. HTTP请求头的具体含意

    为你详细解读HTTP请求头的具体含意 | 浏览:5763 | 更新:2012-03-16 16:41 当我们打开一个网页时,浏览器要向网站服务器发送一个HTTP请求头,然后网站服务器根据HTTP请求头 ...

  10. PTA|团体程序设计天梯赛-练习题目题解锦集(C/C++)(持续更新中……)

    PTA|团体程序设计天梯赛-练习题目题解锦集(持续更新中) 实现语言:C/C++:      欢迎各位看官交流讨论.指导题解错误:或者分享更快的方法!! 题目链接:https://pintia.cn/ ...