Linux tar.gz安装mongodb
安装环境CentOS 6,理论其他环境一样,下载对应版本即可
安装
- 下载wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-4.4.16.tgz
- 解压tar -zxvf mongodb-linux-x86_64-rhel62-4.4.16.tgz
- mv mongodb-linux-x86_64-rhel62-4.4.16 /usr/local/mongodb
- 环境配置export PATH=/usr/local/mongodb/bin:$PATH
mongo.conf配置
#加入以下内容
dbpath=/usr/local/mongodb/data #事先创建该文件
logpath=/usr/local/mongodb/logs/mongo.log #事先创建该文件
logappend=true
journal=true
quiet=true
port=27017
fork=true #后台运行
bind_ip=0.0.0.0 #允许任何IP进行连接
- mongo.log必须事先创建,否则会提示如下错误
ERROR: child process failed, exited with 1
To see additional information in this output, start without the "--fork" option.
- 启动mongodb命令如下
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongo.conf
配置启动脚步
#!/bin/bash
#chkconfig: 2345 80 90
#description: mongodb
start() {
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongo.conf
}
stop() {
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongo.conf --shutdown
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
netstat -tulnp|grep mongod
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
设置启动
vi /etc/init.d/mongodb
chmod +x mongodb
chkconfig --add mongodb
chkconfig mongodb on