作者:XC一米_623 | 来源:互联网 | 2014-05-28 16:53
mongodb的安装1.先下载最新的mongodb版本wgethttp://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.2.tgzwget下载的文件默认在当前目录2.解压大指定目录tar-zxvfmongodb-linux-i686-2.0.2.tgz/usr/loc
mongodb的安装
1.先下载最新的mongodb版本
wget
http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.2.tgz
wget 下载的文件默认在当前目录
2.解压大指定目录
tar -zxvf mongodb-linux-i686-2.0.2.tgz /usr/local/mongodb
3.创建数据库运行时需要的数据存储和日志目录
mkdir -p /data/mongodb
4.配置mongodb启动参数
vi /etc/mongodb.conf
dbpath=/data/mongodb
master=true
logpath=/data/mongodb/mongodb.log
logappend=true
进入mongodb安装目录
# cd /usr/local/mongodb/bin
运行mongo
# ./mongod -f /etc/mongodb.conf &
通过ps -def | grep mongod 可以查看到已经启动的服务进程
root 1082 1 0 07:48 ?
00:00:05 /usr/local/mongodb/bin/mongod
-f /etc/mongod.conf
root 1284 1269 0 08:33 pts/0
00:00:00 grep mongod
rockmongo安装配置
rockmongo是php写的一个mongodb管理工具,所以安装rockmongo前先安装php和apache
安装很简单
配置PATH
# ~/.bashrc: executed by bash(1) for non-login shells.
#Source global definations
if [ -f /etc/bashrc ]; then
./etc/bashrc
fi
#path
PATH="/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
PATH="$PATH":/usr/local/mongodb/bin
# Some more alias to avoid making mistakes:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias vi='vim'
alias mOnod='mongod -f /etc/mongod.conf &'
让mongodb在系统启动时就自启动
让mongodb在系统启动是就启动需要在/etc/init.d下加入mongodb的sh文件
1.建立/etc/init.d/mongodb文件
vi /etc/init.d/mongodb
#!/bin/sh
### BEGIN INIT INFO
# Provides: mongod
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop
### END INIT INFO
# Source function library.
. /lib/lsb/init-functions
retval=0
pidfile=`ps -ef | grep 'mongod' | grep -v grep | awk '{print
$2}'`
COnFIG="/etc/mongod.conf"
PROGRAM="/usr/local/mongodb/bin/mongod"
MOnGOPID=`ps -ef | grep 'mongod' | grep -v grep | awk '{print
$2}'`
test -x $PROGRAM || exit 0
case "$1" in
start)
ulimit -n 3000
log_begin_msg "Starting MongoDB server"
$PROGRAM -f $CONFIG &
log_end_msg 0
;;
stop)
log_begin_msg "Stopping MongoDB server"
if [ ! -z "$MONGOPID" ]; then
kill -15 $MONGOPID
fi
log_end_msg 0
;;
status)
;;
*)
log_success_msg "Usage: /etc/init.d/mongodb
{start|stop|status}"
exit 1
esac
exit 0
2.保存文件并修改权限
chmod +x /etc/init.d/mongodb
3.注册开机脚本
update-rc.d mongodb defaults
4.重启执行mongo命令看看是否成功
root@debian:~# mongo
MongoDB shell version: 2.0.2
connecting to: 192.168.118.203:27017/test
>
启动成功