Mongodb 安装:
[root@sword ~]# mongo -version
MongoDB shell version: 2.6.12
[root@sword ~]# mongo
mongo mongod mongodump mongoexport mongofiles mongoimport mongooplog mongoperf mongorestore mongos mongosniff mongostat mongotop
[root@sword ~]# mongo
mongo mongod mongodump mongoexport mongofiles mongoimport mongooplog mongoperf mongorestore mongos mongosniff mongostat mongotop
[root@sword ~]# mongod
mongod mongodump
[root@sword ~]# mongod -version
db version v2.6.12
2018-09-28T14:07:12.613+0800 git version: nogitversion
2018-09-28T14:07:12.613+0800 OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017
[root@sword ~]#
下载完安装包,并解压 tgz(以下演示的是 64 位 Linux上的安装) 。
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz # 下载
tar -zxvf mongodb-linux-x86_64-3.0.6.tgz # 解压
mv mongodb-linux-x86_64-3.0.6/ /usr/local/mongodb
MongoDB 的可执行文件位于 bin 目录下,所以可以将其添加到 PATH 路径中:
export PATH=<mongodb-install-directory>/bin:$PATH
创建数据库目录:
MongoDB 的数据存储在data目录的db目录下,但是这个目录在安装过程不会自动创建,
所系你需要手动创建data目录,并在data目录中创建db目录。
以下实例中我们将data目录创建于根目录下(/)。
注意:/data/db 是 MongoDB 默认的启动的数据库路径(--dbpath)。
mkdir -p /data/db
命令行中运行MongDB服务:
你可以再命令行中执行mongo安装目录中的bin目录执行mongod命令来启动mongdb服务。
注意:如果你的数据库目录不是/data/db,可以通过 --dbpath 来指定。
[root@adminset ~]# mkdir -p /data/db
[root@adminset ~]# mongod
2018-09-28T11:39:32.002-0400 I JOURNAL [initandlisten] journal dir=/data/db/journal
2018-09-28T11:39:32.002-0400 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
2018-09-28T11:39:32.130-0400 I JOURNAL [durability] Durability thread started
2018-09-28T11:39:32.131-0400 I JOURNAL [journal writer] Journal writer thread started
2018-09-28T11:39:32.132-0400 I CONTROL [initandlisten] MongoDB starting : pid=24636 port=27017 dbpath=/data/db 64-bit host=adminset
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten]
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten]
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten]
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten]
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten] db version v3.0.6
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten] git version: 1ef45a23a4c5e3480ac919b28afcba3c615488f2
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten] build info: Linux build6.ny.cbi.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
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten] allocator: tcmalloc
2018-09-28T11:39:32.133-0400 I CONTROL [initandlisten] options: {}
2018-09-28T11:39:32.135-0400 I INDEX [initandlisten] allocating new ns file /data/db/local.ns, filling with zeroes...
2018-09-28T11:39:32.193-0400 I STORAGE [FileAllocator] allocating new datafile /data/db/local.0, filling with zeroes...
2018-09-28T11:39:32.193-0400 I STORAGE [FileAllocator] creating directory /data/db/_tmp
2018-09-28T11:39:32.198-0400 I STORAGE [FileAllocator] done allocating datafile /data/db/local.0, size: 64MB, took 0.002 secs
2018-09-28T11:39:32.215-0400 I NETWORK [initandlisten] waiting for connections on port 27017