系统环境:Centos-7 64位
下载地址:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.5.tgz
上传位置:/usr/local/src
软件安装位置:/usr/local/mongodb
数据存放位置:/usr/local/mongodb/data
日志存放位置:/usr/local/mongodb/logs
安装
解压
[[email protected] /]# cd /usr/local/src
[[email protected] src]# tar -zxv -f mongodb-linux-x86_64-rhel70-3.2.5.tgz
[[email protected] src]# mv mongodb-linux-x86_64-rhel70-3.2.5.tgz /usr/local/mongodb
[[email protected] src]# cd /usr/local/mongodb
创建数据库目录和日志目录
[[email protected] mongodb]#mkdir -p /usr/local/mongodb/data
[[email protected] mongodb]#mkdir -p /usr/local/mongodb/logs
配置防火墙
# vi /etc/sysconfig/iptables
插入
-A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
# service iptables restart
启动mongodb
Mongodb的默认数据库目录是/data/db,改变目录需要在启动时添加路径配置
[[email protected] /]# cd /usr/local/mongodb
[[email protected] mongodb]# ./bin/mongod --dbpath=/usr/local/mongodb/data --logpath /usr/local/mongodb/logs/log.txt --logappend --fork
看到如下信息说明已经安装完成并成功启动:
about to fork child process, waiting until server is ready for connections. forked process: 35828 child process started successfully, parent exiting
停止mongodb
[[email protected] /]# cd /usr/local/mongodb
[[email protected] mongodb]# ./bin/mongod --shutdown --dbpath /usr/local/mongodb/data/
添加Centos开始启动项
[[email protected] src]# vi + /etc/rc.d/rc.local
将mongodb启动命令追加到本文件中:
/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data –logpath
/usr/local/mongodb/logs/log.txt --logappend --fork