centos6.4下安装mongodb-3.2.6

1.下载

下载地址:  https://www.mongodb.com/download 选择社区linux版本,下载最新的,目前最新的即为3.2.6
或者直接用
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.6.tgz

2.解压缩文件

下载下来的文件是二进制版本类似于mysql的general版本,无需要编译的.解压之后可以看到如下目录:
      
      
      
      
[root@mongodb1 mongodb-linux-x86_64-3.2.6]# ls -l
total 100
drwxr-xr-x. 2 root root 4096 May 14 17:45 bin
-rw-r--r--. 1 1046 1046 34520 Apr 28 04:38 GNU-AGPL-3.0
-rw-r--r--. 1 1046 1046 16726 Apr 28 04:38 MPL-2
-rw-r--r--. 1 1046 1046 1324 May 14 17:52 README
-rw-r--r--. 1 1046 1046 35910 Apr 28 04:38 THIRD-PARTY-NOTICES
主要就是这个bin目录,具体文件如下:
      
      
      
      
[root@mongodb1 bin]# ls -l
total 174480
-rwxr-xr-x. 1 1046 1046 4722768 Apr 28 04:38 bsondump
-rwxr-xr-x. 1 1046 1046 20987301 Apr 28 04:51 mongo
-rwxr-xr-x. 1 1046 1046 36731194 Apr 28 04:51 mongod
-rwxr-xr-x. 1 1046 1046 10796256 Apr 28 04:38 mongodump
-rwxr-xr-x. 1 1046 1046 6607288 Apr 28 04:38 mongoexport
-rwxr-xr-x. 1 1046 1046 6457168 Apr 28 04:38 mongofiles
-rwxr-xr-x. 1 1046 1046 6724760 Apr 28 04:38 mongoimport
-rwxr-xr-x. 1 1046 1046 6190176 Apr 28 04:38 mongooplog
-rwxr-xr-x. 1 1046 1046 36436521 Apr 28 04:51 mongoperf
-rwxr-xr-x. 1 1046 1046 13542128 Apr 28 04:38 mongorestore
-rwxr-xr-x. 1 1046 1046 16749560 Apr 28 04:51 mongos
-rwxr-xr-x. 1 1046 1046 6419256 Apr 28 04:38 mongostat
-rwxr-xr-x. 1 1046 1046 6273904 Apr 28 04:38 mongotop
下面是官方对文件的解释:
       
       
       
       
COMPONENTS
 
bin/mongod - The database process. #数据库进程,类似于mysqld
bin/mongos - Sharding controller. #分片的控制器
bin/mongo - The database shell (uses interactive javascript). #命令行工具
 
UTILITIES
 
bin/mongodump - MongoDB dump tool - for backups, snapshots, etc.. #dump工具,用来备份,快照
bin/mongorestore - MongoDB restore a dump #还原工具,用来恢复dump的文件,和上面对应
bin/mongoexport - Export a single collection to test (JSON, CSV) #将数据库导出为一个json和csv文件
bin/mongoimport - Import from JSON or CSV #从json或者csv格式导入,和上面对应
bin/mongofiles - Utility for putting and getting files from MongoDB GridFS #工具用来从Gridfs文件系统中存放或者获取文件
bin/mongostat - Show performance statistics #显示性能统计信息


3.移动到指定文件夹

将解压文件移动到你想要的安装目录中,例如一般放到/usr/local下
      
      
      
      
[root@mongodb1 ~]# mv mongodb-linux-x86_64-3.2.6 /usr/local/mongodb
将bin目录添加到环境变量中
      
      
      
      
PATH=/usr/local/mongodb/bin:$PATH:$HOME/bin

4.创建指定的数据文件夹

主要包括数据文件目录,日志目录,例如我这里将数据文件目录放在/data/db下,日志目录放在/data/log下:
      
      
      
      
[root@mongodb1 ~]# mkdir -p /data/db
[root@mongodb1 ~]# mkdir -p /data/log

5.启动数据库

创建mongodb配置文件,在vi /etc/mongod.conf
      
      
      
      
[root@mongodb1 bin]# cat /etc/mongod.conf
port=27017
dbpath=/data/db
logpath=/data/log/mongod.log
fork = true
 分别表示端口号,数据文件目录,log文件,后台运行,详细的其它参数可以使用mongd -h来
使用如下命令启动数据库:
      
      
      
      
[root@mongodb1 bin]# ./mongod -f /etc/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 2859
child process started successfully, parent exiting
启动完成之后就可以使用mongo连接数据库了:
      
      
      
      
[root@mongodb1 bin]# mongo
MongoDB shell version: 3.2.6
connecting to: test
Server has startup warnings:
2016-05-14T20:00:32.591+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-05-14T20:00:32.592+0800 I CONTROL [initandlisten]
2016-05-14T20:00:32.592+0800 I CONTROL [initandlisten]
2016-05-14T20:00:32.592+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-05-14T20:00:32.592+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-05-14T20:00:32.592+0800 I CONTROL [initandlisten]
2016-05-14T20:00:32.592+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-05-14T20:00:32.592+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-05-14T20:00:32.592+0800 I CONTROL [initandlisten]
>

6.关闭数据库

先到admin下,在使用db.shutdownServer()来关闭数据库,注意mongodb是区分大小写的
      
      
      
      
[root@mongodb1 bin]# mongo
MongoDB shell version: 3.2.6
connecting to: test
Server has startup warnings:
2016-05-14T20:10:29.834+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-05-14T20:10:29.835+0800 I CONTROL [initandlisten]
2016-05-14T20:10:29.835+0800 I CONTROL [initandlisten]
2016-05-14T20:10:29.835+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-05-14T20:10:29.835+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-05-14T20:10:29.835+0800 I CONTROL [initandlisten]
2016-05-14T20:10:29.835+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-05-14T20:10:29.835+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-05-14T20:10:29.835+0800 I CONTROL [initandlisten]
> use admin
switched to db admin
> db.shutdownServer()
server should be down...
2016-05-14T20:12:18.056+0800 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2016-05-14T20:12:18.056+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-05-14T20:12:18.056+0800 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed
> exit
再看mongodb的进程不在了:
      
      
      
      
[root@mongodb1 bin]# ps -ef |grep mong
root 1923 1 0 17:55 ? 00:00:00 /usr/sbin/certmonger -S -p /var/run/certmonger.pid
root 3043 2657 0 20:12 pts/0 00:00:00 grep mong

禁用动态hugepage分配,在/etc/rc.local下添加如下语句,然后重启服务器即可.
      
      
      
      
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi















你可能感兴趣的:(mongodb)