码迷,mamicode.com
首页 > 数据库 > 详细

新手玩个人服务器(阿里云centos)-mongodb安装和启动

时间:2014-09-27 05:05:10      阅读:597      评论:0      收藏:0      [点我收藏+]

标签:linux   mongodb   

一首《爱你的宿命》和《后会无期》,昨晚张碧晨在中国好声音很稳定,晋级实至名归,虽然几天前我从微博就知道结局了。陈冰吼过了……

今天看到草稿箱有篇没有完成的文章,在不怎么稳定的情绪继续完成,毕竟最爱小二班,后会无期,往往后会有期;但是后会有期,往往后会无期,珍惜身边爱你的人,这不是你的宿命,而是你的使命……

附上mongo在 github地址: https://github.com/mongodb/mongo/tree/master/rpm

<1>下载

wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.4.11.tgz

<2>解压

 tar zxf mongodb-linux-i686-2.4.11.tgz

<3>安装

(1)把mongodb安装到 /miodata/local/mongodb

mv /usr/local/src/mongodb-linux-i686-2.4.11 /miodata/local/mongodb

(2)创建数据库文件夹

 mkdir /miodata/local/mongodb/data

(3)将mongodb启动项加入rc.local保证开机启动mongodb

echo "/miodata/local/mongodb/bin/mongod --dbpath=/miodata/local/mongodb/data" >> /etc/rc.local

<3>启动mongodb

bubuko.com,布布扣

安装成功

开发模式用该安装方法


二:生产环境的方法

运行yum命令查看MongoDB的包信息 [root@vm ~]# yum info mongo-10gen  
(提示没有相关匹配的信息,)  
说明你的centos系统中的yum源不包含MongoDB的相关资源,所以要在使用yum命令安装MongoDB前需要增加yum源,也就是在 /etc/yum.repos.d/目录中增加 *.repo yum源配置文件
<span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; line-height: 18px; background-color: rgb(250, 250, 250);">我们这里就将该文件命名为:/etc/yum.repos.d/10gen.repo</span>


(1)安装32位yum适用的RPM包,编辑/etc/yum.repos.d/10gen.repo,加入以下代码:
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0

安装服务器端:  
  
[root@vm ~]# yum install mongo-10gen-server  
因为mongo-10gen-server包依赖于mongo-10gen,所以安装了服务器后就不需要单独安装客户端工具包mongo-10gen了  
  
   
  
单独安装可客户端:  
  
[root@vm ~]# yum install mongo-10gen  



(2)安装成功后,可以通过脚本来控制启动/停止/重新启动
/etc/init.d/mongodb start/stop/restart

(3)这时候查看系统服务:
chkconfig --list 

(4)会有一个叫 mongod 的服务了,将它设为开机启动:
chkconfig --level 345 mongod on

(5)然后启动它:
service mongod start

(6)这时候再查看该服务用的哪个端口:
netstat -atln

(6)验证MongoDB
可以通过检查日志文件/var/log/mongodb/mongod.log的内容来判断mongod进程是否正常运行。
也可以执行命令:
$ sudo chkconfig mongod on

要停止MongoDB,执行:
$ sudo service mongod stop

要重启MongoDB,执行:
$ sudo service mongod restart


三:安全性

1:After upgrading MongoDB from version 2.4 to 2.6, I am not able to connect to it from another machine. The firewall has been checked to ensure that port 27017 is opened for the machine that I want to connect from.

So what else could go wrong?  Well, I was impatient and turned to you know what… Google search. According to this link: https://groups.google.com/forum/#!msg/mongodb-user/yhf05AW-hK8/YqES0cVIXlUJ, the problem is due to the database is bound to only local IP.

Indeed, this was the case, and I could have found it out very easily had I run the netstat command:

# netstat -tpln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       
tcp        0      0 127.0.0.1:27017             0.0.0.0:*                   LISTEN      10122/mongod 
To fix this, modify /etc/mongod.conf to include your server’s IP. Make sure you use ‘;’ instead of ‘,’ to list IP addresses.

# Listen to local interface only. Comment out to listen on all interfaces. 
bind_ip=127.0.0.1;123.123.123.123
</pre><pre name="code" class="plain">http://blog.khmersite.net/2014/05/mongodb-warning-failed-to-connect/


I could not understand what bind_ip in mongodb is. I could make a remote connection from desktop to the EC2 machine by having bind_ip = 0.0.0.0, but could not make it work with bind_ip = 127.0.0.1.

Please explain me what bind_ip is and why it works for 0.0.0.0 and not for 127.0.0.1.

For reference from mongodb docs:

bind_ip

Default: All interfaces.

Set this option to configure the mongod or mongos process to bind to and listen for connections from applications on this address. You may attach mongod or mongos instances to any interface; however, if you attach the process to a publicly accessible interface, implement proper authentication or firewall restrictions to protect the integrity of your database.

You may concatenate a list of comma separated values to bind mongod to multiple IP addresses.

You can't access your machine when you bind it to 127.0.0.1 on EC2. That's not a bug, it's reasoned by the network interface bindings.

127.0.0.1 will only bind to the loopback interface (so you will only be able to access it locally), while 0.0.0.0 will bind it to all network interfaces that are available.

That's why you can access your mongodb on EC2 when you bind it to 0.0.0.0(as it's available through the internet now) and not via 127.0.0.1.

For local servers (like a WAMP or a local mongodb server) that won't look different to you, but for that case you should also thing that binding to 0.0.0.0 for local servers might make them available over all network interfaces (so it might be public for someone who knows your IP, if there is no firewall!)

Read on a similar question on Server Fault here.
http://stackoverflow.com/questions/17588876/mongodb-conf-bind-ip-127-0-0-1-does-not-work-but-0-0-0-0-works


参阅:http://be-evil.org/install-mongodb-on-centos.html

http://www.cnblogs.com/kgdxpr/p/3519352.html


http://blog.csdn.net/chszs/article/details/23392487


http://zuoqiang.iteye.com/blog/1155069


http://www.server110.com/mongodb/201310/2737.html

新手玩个人服务器(阿里云centos)-mongodb安装和启动

标签:linux   mongodb   

原文地址:http://blog.csdn.net/xizai2012/article/details/39040625

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!