近段時間感受有點迷茫了,不知道該作什麼,今天上班看看本身的監控數據,想一想能不能爲了讀寫速度我把數據寫入到mongodb裏面這種非關係型數據庫裏面呢,下面開始學習mongodb:linux
一、安裝:mongodb
下載: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/
vim
[root@saltstack mongodb]# mv mongodb-linux-x86_64-2.6.3 mongodb
bash
編輯.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
app
二、爲了方便管理,給出配置文件和啓動腳本:ide
(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.1insert 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