远程连接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添加 ...
随机推荐
- SQL Server中的事务日志管理的阶梯,级别1:事务日志概述
SQL Server中的事务日志管理的阶梯,级别1:事务日志概述 翻译:刘琼滨 谢雪妮 许雅莉 赖慧芳 级别1:事务日志概述 事务日志是一个文件,其中SQL服务器存储了所有与日志文件关联的数据库执行的 ...
- SAP云平台架构概述
在我们开始SAP云平台的架构之旅之前,让我们先看看SAP已经发布的一些其他云产品.这些云产品方案可以分为公有云和私有云两种. SAP公有云解决方案见下图最右侧,比较著名的有SAP SuccessFac ...
- 用python+pygame写贪吃蛇小游戏
因为python语法简单好上手,前两天在想能不能用python写个小游戏出来,就上网搜了一下发现了pygame这个写2D游戏的库.了解了两天再参考了一些资料就开始写贪吃蛇这个小游戏. 毕竟最开始的练手 ...
- ElasticSearch数据库同步插件logstash
1.下载和elasticsearch 相同版本的logstash. 2.进行解压后,进入bin下,新建一个文件mysql.conf,并输入 input { stdin{ }} output { std ...
- python基础一 day6 文件操作
读写只会进行两步, r+模式下写读 seek是按字节去找的 for line in f: for循环是一行一行的读取出来 strip默认去空格和换行符 空格.制表符.换行符.回车.换页垂直制表符和换行 ...
- Gear Pump: Why Install A Pressure Reducing Valve?
When the Gear Pump Manufacturers prompts to install a gear pump, the following points should ...
- JavaSE-30 BigDecimal类的使用
问题 Java(其他编程语言也存在类似问题)中浮点数直接进行算术运算会导致精度丢失. 示例代码: System.out.println("1.0 - 0.9 =" + (1.0 - ...
- 02.28 day03
print(1 or 3 > 2 and 4 < 5 or 6 and 2 < 7)## while True:# print(11)# print(22)# # break# # ...
- 转: 使用 /sys 文件系统访问 Linux 内核
转一个挺不错的文章 使用 /sys 文件系统访问 Linux 内核 https://www.ibm.com/developerworks/cn/linux/l-cn-sysfs/ 如果你正在开发的设备 ...
- Could not resolve dependencies for project com.shadow:shlang:jar:1.0-SNAPSHOT:
maven打包项目出现缺少jar包错误 如果是将本地引用的jar包放在了lib目录下并通过下面方式引入 解决方案为 <dependency> <groupId>com.o ...