在Linux系统部署MongoDB
1、下载mongodb-Linux-x86_64-2.6.8.tgz安装包
2、安装MongoDB到 /usr/local/ 目录下
解压,重命名为mongodb,并移至 /usr/local/ 目录
[root@localhost home]# tar -zvxf mongodb-linux-x86_64-2.6.8.tgz
[root@localhost home]# mv mongodb-linux-x86_64-2.6.8 mongodb
[root@localhost home]# mv mongodb /usr/local/
修改权限
[root@localhost local]# chmod -R 755 mongodb
修改配置文件
[root@localhost local]# vim mongodb/bin/mongodb.conf
dbpath=/usr/local/mongodb/db
logpath=/usr/local/mongodb/logs/mongodb.log
bind_ip=0.0.0.0
port=27017
fork=true
nohttpinterface=true
3、在mongodb目录下创建db和logs文件夹,用于存放数据库文件和日志文件。
[root@localhost mongodb]# mkdir db
[root@localhost mongodb]# mkdir logs
4、添加mongodb为系统服务,打开编辑器粘贴下面内容,然后保存为mongod.
[root@localhost bin]# vim /etc/rc.d/init.d/mongod
ulimit -SHn 655350
#!/bin/sh
# chkconfig: - 64 36
# description:mongod
case $1 in
start)
/usr/local/mongodb/bin/mongod --maxConns 20000 --config /usr/local/mongodb/bin/mongodb.conf
;;
stop)
/usr/local/mongodb/bin/mongo 127.0.0.1:27017/admin --eval "db.shutdownServer()"
;;
status)
/usr/local/mongodb/bin/mongo 127.0.0.1:27017/admin --eval "db.stats()"
;;
esac
保存完成之后,添加脚本执行权限
[root@localhost bin]# chmod +x /etc/rc.d/init.d/mongod
5、启动mongodb
[root@localhost bin]# service mongod start
warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default about to fork child process, waiting until server is ready for connections.
forked process: 70657
child process started successfully, parent exiting
查看进程
[root@localhost bin]# ps aux | grep mong
root 70657 0.5 0.4 355840 31232 ? Sl 18:11 0:00 /usr/local/mongodb/bin/mongod --maxConns 20000 --config /usr/local/mongodb/bin/mongodb.conf
6、设置mongodb为开机启动
[root@localhost bin]# chkconfig mongod on
[root@localhost mongodb]# chkconfig --list
gmetad 0:off 1:off 2:on 3:on 4:on 5:on 6:off
gmond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
mongod 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
7、后台启动MongoDB服务
nohup /usr/bin/mongod --config /etc/mongodb.conf&
8、[ END ]