近段时间感觉有点迷茫了,不知道该做什么,今天上班看看自己的监控数据,想想能不能为了读写速度我把数据写入到mongodb里面这种非关系型数据库里面呢,下面开始学习mongodb:
1、安装:
下载:wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.3.tgz
[root@saltstack mongodb]
# tar xvfz mongodb-linux-x86_64-2.6.3.tgz -C /usr/local/
[root@saltstack mongodb]# mv mongodb-linux-x86_64-2.6.3 mongodb
编辑.bash_profile文件,加入MongoDB的路径,然后刷新一下该文件
[root@saltstack mongodb]# vim .bash_profile
MONGO_BIN=
/usr/local/mongodb/bin
export
PATH=$PATH:$MONGO_BIN
[root@saltstack mongodb]# source /root/.bash_profile
2、为了方便管理,给出配置文件和启动脚本:
(1)[root@saltstack mongodb]# cat /etc/mongod.conf
bind_ip=127.0.0.1
port=27017
fork=true
quiet=false
dbpath=/opt/mongodata
logpath=/opt/log/mongodb/mongod.log
logappend=true
journal=true
auth=true
(2)建立数据库文件目录:
mkdir /opt/mongodata
(3)设置启动服务器脚本:
[root@saltstack mongodb]# cat /etc/init.d/mongod
#!/bin/bash
config_file=/etc/mongod.conf
lock_file=/opt/mongodata/mongod.lock
bin_file=/usr/local/mongodb/bin/mongod
start(){
pid=`cat "$lock_file" 2>/dev/null`
if [ -z "$pid" ];then
"$bin_file" --config="$config_file"
echo "mongod is start!"
else
echo "mongod is running!"
fi
}
stop(){
pid=`cat "$lock_file" 2>/dev/null`
if [ -z "$lock_file" ];then
echo "mongod is not running!"
else
kill -2 $pid
echo "mongod is stop!"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}"
exit 3
;;
esac
exit 0
安装之后启动测试:
[root@saltstack mongodb]# /etc/init.d/mongod start
[root@saltstack mongodb]# mongostat
connected to: 127.0.0.1
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn time
*0 *0 *0 *0 0 1|0 0 240m 777m 32m 0 xiaoluo:0.0% 0 0|0 0|0 62b 3k 1 06:22:04
*0 *0 *0 *0 0 1|0 0 240m 777m 32m 0 xiaoluo:0.0% 0 0|0 0|0 62b 3k 1 06:22:05
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。