远程连接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添加 ...
随机推荐
- 2. UITest相关APIs
1. XCUIApplication 这是你正在测试的应用的代理.它能让你启动应用,这样你就能执行测试了.它每次都会新起一个进程,这会多花一些时间,但是能保证测试应用时的状态是干净的,这样你需要处理的 ...
- DOM编程练习(慕课网题目)
编程练习 制作一个表格,显示班级的学生信息. 要求: 1. 鼠标移到不同行上时背景色改为色值为 #f2f2f2,移开鼠标时则恢复为原背景色 #fff 2. 点击添加按钮,能动态在最后添加一行 3. 点 ...
- 微信小程序 插件介绍
小程序的插件是对一组js接口.自定义组件或页面的封装.插件不能独立运行,必须嵌入在其他小程序中才能被用户使用:而第三方小程序在使用插件时,也无法看到插件的代码.因此,插件适合用来封装自己的功能或服务, ...
- #pragma使用分析
#pragma简介 #pragma用于指示编译器完成一些特定的动作 #pragma所定义的很多指示字是编译器特有的 #pragma在不同的编译器间是不可移植的 预处理器将忽略它不认识的#pragma指 ...
- 架包Error inflating class错误
当引用架包后,出现Error inflating class错误时通常要检测架包是否正确引用: 1.首先将你所需要的架包拷贝到工程目录下: 2.右击工程,选择Build Path-->confi ...
- UART协议
通用异步收发传输器(Universal Asynchronous Receiver/Transmitter,通常称作UART,读音/ˈjuːart/)是一种异步收发传输器,是电脑硬件的一部分,将资料由 ...
- configure: error: MySQL library not found
在CentOS系统中,安装zabbix进行configure时会遇到以下问题 ./configure --enable-server --enable-agent --with-mysql --wit ...
- Java进化的尽头
转载需声明:原文链接网址:http://www.artima.com/weblogs/viewpost.jsp?thread=221903 Java: Evolutionary Dead End 我在 ...
- 计算1至n的k次方的和
package com.ywx.count; import java.util.Scanner; /** * @author Vashon * date:20150410 * 题目:计算1至n的k次方 ...
- 开启server-status失败
近日在配置监控宝的apache监控老是出错,经过研究发现如下: 下面先做一些简要的介绍,以防以后查看之用. 一.server-status是什么?二.如何打开server-status?三.serve ...