centOS下mongodb的安装

###############centOS下mongodb的安装#########
mongodb作为非关系型数据库NoSQL数据库的一种,并且是属于免安装类型。
mongodb安装说明:32的安装db空间有限,最大支持2G多,并且性能低于64bit。64bit系统db存储没有限制!
                                 mongodb安装需要磁盘大小为15G以上,如果只是测试可以使用--smallfiles参数最小安装!
1:准备安装包:
   可以到官网下载: https://www.mongodb.org/
   包括各种:dbservers / drivers / docs
2:我准备的安装包[mongodb-linux-x86_64-3.0.3.gz]:
[root@localhost install-files]# ll
total 115412
-rw-r--r--. 1 root root 40231021 Oct 17 11:45 mongodb-linux-x86_64-3.0.3.gz
-rw-r--r--. 1 root root 18596528 Oct 12 22:42 MySQL-client-5.6.27-1.el6.x86_64.rpm
-rw-r--r--. 1 root root  3392620 Oct 12 22:42 MySQL-devel-5.6.27-1.el6.x86_64.rpm
-rw-r--r--. 1 root root 55950588 Oct 12 22:42 MySQL-server-5.6.27-1.el6.x86_64.rpm
3:免安装,解压即可使用:
[root@localhost install-files]# tar zxvf mongodb-linux-x86_64-3.0.3.gz 
mongodb-linux-x86_64-3.0.3/README
mongodb-linux-x86_64-3.0.3/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-3.0.3/GNU-AGPL-3.0
mongodb-linux-x86_64-3.0.3/bin/mongodump
mongodb-linux-x86_64-3.0.3/bin/mongorestore
mongodb-linux-x86_64-3.0.3/bin/mongoexport
mongodb-linux-x86_64-3.0.3/bin/mongoimport
mongodb-linux-x86_64-3.0.3/bin/mongostat
mongodb-linux-x86_64-3.0.3/bin/mongotop
mongodb-linux-x86_64-3.0.3/bin/bsondump
mongodb-linux-x86_64-3.0.3/bin/mongofiles
mongodb-linux-x86_64-3.0.3/bin/mongooplog
mongodb-linux-x86_64-3.0.3/bin/mongoperf
mongodb-linux-x86_64-3.0.3/bin/mongod
mongodb-linux-x86_64-3.0.3/bin/mongos
mongodb-linux-x86_64-3.0.3/bin/mongo
4:查看免安装目录下的文件结构:
[root@localhost install-files]# ll
total 115412
drwxr-xr-x. 3 root root       74 Oct 17 11:46 mongodb-linux-x86_64-3.0.3
-rw-r--r--. 1 root root 40231021 Oct 17 11:45 mongodb-linux-x86_64-3.0.3.gz
-rw-r--r--. 1 root root 18596528 Oct 12 22:42 MySQL-client-5.6.27-1.el6.x86_64.rpm
-rw-r--r--. 1 root root  3392620 Oct 12 22:42 MySQL-devel-5.6.27-1.el6.x86_64.rpm
-rw-r--r--. 1 root root 55950588 Oct 12 22:42 MySQL-server-5.6.27-1.el6.x86_64.rpm
[root@localhost install-files]# cd mongodb-linux-x86_64-3.0.3
[root@localhost mongodb-linux-x86_64-3.0.3]# ll
total 68
drwxr-xr-x. 2 root root  4096 Oct 17 11:47 bin
-rw-r--r--. 1 1046 1046 34520 May 12 05:35 GNU-AGPL-3.0
-rw-r--r--. 1 1046 1046  1359 May 12 05:35 README
-rw-r--r--. 1 1046 1046 22660 May 12 05:35 THIRD-PARTY-NOTICES
[root@localhost mongodb-linux-x86_64-3.0.3]# cd bin/
[root@localhost bin]# ll
total 116340
-rwxr-xr-x. 1 1046 1046  4305912 May 12 05:35 bsondump
-rwxr-xr-x. 1 1046 1046 11694552 May 12 05:43 mongo
-rwxr-xr-x. 1 1046 1046 22349960 May 12 05:43 mongod
-rwxr-xr-x. 1 1046 1046  6199144 May 12 05:35 mongodump
-rwxr-xr-x. 1 1046 1046  6001840 May 12 05:35 mongoexport
-rwxr-xr-x. 1 1046 1046  5956232 May 12 05:35 mongofiles
-rwxr-xr-x. 1 1046 1046  6211952 May 12 05:35 mongoimport
-rwxr-xr-x. 1 1046 1046  5686856 May 12 05:35 mongooplog
-rwxr-xr-x. 1 1046 1046 22129448 May 12 05:43 mongoperf
-rwxr-xr-x. 1 1046 1046  6332464 May 12 05:35 mongorestore
-rwxr-xr-x. 1 1046 1046 10552760 May 12 05:43 mongos
-rwxr-xr-x. 1 1046 1046  5909928 May 12 05:35 mongostat
-rwxr-xr-x. 1 1046 1046  5769944 May 12 05:35 mongotop
解压即可使用!
注:参数最后备注附件:
5:mongod为启动mongodb,可以直接./mongod,默认启动需要配置db的路径为/data/db,没有路径则失败,请手动创建!
[root@localhost bin]# ./mongod
2015-10-17T11:52:52.338+0800 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2015-10-17T11:52:52.338+0800 I CONTROL  [initandlisten] dbexit:  rc: 100
[root@localhost bin]# mkdir /data
[root@localhost bin]# mkdir /data/db
安装留足空间最小大概15G空间,不然报错:Error:Insufficient free space for journal files
解决:注可以使用--smallfiles参数最小安装
默认:启动mongodb:
[root@localhost bin]# ./mongod --smallfiles
[root@localhost bin]# ./mongod
非最小安装启动:
[root@localhost bin]# ./mongod
2015-10-17T12:03:34.488+0800 I STORAGE  [initandlisten]
………………
2015-10-17T12:03:41.407+0800 I NETWORK  [initandlisten] waiting for connections on port 27017
6:查看默认安装文件结构:
[root@localhost bin]# cd /data/db/
[root@localhost db]# ll
total 81932
drwxr-xr-x. 2 root root       17 Oct 17 12:03 journal
-rw-------. 1 root root 67108864 Oct 17 12:03 local.0
-rw-------. 1 root root 16777216 Oct 17 12:03 local.ns
-rwxr-xr-x. 1 root root        5 Oct 17 12:03 mongod.lock
-rw-r--r--. 1 root root       69 Oct 17 11:59 storage.bson

7:默认关闭关闭mongodb:
[root@localhost bin]# pwd
/home/install-files/mongodb-linux-x86_64-3.0.3/bin
[root@localhost bin]# ./mongod --shutdown
killing process with pid: 2107
注:默认安装缺点:数据库目录不能指定,log日志不能保存查看.
8:自定义配置文件安装mongodb:
查看mongodb的启动参数:
[root@localhost bin]# ./mongod --help
或
[root@localhost bin]# ./mongod --help | more
-f  参数 使用配置文件控制mongodb的启动:
操作:在mongodb免安装目录下创建/conf/mongodb.conf来配置启动参数:
[root@localhost mongodb-linux-x86_64-3.0.3]# pwd
/home/install-files/mongodb-linux-x86_64-3.0.3
[root@localhost mongodb-linux-x86_64-3.0.3]# mkdir conf
[root@localhost mongodb-linux-x86_64-3.0.3]# ll
total 68
drwxr-xr-x. 2 root root  4096 Oct 17 12:27 bin
drwxr-xr-x. 2 root root    25 Oct 17 12:25 conf
-rw-r--r--. 1 1046 1046 34520 May 12 05:35 GNU-AGPL-3.0
-rw-r--r--. 1 1046 1046  1359 May 12 05:35 README
-rw-r--r--. 1 1046 1046 22660 May 12 05:35 THIRD-PARTY-NOTICES
[root@localhost mongodb-linux-x86_64-3.0.3]# cd conf/
[root@localhost mongodb-linux-x86_64-3.0.3]# vim mongodb.conf
[root@localhost mongodb-linux-x86_64-3.0.3]# cat mongodb.conf 
配置文件信息:
#日志路径
logpath=../log/mongodb.log
#启动日志不追加,太过庞大
logappend=false
#设置mongodb的db路径
dbpath=/home/mongodb/data/db
#后台驻留(守护)进程服务运行
fork=true
注:日志路径和mongodb的路径需要自己创建,否则报错:
创建日志目录:
[root@localhost mongodb-linux-x86_64-3.0.3]# mkdir log
[root@localhost mongodb-linux-x86_64-3.0.3]# ll
total 68
drwxr-xr-x. 2 root root  4096 Oct 17 12:27 bin
drwxr-xr-x. 2 root root    25 Oct 17 12:25 conf
-rw-r--r--. 1 1046 1046 34520 May 12 05:35 GNU-AGPL-3.0
drwxr-xr-x. 2 root root     6 Oct 17 12:29 log
-rw-r--r--. 1 1046 1046  1359 May 12 05:35 README
-rw-r--r--. 1 1046 1046 22660 May 12 05:35 THIRD-PARTY-NOTICES
创建mongodb数据db路径:
[root@localhost home]# mkdir mongodb
root@localhost home]# cd mongodb/
[root@localhost mongodb]# mkdir data
[root@localhost mongodb]# cd data/
[root@localhost data]# mkdir db
[root@localhost data]# cd db/
[root@localhost db]# pwd
/home/mongodb/data/db
删除默认安装的mongodb数据,释放空间:
[root@localhost mongodb-linux-x86_64-3.0.3]# cd /
[root@localhost /]# ls
bin  boot  data  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@localhost /]# rm -rf data/
[root@localhost /]# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
使用-f参数:配置文件控制mongodb的启动,空间不足继续加参数:--smallfiles
[root@localhost mongodb-linux-x86_64-3.0.3]# cd bin/
[root@localhost bin]# ls
bsondump  mongo  mongod  mongodump  mongoexport  mongofiles  mongoimport  mongooplog  mongoperf  mongorestore  mongos  mongostat  mongotop
[root@localhost bin]# pwd
/home/install-files/mongodb-linux-x86_64-3.0.3/bin
使用自定义配置文件启动mongodb:
[root@localhost bin]# ./mongod -f ../conf/mongodb.conf 
about to fork child process, waiting until server is ready for connections.
forked process: 4327
child process started successfully, parent exiting
查看是否用守护进程服务启动:
[root@localhost bin]# ps -ef | grep mongodb
root      4327     1  0 12:38 ?        00:00:00 ./mongod -f ../conf/mongodb.conf
root      4340  2122  0 12:41 pts/1    00:00:00 grep --color=auto mongodb
查看自定义的mongodb数据文件:
[root@localhost bin]# cd /home/mongodb/data/db/
[root@localhost db]# ll
total 81932
drwxr-xr-x. 2 root root       17 Oct 17 12:38 journal
-rw-------. 1 root root 67108864 Oct 17 12:38 local.0
-rw-------. 1 root root 16777216 Oct 17 12:38 local.ns
-rwxr-xr-x. 1 root root        5 Oct 17 12:38 mongod.lock
-rw-r--r--. 1 root root       69 Oct 17 12:38 storage.bson
drwxr-xr-x. 2 root root        6 Oct 17 12:38 _tmp
注:--smallfiles启动,无storage.bson文件.
查看自定义的日志文件:
[root@localhost db]# cd /home/install-files/mongodb-linux-x86_64-3.0.3/log/
[root@localhost log]# ls
mongodb.log
[root@localhost log]# cat mongodb.log 
2015-10-17T12:38:58.575+0800 I STORAGE  [initandlisten] 
………………
2015-10-17T12:38:58.979+0800 I NETWORK  [initandlisten] waiting for connections on port 27017
默认启动端口为:27017
登陆测试:
[root@CentOS-Slave1 bin]# telnet localhost 27017
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
登陆日志:
[root@CentOS-Slave1 log]# tail -f mongodb.log
………………………
2015-10-18T10:24:10.877+0800 I NETWORK  [conn27] AssertionException handling request, closing client connection: 17133 SSL handshake requested, SSL feature not available in this build
2015-10-18T10:24:12.627+0800 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:56321 #28 (1 connection now open)
2015-10-18T10:24:16.956+0800 I NETWORK  [conn28] end connection 127.0.0.1:56321 (0 connections now open)
注:日志会自动备份:
[root@CentOS-Slave1 sbin]# cd /home/install-files/mongodb-linux-x86_64-3.0.3/log/
[root@CentOS-Slave1 log]# ls
mongodb.log  mongodb.log.2015-10-17T08-35-18  mongodb.log.2015-10-18T01-31-48
[root@CentOS-Slave1 log]# tail -f mongodb.log
………………………
2015-10-18T10:24:10.877+0800 I NETWORK  [conn27] AssertionException handling request, closing client connection: 17133 SSL handshake requested, SSL feature not available in this build
2015-10-18T10:24:12.627+0800 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:56321 #28 (1 connection now open)
2015-10-18T10:24:16.956+0800 I NETWORK  [conn28] end connection 127.0.0.1:56321 (0 connections now open)
打开浏览器console:
[root@CentOS-Slave1 conf]# pwd
/home/install-files/mongodb-linux-x86_64-3.0.3/conf
[root@CentOS-Slave1 conf]# vim mongodb.conf 
[root@CentOS-Slave1 conf]# cat mongodb.conf 
#日志路径
logpath=../log/mongodb.log
#启动日志不追加,太过庞大
logappend=false
#设置mongodb的db路径
dbpath=/home/mongodb/data/db
#后台驻留进程服务运行
fork=true
#配置浏览器可以通过28017端口访问mongodb
rest=true
配置后,重新启动,先关闭再启动:
关闭自定义配置文件的mongodb:
[root@CentOS-Slave1 bin]# ./mongod --shutdown --dbpath=/home/mongodb/data/db/
killing process with pid: 5891
浏览器登录端口默认28017:
访问url:http://192.168.10.56:28017/

使用客户端登陆mongodb:
[root@CentOS-Slave1 bin]# ./mongo --port 27017
MongoDB shell version: 3.0.3
connecting to: 127.0.0.1:27017/test
Server has startup warnings: 
2015-10-18T09:31:48.114+0800 I CONTROL  ** WARNING: --rest is specified without --httpinterface,
2015-10-18T09:31:48.114+0800 I CONTROL  **          enabling http interface
2015-10-18T09:31:48.159+0800 I STORAGE  [initandlisten] 
2015-10-18T09:31:48.159+0800 I STORAGE  [initandlisten] ** WARNING: Readahead for /home/mongodb/data/db is set to 4096KB
2015-10-18T09:31:48.159+0800 I STORAGE  [initandlisten] **          We suggest setting it to 256KB (512 sectors) or less
2015-10-18T09:31:48.159+0800 I STORAGE  [initandlisten] **          http://dochub.mongodb.org/core/readahead
2015-10-18T09:31:48.940+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2015-10-18T09:31:48.940+0800 I CONTROL  [initandlisten] 
2015-10-18T09:31:48.941+0800 I CONTROL  [initandlisten] 
2015-10-18T09:31:48.941+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-10-18T09:31:48.941+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-10-18T09:31:48.941+0800 I CONTROL  [initandlisten] 
2015-10-18T09:31:48.941+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-10-18T09:31:48.941+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-10-18T09:31:48.941+0800 I CONTROL  [initandlisten] 
> show dbs
local  0.078GB
> show users
> 
备注附件:
mongodb数据db目录文件:
[root@CentOS-Slave1 db]# pwd
/home/mongodb/data/db
[root@CentOS-Slave1 db]# ll
total 81932
drwxr-xr-x. 2 root root       17 Oct 18 09:31 journal
-rw-------. 1 root root 67108864 Oct 18 09:31 local.0
-rw-------. 1 root root 16777216 Oct 18 09:31 local.ns
-rwxr-xr-x. 1 root root        5 Oct 18 09:31 mongod.lock
-rw-r--r--. 1 root root       69 Oct 17 12:38 storage.bson
journal :事务日志目录(j._0 日志文件从0编号,可循环重用)
mongod.lock :记录当前的mongod的进程号
_tmp :临时数据文件
local.0 :数据库文件,按序号递增,大小也倍增(64M—128M—256M—512M—1G—最大2G)
local.ns :记录集合命名空间和索引命名空间

mongodb指令文件:
[root@CentOS-Slave1 bin]# pwd
/home/install-files/mongodb-linux-x86_64-3.0.3/bin
[root@CentOS-Slave1 bin]# ll
total 116340
-rwxr-xr-x. 1 1046 1046  4305912 May 12 05:35 bsondump
-rwxr-xr-x. 1 1046 1046 11694552 May 12 05:43 mongo
-rwxr-xr-x. 1 1046 1046 22349960 May 12 05:43 mongod
-rwxr-xr-x. 1 1046 1046  6199144 May 12 05:35 mongodump
-rwxr-xr-x. 1 1046 1046  6001840 May 12 05:35 mongoexport
-rwxr-xr-x. 1 1046 1046  5956232 May 12 05:35 mongofiles
-rwxr-xr-x. 1 1046 1046  6211952 May 12 05:35 mongoimport
-rwxr-xr-x. 1 1046 1046  5686856 May 12 05:35 mongooplog
-rwxr-xr-x. 1 1046 1046 22129448 May 12 05:43 mongoperf
-rwxr-xr-x. 1 1046 1046  6332464 May 12 05:35 mongorestore
-rwxr-xr-x. 1 1046 1046 10552760 May 12 05:43 mongos
-rwxr-xr-x. 1 1046 1046  5909928 May 12 05:35 mongostat
-rwxr-xr-x. 1 1046 1046  5769944 May 12 05:35 mongotop
[root@CentOS-Slave1 bin]# 
mongo 客户端程序,连接MongoDB 
mongod 服务端程序,启动MongoDB 
mongodump 备份程序 
mongoexport 数据导出程序 
mongofiles GridFS工具,内建的分布式文件系统 
mongoimport 数据导入程序 
mongorestore 数据恢复程序 
mongos 数据分片程序,支持数据的横向扩展 
mongostat 监视程序 



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值