MongoDB 安装(CentOS 6.5 64位)

跟着官方的Doc安装,很简单。 留点笔记以后用。

1. yum 配置文件定义

[root@mongodb ~]# vi /etc/yum.repos.d/mongodb.repo

[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

2. 安装

安装前确认系统没有既存的mongodb,以免版本发生冲突。如果有,应该卸载。
查看mongodb

[root@mongodb ~]# rpm -qa | grep mongodb
mongodb-2.4.6-1.el6.x86_64

卸载mongodb

[root@mongodb ~]# rpm -e mongodb

安装mongodb 根据网速快慢,安装可能需要几分钟。
也可以指定安装版本,默认是最新版本。当前时2.6.1-2

[root@mongodb ~]# sudo yum install mongodb-org

3. 系统设定

 以为要设置端口和防火墙,结果没设置好像也没事。....

4. 运行MongoDB

启动

[root@mongodb ~]# sudo service mongod start
Starting mongod:                                           [  OK  ]

停止

[root@mongodb ~]# sudo service mongod stop
Stopping mongod:                                           [  OK  ]

重启 因为mongodb没有启动,所以停止时出错了。没有影响,忽略就行了。

[root@mongodb ~]# sudo service mongod restart
Stopping mongod:                                           [FAILED]
Starting mongod:                                           [  OK  ]

查看当前mongodb是不是启动中

[root@mongodb ~]# ps -ef | grep mongod
mongod    1267     1  0 03:34 ?        00:00:04 /usr/bin/mongod -f /etc/mongod.conf
root      1295  1051  0 03:41 pts/0    00:00:00 grep mongod

通过杀进程,关闭mongodb

[root@mongodb ~]# kill -9 1267

设置开机启动

[root@mongodb ~]# sudo chkconfig mongod on

5. 查看log

log路径:/var/log/mongo
数据路径:/var/lib/mongo

[root@mongodb ~]# tail -f /var/log/mongodb/mongod.log
2014-06-13T03:34:07.266-0400 [initandlisten] build info: Linux build14.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-06-13T03:34:07.266-0400 [initandlisten] allocator: tcmalloc
2014-06-13T03:34:07.266-0400 [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/var/lib/mongo" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }

6. 初体验

连接mongodb 系统模拟人的监听端口是27017,host是localhost

[root@mongodb ~]# mongo
MongoDB shell version: 2.6.1
connecting to: test
>

查看帮助 命令行的操作不太喜欢,还是选一个好的可视化工具吧。例如:Robomongo

[root@mongodb ~]# mongo
MongoDB shell version: 2.6.1
connecting to: test
> help
    db.help()                    help on db methods
    db.mycoll.help()             help on collection methods
    sh.help()                    sharding helpers
    rs.help()                    replica set helpers
    help admin                   administrative help
    help connect                 connecting to a db help
    help keys                    key shortcuts
    help misc                    misc things to know
    help mr                      mapreduce

    show dbs                     show database names
    show collections             show collections in current database
    show users                   show users in current database
    show profile                 show most recent system.profile entries with time >= 1ms
    show logs                    show the accessible logger names
    show log [name]              prints out the last segment of log in memory, 'global' is default
    use <db_name>                set current database
    db.foo.find()                list objects in collection foo
    db.foo.find( { a : 1 } )     list objects in foo where a == 1
    it                           result of the last line evaluated; use to further iterate
    DBQuery.shellBatchSize = x   set default number of items to display on shell
    exit                         quit the mongo shell
>

※如果是root用户,命令前不用加sudo。

你可能感兴趣的:(MongoDB 安装(CentOS 6.5 64位))