linux命令行提示符符里怎么远程连接MongoDB

一、背景描述:
&&&& 我在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,发现如下文章:
&&&&& 解决了我的问题。重点是由于在RED7中,关闭防火墙的命令改为:systemctl stop firewalld
&&&&& 这样后,便可以真正关闭防火墙功能。远程连接mongodb成功!
&&&&& 上述连接:/2014/07/centos-70-x64.html 内容如下(需翻 墙才可访问,所以就把原文复制过来了。望原作者莫见怪!):
[研究] CentOS 7.0 x64 的 iptables 與 firewall-cmd 防火牆
[研究] CentOS 7.0 x64 的 iptables 與 firewall-cmd 防火牆
2014-07-25
2014-08-01 修訂
CentOS 7.0 開始,服務的管理使用變成用 systemctl,例如 httpd 的使用可用下面幾種方式
# systemctl status|start|stop|restart|reload httpd
# service httpd status|start|stop|restart|reload
# 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. disabled)
Active: active (running) since Fri 2014-07-25 15:54:58 CST; 21s ago
Main PID: 14250 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic:
CGroup: /system.slice/httpd.service
? 14250 /usr/sbin/httpd -DFOREGROUND
? 14251 /usr/sbin/httpd -DFOREGROUND
? 14252 /usr/sbin/httpd -DFOREGROUND
? 14253 /usr/sbin/httpd -DFOREGROUND
? 14254 /usr/sbin/httpd -DFOREGROUND
? 14255 /usr/sbin/httpd -DFOREGROUND
Jul 25 15:54:58 localhost.localdomain systemd[1]: Starting The Apache HTTP Se...
Jul 25 15:54:58 localhost.localdomain httpd[14250]: AH00558: httpd: Could not...
Jul 25 15:54:58 localhost.localdomain systemd[1]: Started The Apache HTTP Ser...
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# ps aux | grep httpd
0.2 209484
0:00 /usr/sbin/http
-DFOREGROUND
0.1 211568
0:00 /usr/sbin/http
-DFOREGROUND
0.1 211568
0:00 /usr/sbin/http
-DFOREGROUND
0.1 211568
0:00 /usr/sbin/http
-DFOREGROUND
0.1 211568
0:00 /usr/sbin/http
-DFOREGROUND
0.1 211568
0:00 /usr/sbin/http
-DFOREGROUND
0.0 112640
0:00 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. disabled)
Active: inactive (dead)
Jul 25 15:56:53 localhost.localdomain systemd[1]: Stopped IPv4 firewall with ...
Hint: Some lines were ellipsized, use -l to show in full.
列出防火牆
rules,居然仍有
[root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
prot opt source
destination
ctstate RELATED,ESTABLISHED
INPUT_direct
INPUT_ZONES_SOURCE
INPUT_ZONES
reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
prot opt source
destination
ctstate RELATED,ESTABLISHED
FORWARD_direct
FORWARD_IN_ZONES_SOURCE
FORWARD_IN_ZONES
FORWARD_OUT_ZONES_SOURCE
FORWARD_OUT_ZONES
reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
prot opt source
destination
OUTPUT_direct
Chain FORWARD_IN_ZONES (1 references)
prot opt source
destination
FWDI_public
FWDI_public
Chain FORWARD_IN_ZONES_SOURCE (1 references)
prot opt source
destination
Chain FORWARD_OUT_ZONES (1 references)
prot opt source
destination
FWDO_public
FWDO_public
Chain FORWARD_OUT_ZONES_SOURCE (1 references)
prot opt source
destination
Chain FORWARD_direct (1 references)
prot opt source
destination
Chain FWDI_public (2 references)
prot opt source
destination
FWDI_public_log
FWDI_public_deny
FWDI_public_allow
Chain FWDI_public_allow (1 references)
prot opt source
destination
Chain FWDI_public_deny (1 references)
prot opt source
destination
Chain FWDI_public_log (1 references)
prot opt source
destination
Chain FWDO_public (2 references)
prot opt source
destination
FWDO_public_log
FWDO_public_deny
FWDO_public_allow
Chain FWDO_public_allow (1 references)
prot opt source
destination
Chain FWDO_public_deny (1 references)
prot opt source
destination
Chain FWDO_public_log (1 references)
prot opt source
destination
Chain INPUT_ZONES (1 references)
prot opt source
destination
Chain INPUT_ZONES_SOURCE (1 references)
prot opt source
destination
Chain INPUT_direct (1 references)
prot opt source
destination
Chain IN_public (2 references)
prot opt source
destination
IN_public_log
IN_public_deny
IN_public_allow
Chain IN_public_allow (1 references)
prot opt source
destination
tcp dpt:ssh ctstate NEW
Chain IN_public_deny (1 references)
prot opt source
destination
Chain IN_public_log (1 references)
prot opt source
destination
Chain OUTPUT_direct (1 references)
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)
prot opt source
destination
Chain FORWARD (policy ACCEPT)
prot opt source
destination
Chain OUTPUT (policy ACCEPT)
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
其他常用 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=8080/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:///install-lamp-in-centos-7/
点击查看文章内容
三、RED7中通过yum安装mongodb的官方步骤:
四、关于RED 7中关闭防火墙命令的描述如下:
阅读(...) 评论()问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
请输入代码我按照这篇教程设置:
其实就是把配置文件中bind_ip = 0.0.0.0给注释掉..但是蛋疼的来了:mongo 服务器的ip:27017
居然就能连接上!!而且不用用户名和密码!!!!!!找了半天都找不到一篇答案是真正有用的!有知道的高手可以解答吗?如何让我的数据库远程访问需要密码,也就是mongo 服务器的ip:27017这样直接访问是访问不了的
按照这个教程:我添加了管理员账户以后,提示是成功创建了~~但是我登录的话 发现还是直接登录!!!
这样太不安全了~知道我的ip地址就可以登录我的数据库~~
经过google一下,发现可能是没有开启验证`` 但是网上看到的基本是不3.0的教程都说要在mongodb.conf,把auth = true 开启,但是3.0的mongodb没有这个选项 要在哪里修改?
来源: MongoDB 技术问答
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
是3.X以上的吗,可以看看这篇我在这里说一下几个要点:进入配置文件vi /etc/mongod.conf修改 `bindIp : 0.0.0.0 //允许所有IP链接,外链然后对你需要远程的数据库添加权限,如:db.createUser({user:"jimb55",pwd:"123456",roles:[{"role":"readWrite","db":"xxxx"}]})
然后exit退出客户端杀掉相关的进程killall mongod然后开启验证模式mongod -f /etc/mongod.conf --fork --auth 你可以用Robomongo.exe远程登录试试Robomongo.exe的使用在给出的链接里面有说明
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
修改mongod.conf
authorization: enabled
mongodb 设计得真是太差了,打算换 RethinkDB
同步到新浪微博
分享到微博?
你好!看起来你挺喜欢这个内容,但是你还没有注册帐号。 当你创建了帐号,我们能准确地追踪你关注的问题,在有新答案或内容的时候收到网页和邮件通知。还能直接向作者咨询更多细节。如果上面的内容有帮助,记得点赞 (????)? 表示感谢。
明天提醒我
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:mongodb 实现远程连接
投稿:hebedich
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了mongodb 实现远程连接,需要的朋友可以参考下
mongodb远程连接配配置,分以下4步。
1,添加管理员账
& use admin
switched to db admin
& db.addUser('tank','test');
2,配置mongodb.conf
#bind_ip = 127.0.0.1
//注释此行
auth = true
//将此行前的注释去掉
3,重启mongodb
/etc/init.d/mongod
4,防火墙开放27017端口
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
mongdb 远程连接
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

更多关于 ubuntu 命令行提示符 的文章

 

随机推荐