远程连接mongodb时,27017端口连接不上的解决办法
一、背景描述:
我在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的官方步骤:
四、关于RED 7中关闭防火墙命令的描述如下:
http://linux.it.net.cn/CentOS/fast/2014/1102/7635.html
远程连接mongodb时,27017端口连接不上的解决办法的更多相关文章
- 远程连接Windows2008R2时服务器报Terminal Services错误的解决办法
症状: 使用终端服务客户端连接到Windows Server2008 R2的机器时,如果客户端选项中选择了打印机(注1)时,它可能会在在系统事件日志中记录一个TerminalServices打印机错误 ...
- 关于在运行java连接MongoDB时遇到的连接超时问题
在linux虚拟机里运行创建集合的时候,遇到了以下问题: 这里我最开始时使用的虚拟机IP地址进行连接,因此就出现了错误,连接超时. 在网上查了一些类似的问题,说要改驱动,后来才发现不是这个问题. 在本 ...
- 使用mysql连接django时,需要的步骤以及错误解决办法
django默认使用的sqlite3,更改为SQL时需要按照如下操作进行 1.在settings.py中的78行进行更改 DATABASES = { 'default': { 'ENGINE': 'd ...
- centos7 远程连接mongodb时,27017端口连接不上的解决办法
一.问题描述:centos 7 上安装mongogdb,然后通过另外一台电脑用pymongo连接mongodb时,报错:连接拒绝 解决过程: 1.修改mongo.conf文件 命令:sudo vi ...
- Vue中使用echarts,ajax请求的远程数据赋值给图表不刷新的问题和解决办法
问题: vue-cli搭建的项目,在mounted钩子函数里面创建echarts图表,本地模拟数据可以正常显示,但是当将ajax请求的远程数据赋值给图表时,图表并不会刷新. 解决办法: 刚开始以为是v ...
- VMware下ubuntu与win8共享文件时/mnt/hgfs目录为空的解决办法
VMware下ubuntu(guest)与win8共享文件时/mnt/hgfs目录为空的解决办法 环境:VMware-player-5.0.2-1031769 + ubuntu13.04 1.安装vm ...
- vs调试windows mobile程序时布署时间太长的解决办法
vs调试windows mobile程序时布署时间太长的解决办法 1.VS平台上,选工具-选项-项目和解决方案-MS BUILD项目生成输出详细信息中选择“诊断”,目的是在调试窗口中看出哪个过程编译的 ...
- Apache 80 端口被占用无法重启解决办法
原文出处 Apache 80 端口被占用无法重启解决办法 www.111cn.net 编辑:tiger 来源:转载使用WEB服务器的朋友都知道80端口是一个用来对外让用户访问的一个端口了,像apach ...
- 向SDE图层中添加大量数据时,出现ORA-00604以及ORA-01000的解决办法
转自原文 向SDE图层中添加大量数据时,出现ORA-00604以及ORA-01000的解决办法 写了一个小程序,从一个列表中读取坐标串,每个坐标串生成一个IPolygon,然后将这些Polygon添加 ...
随机推荐
- 你干啥的?Lombok
01.Lombok 的自我介绍 Lombok 在官网是这样作自我介绍的: Project Lombok makes java a spicier language by adding 'handler ...
- cordova应用使用手机调试
对于cordova应用的调试,最方便调试方式还是作为h5应用在浏览器来调试,调试好了再打包cordova应用和打包apk.然而h5应用时的效果跟最终在安卓手机运行还有少数情况会不一样,因此,也需要有能 ...
- myeclipse 安装svn(subeclipsesite)插件
(1)到官网下载subeclipsesite,下载最新的版本:http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=224 ...
- [Python學習筆記] 在Centos上安裝 Django
曾在模擬器跟Digital Ocean上安裝成功,我在 Digital Ocean上的是CentOS 7 x64,模擬器的則是Centos 6.雖然Centos 本身已經裝好 Python 但是是2. ...
- 基于SAE的Python+Django部署
本文主要参考:http://www.cnblogs.com/qtsharp/archive/2012/01/12/2320774.html,另外包括自己的实际操作. 一.申请SAE帐号以及创建应用ya ...
- css广告弹窗满屏跑
window.onload=function(){ //广告滚动 var oneInner = $('#divid')[0]; //定时器 var a1a = setInterval(moves,10 ...
- js 数组过滤 filter
let res = this.list.filter(item => routeEqual(this.currentRouteObj, item) || item.name === this.$ ...
- Vue的 $parent,并不能准确找到上一层的控件,所以如果需要,需要填坑这个 bug,递归寻找下上级
Vue的 $parent,并不能准确找到上一层的控件,所以如果需要,需要填坑这个 bug,递归寻找下上级 // Find components upward function findComponen ...
- DLL动态链接库的创建
dll的创建主要有两种方法:一是使用 __declspec(dllexport) 创建dll,二是使用模块定义(.def)文件创建dll. 使用 __declspec(dllexport) 创建dll ...
- OpenCV2:第十章 视频操作
一.简介 OpenCV提供了专门操作视频的接口类VideoCapture 二.构造VideoCapture类 VideoCapture::VideoCapture() VideoCapture::Vi ...