当前位置:Gxlcms > 数据库问题 > 远程连接mongodb时,27017端口连接不上的解决办法

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

时间:2021-07-01 10:21:17 帮助过:7人阅读

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

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

技术分享
  1. [研究] CentOS <span style="color: #800080;">7.0</span> x64 的 iptables 與 firewall-<span style="color: #000000;">cmd 防火牆
  2. [研究] CentOS </span><span style="color: #800080;">7.0</span> x64 的 iptables 與 firewall-<span style="color: #000000;">cmd 防火牆
  3. </span><span style="color: #800080;">2014</span>-<span style="color: #800080;">07</span>-<span style="color: #800080;">25</span>
  4. <span style="color: #800080;">2014</span>-<span style="color: #800080;">08</span>-<span style="color: #800080;">01</span><span style="color: #000000;"> 修訂
  5. CentOS </span><span style="color: #800080;">7.0</span><span style="color: #000000;"> 開始,服務的管理使用變成用 systemctl,例如 httpd 的使用可用下面幾種方式
  6. # systemctl status</span>|start|stop|restart|<span style="color: #000000;">reload httpd
  7. OR
  8. # service httpd status</span>|start|stop|restart|<span style="color: #000000;">reload
  9. OR
  10. # apachectl configtest</span>|<span style="color: #000000;"> graceful
  11. service httpd 會自動重導指令到 systemctl 命令,問題不大。
  12. 但是防火牆就有問題了,因為架網站時本機測試正常,遠端關了防火牆卻仍連不上,所以做了點研究測試。
  13. [root@localhost </span>~]# yum -<span style="color: #000000;">y install httpd
  14. [root@localhost </span>~<span style="color: #000000;">]# service httpd restart
  15. Redirecting to </span>/bin/<span style="color: #000000;">systemctl restart httpd.service
  16. [root@localhost </span>~<span style="color: #000000;">]# service httpd status
  17. Redirecting to </span>/bin/<span style="color: #000000;">systemctl status httpd.service
  18. httpd.service </span>-<span style="color: #000000;"> The Apache HTTP Server
  19. Loaded: loaded (</span>/usr/lib/systemd/system/<span style="color: #000000;">httpd.service; disabled)
  20. Active: active (running) since Fri </span><span style="color: #800080;">2014</span>-<span style="color: #800080;">07</span>-<span style="color: #800080;">25</span> <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span>:<span style="color: #800080;">58</span><span style="color: #000000;"> CST; 21s ago
  21. Main PID: </span><span style="color: #800080;">14250</span><span style="color: #000000;"> (httpd)
  22. Status: </span><span style="color: #800000;">"</span><span style="color: #800000;">Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec</span><span style="color: #800000;">"</span><span style="color: #000000;">
  23. CGroup: </span>/system.slice/<span style="color: #000000;">httpd.service
  24. </span>? ? <span style="color: #800080;">14250</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
  25. </span>? ? <span style="color: #800080;">14251</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
  26. </span>? ? <span style="color: #800080;">14252</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
  27. </span>? ? <span style="color: #800080;">14253</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
  28. </span>? ? <span style="color: #800080;">14254</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
  29. </span>? ? <span style="color: #800080;">14255</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
  30. Jul </span><span style="color: #800080;">25</span> <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span>:<span style="color: #800080;">58</span> localhost.localdomain systemd[<span style="color: #800080;">1</span><span style="color: #000000;">]: Starting The Apache HTTP Se...
  31. Jul </span><span style="color: #800080;">25</span> <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span>:<span style="color: #800080;">58</span> localhost.localdomain httpd[<span style="color: #800080;">14250</span><span style="color: #000000;">]: AH00558: httpd: Could not...
  32. Jul </span><span style="color: #800080;">25</span> <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span>:<span style="color: #800080;">58</span> localhost.localdomain systemd[<span style="color: #800080;">1</span><span style="color: #000000;">]: Started The Apache HTTP Ser...
  33. Hint: Some lines were ellipsized, use </span>-l to show <span style="color: #0000ff;">in</span><span style="color: #000000;"> full.
  34. [root@localhost </span>~]# ps aux |<span style="color: #000000;"> grep httpd
  35. root </span><span style="color: #800080;">14250</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.2</span> <span style="color: #800080;">209484</span> <span style="color: #800080;">4804</span> ? Ss <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
  36. apache </span><span style="color: #800080;">14251</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.1</span> <span style="color: #800080;">211568</span> <span style="color: #800080;">2968</span> ? S <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
  37. apache </span><span style="color: #800080;">14252</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.1</span> <span style="color: #800080;">211568</span> <span style="color: #800080;">2968</span> ? S <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
  38. apache </span><span style="color: #800080;">14253</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.1</span> <span style="color: #800080;">211568</span> <span style="color: #800080;">2968</span> ? S <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
  39. apache </span><span style="color: #800080;">14254</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.1</span> <span style="color: #800080;">211568</span> <span style="color: #800080;">2968</span> ? S <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
  40. apache </span><span style="color: #800080;">14255</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.1</span> <span style="color: #800080;">211568</span> <span style="color: #800080;">2968</span> ? S <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
  41. root </span><span style="color: #800080;">14276</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">112640</span> <span style="color: #800080;">980</span> pts/<span style="color: #800080;">1</span> R+ <span style="color: #800080;">15</span>:<span style="color: #800080;">55</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> grep --color=<span style="color: #000000;">auto httpd
  42. [root@localhost </span>~<span style="color: #000000;">]#
  43. [root@localhost </span>~<span style="color: #000000;">]# service iptables stop
  44. Redirecting to </span>/bin/<span style="color: #000000;">systemctl stop iptables.service
  45. (下圖) 本機上測試正常
  46. (下圖) 遠端去連失敗
  47. 檢查防火牆狀態,是 inactive 的
  48. [root@localhost </span>~]# service iptables -<span style="color: #000000;">L
  49. The service command supports only basic LSB actions (start, stop, restart, </span><span style="color: #0000ff;">try</span>-restart, reload, force-reload, status). For other actions, please <span style="color: #0000ff;">try</span><span style="color: #000000;"> to use systemctl.
  50. [root@localhost </span>~<span style="color: #000000;">]# service iptables status
  51. Redirecting to </span>/bin/<span style="color: #000000;">systemctl status iptables.service
  52. iptables.service </span>-<span style="color: #000000;"> IPv4 firewall with iptables
  53. Loaded: loaded (</span>/usr/lib/systemd/system/<span style="color: #000000;">iptables.service; disabled)
  54. Active: inactive (dead)
  55. Jul </span><span style="color: #800080;">25</span> <span style="color: #800080;">15</span>:<span style="color: #800080;">56</span>:<span style="color: #800080;">53</span> localhost.localdomain systemd[<span style="color: #800080;">1</span><span style="color: #000000;">]: Stopped IPv4 firewall with ...
  56. Hint: Some lines were ellipsized, use </span>-l to show <span style="color: #0000ff;">in</span><span style="color: #000000;"> full.
  57. 列出防火牆 rules,居然仍有
  58. [root@localhost </span>~]# iptables -<span style="color: #000000;">L
  59. Chain INPUT (policy ACCEPT)
  60. target prot opt source destination
  61. ACCEPT all </span>--<span style="color: #000000;"> anywhere anywhere ctstate RELATED,ESTABLISHED
  62. ACCEPT all </span>--<span style="color: #000000;"> anywhere anywhere
  63. INPUT_direct all </span>--<span style="color: #000000;"> anywhere anywhere
  64. INPUT_ZONES_SOURCE all </span>--<span style="color: #000000;"> anywhere anywhere
  65. INPUT_ZONES all </span>--<span style="color: #000000;"> anywhere anywhere
  66. ACCEPT icmp </span>--<span style="color: #000000;"> anywhere anywhere
  67. REJECT all </span>-- anywhere anywhere reject-with icmp-host-<span style="color: #000000;">prohibited
  68. Chain FORWARD (policy ACCEPT)
  69. target prot opt source destination
  70. ACCEPT all </span>--<span style="color: #000000;"> anywhere anywhere ctstate RELATED,ESTABLISHED
  71. ACCEPT all </span>--<span style="color: #000000;"> anywhere anywhere
  72. FORWARD_direct all </span>--<span style="color: #000000;"> anywhere anywhere
  73. FORWARD_IN_ZONES_SOURCE all </span>--<span style="color: #000000;"> anywhere anywhere
  74. FORWARD_IN_ZONES all </span>--<span style="color: #000000;"> anywhere anywhere
  75. FORWARD_OUT_ZONES_SOURCE all </span>--<span style="color: #000000;"> anywhere anywhere
  76. FORWARD_OUT_ZONES all </span>--<span style="color: #000000;"> anywhere anywhere
  77. ACCEPT icmp </span>--<span style="color: #000000;"> anywhere anywhere
  78. REJECT all </span>-- anywhere anywhere reject-with icmp-host-<span style="color: #000000;">prohibited
  79. Chain OUTPUT (policy ACCEPT)
  80. target prot opt source destination
  81. OUTPUT_direct all </span>--<span style="color: #000000;"> anywhere anywhere
  82. Chain FORWARD_IN_ZONES (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  83. target prot opt source destination
  84. FWDI_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
  85. FWDI_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
  86. Chain FORWARD_IN_ZONES_SOURCE (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  87. target prot opt source destination
  88. Chain FORWARD_OUT_ZONES (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  89. target prot opt source destination
  90. FWDO_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
  91. FWDO_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
  92. Chain FORWARD_OUT_ZONES_SOURCE (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  93. target prot opt source destination
  94. Chain FORWARD_direct (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  95. target prot opt source destination
  96. Chain FWDI_public (</span><span style="color: #800080;">2</span><span style="color: #000000;"> references)
  97. target prot opt source destination
  98. FWDI_public_log all </span>--<span style="color: #000000;"> anywhere anywhere
  99. FWDI_public_deny all </span>--<span style="color: #000000;"> anywhere anywhere
  100. FWDI_public_allow all </span>--<span style="color: #000000;"> anywhere anywhere
  101. Chain FWDI_public_allow (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  102. target prot opt source destination
  103. Chain FWDI_public_deny (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  104. target prot opt source destination
  105. Chain FWDI_public_log (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  106. target prot opt source destination
  107. Chain FWDO_public (</span><span style="color: #800080;">2</span><span style="color: #000000;"> references)
  108. target prot opt source destination
  109. FWDO_public_log all </span>--<span style="color: #000000;"> anywhere anywhere
  110. FWDO_public_deny all </span>--<span style="color: #000000;"> anywhere anywhere
  111. FWDO_public_allow all </span>--<span style="color: #000000;"> anywhere anywhere
  112. Chain FWDO_public_allow (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  113. target prot opt source destination
  114. Chain FWDO_public_deny (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  115. target prot opt source destination
  116. Chain FWDO_public_log (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  117. target prot opt source destination
  118. Chain INPUT_ZONES (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  119. target prot opt source destination
  120. IN_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
  121. IN_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
  122. Chain INPUT_ZONES_SOURCE (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  123. target prot opt source destination
  124. Chain INPUT_direct (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  125. target prot opt source destination
  126. Chain IN_public (</span><span style="color: #800080;">2</span><span style="color: #000000;"> references)
  127. target prot opt source destination
  128. IN_public_log all </span>--<span style="color: #000000;"> anywhere anywhere
  129. IN_public_deny all </span>--<span style="color: #000000;"> anywhere anywhere
  130. IN_public_allow all </span>--<span style="color: #000000;"> anywhere anywhere
  131. Chain IN_public_allow (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  132. target prot opt source destination
  133. ACCEPT tcp </span>--<span style="color: #000000;"> anywhere anywhere tcp dpt:ssh ctstate NEW
  134. Chain IN_public_deny (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  135. target prot opt source destination
  136. Chain IN_public_log (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  137. target prot opt source destination
  138. Chain OUTPUT_direct (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
  139. target prot opt source destination
  140. [root@localhost </span>~<span style="color: #000000;">]#
  141. 經過研究發現,應該要改用 firewall</span>-<span style="color: #000000;">cmd 命令
  142. 要暫時開放 http port,可執行
  143. # firewall</span>-cmd --add-service=<span style="color: #000000;">http
  144. 要永久開放 http port,可執行
  145. # firewall</span>-cmd --permanent --add-service=<span style="color: #000000;">http
  146. # systemctl restart firewalld
  147. 要停掉
  148. [root@localhost </span>~<span style="color: #000000;">]# systemctl stop firewalld
  149. 下面確認一下,真的停掉了
  150. [root@localhost </span>~]# iptables -<span style="color: #000000;">L
  151. Chain INPUT (policy ACCEPT)
  152. target prot opt source destination
  153. Chain FORWARD (policy ACCEPT)
  154. target prot opt source destination
  155. Chain OUTPUT (policy ACCEPT)
  156. target prot opt source destination
  157. [root@localhost </span>~<span style="color: #000000;">]#
  158. (下圖) 再從遠端連上網站看看,成功了
  159. 也就是 service iptables stop 無法停掉防火牆了 ( 看下面訊息該有支援,Bug 嗎 </span>?<span style="color: #000000;">)
  160. [root@localhost </span>~<span style="color: #000000;">]# service iptables
  161. The service command supports only basic LSB actions (start, stop, restart, </span><span style="color: #0000ff;">try</span>-restart, reload, force-reload, status). For other actions, please <span style="color: #0000ff;">try</span><span style="color: #000000;"> to use systemctl.
  162. 設定 httpd 隨作業系統啟動
  163. systemctl enable httpd
  164. 其他常用 firewall</span>-<span style="color: #000000;">cmd 命令
  165. # firewall</span>-cmd --<span style="color: #000000;">state
  166. # firewall</span>-cmd --list-<span style="color: #000000;">all
  167. # firewall</span>-cmd --list-<span style="color: #000000;">interfaces
  168. # firewall</span>-cmd --<span style="color: #0000ff;">get</span>-<span style="color: #000000;">service
  169. # firewall</span>-cmd --query-<span style="color: #000000;">service service_name
  170. # firewall</span>-cmd --add-port=<span style="color: #800080;">8080</span>/<span style="color: #000000;">tcp
  171. (完)
  172. 相關
  173. [研究] CentOS </span><span style="color: #800080;">7.0</span><span style="color: #000000;"> x64 的網站架設與防火牆
  174. http:</span><span style="color: #008000;">//</span><span style="color: #008000;">shaurong.blogspot.tw/2014/07/centos-linux-701406.html</span>
  175. <span style="color: #000000;">
  176. Installing LAMP (Linux, Apache, MariaDB, PHP</span>/PhpMyAdmin) <span style="color: #0000ff;">in</span> RHEL/CentOS <span style="color: #800080;">7.0</span><span style="color: #000000;">
  177. http:</span><span style="color: #008000;">//</span><span style="color: #008000;">www.tecmint.com/install-lamp-in-centos-7/</span>
点击查看文章内容

     

三、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端口连接不上的解决办法

标签:

人气教程排行