【一】MongoDB安装及配置
一、MongoDB安装
1、下载并解压
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.0.tgz tar zxvf mongodb-linux-x86_64-rhel62-3.2.0.tgz
2、移动到指定目录下
mv mongodb-linux-x86_64-rhel62-3.2.0 /usr/local/mongodb
3、添加到PATH中
vim /etc/profile export PATH=/usr/local/mongodb/bin:$PATH source /etc/profile
二、MongoDB配置启动
1、创建数据目录和日志目录
默认下,mongodb的数据目录在/data/db,如果放到其他目录启动时需要指定--dbpath参数。
mkdir -p /data/db mkdir -p /data/log touch /data/log/mongodb.log
2、启动mongod服务
[root@node1 log]# mongod --dbpath=/data/db --fork --logpath=/data/log/mongodb.log #默认启动27017端口
about to fork child process, waiting until server is ready for connections.
forked process: 45134
child process started successfully, parent exiting
参数说明:
--dbpath #数据文件存储路径 --fork #用子进程在后台启动,否则一直占有终端,用该参数时,必须指定logpath参数 --logpath #日志文件的存储路径 --httpinterface #网页管理mongodb接口,之前版本默认是开启的,由于安全性,本版本默认是关闭的,如需要加上该参数启动
3、连接到mongodb
[root@node1 ~]# mongo MongoDB shell version: 3.2.0 connecting to: test Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user Server has startup warnings: 2015-11-29T11:04:05.002+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2015-11-29T11:04:05.002+0800 I CONTROL [initandlisten] 2015-11-29T11:04:05.002+0800 I CONTROL [initandlisten] 2015-11-29T11:04:05.003+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2015-11-29T11:04:05.003+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2015-11-29T11:04:05.003+0800 I CONTROL [initandlisten] 2015-11-29T11:04:05.003+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2015-11-29T11:04:05.003+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2015-11-29T11:04:05.003+0800 I CONTROL [initandlisten] > 2+3 5
4、关闭mongod服务
mongod --dbpath=/data/db --fork --logpath=/data/log/mongodb.log --shutdown