(二):Centos7安装mongodb3.4.6步骤
1、下载
下载mongodb www.mongodb.org 下载最新的stable版
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.6.tgz
2、解压文件
3、移动文件夹
不用编译,本身就是编译后的二进制可执行文件.
进入bin目录下:

注:mongosniff、mongostat、mongotop:用于监控mongodb状态


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 #显示性能统计信息
#将解压的文件夹重命名为mongodb并移动到/usr/local,目录下
4、将bin目录添加到环境变量中
vim /etc/profile
source /etc/profile
5、创建指定数据文件夹
创建数据库目录:/data/db
创建数据库日志目录:/data/log
6、启动数据库服务
创建mongodb配置文件,在vi /etc/mongod.conf
[root@mongodb1 bin]# cat /etc/mongod.conf port=27017 dbpath=/data/db logpath=/data/log/mongod.log fork = true
[root@master ~]# mongod -f /etc/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 16111
child process started successfully, parent exiting
启动完成之后就可以使用mongo连接数据库了:
[root@master ~]# mongo MongoDB shell version v3.4.6 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.6 Server has startup warnings: 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] >
7、关闭数据库
先到admin下,在使用db.shutdownServer()来关闭数据库,注意mongodb是区分大小写的
[root@master ~]# mongo MongoDB shell version v3.4.6 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.6 Server has startup warnings: 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2017-08-03T21:12:31.561+0800 I CONTROL [initandlisten] > use admin switched to db admin > db.shutdownServer() server should be down... 2017-08-03T21:15:18.676+0800 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 2017-08-03T21:15:18.676+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused 2017-08-03T21:15:18.676+0800 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed > exit bye [root@master ~]#
查看mongodb的进程(已经不存在了)
[root@master ~]# ps -ef |grep mong root 16143 9897 0 21:16 pts/0 00:00:00 grep --color=auto mong [root@master ~]#
注意:8、mongodb非常的占磁盘空间, 刚启动后要占3-4G左右,(查看:启动后 ll /data)
如果你用虚拟机练习,可能空间不够,导致无法启动.
可以用 --smallfiles 选项来启动,(mongod --smallfiles -f /etc/mongod.conf)
将会占用较小空间 400M左右.

浙公网安备 33010602011771号