kv永久存储mongodb
系统版本:32位CENTOS5.5
安装MongoDB
安装scons、js
yum install -y boost boost-devel pcre pcre-devel wget http://sourceforge.net/projects/scons/files/scons/2.1.0.alpha.20101125/scons-2.1.0.alpha.20101125.tar.gz/download tar xvf scons-2.1.0.alpha.20101125.tar.gz cd scons-2.1.0.alpha.20101125 python setup.py install cd .. wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz tar zxvf js-1.7.0.tar.gz cd js/src/ export CFLAGS="-DJS_C_STRINGS_ARE_UTF8" make -f Makefile.ref JS_DIST=/usr gmake -f Makefile.ref export cd ../..
安装MongoDB
wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.4.tgz tar xvf http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.4.tgz mv mongodb-linux-i686-2.0.4 /usr/local/mongodb mkdir -pv /usr/local/mongodb/data /usr/local/mongodb/etc /usr/local/mongodb/log
配置文件
cat > /usr/local/mongodb/etc/mongod.conf <<‘EOF‘ # log file to send write to instead of stdout – has to be a file, not directory logpath=/usr/local/mongodb/log/mongod.log # append to logpath instead of over-writing logappend=true # fork and run in background fork = true # specify port number port = 27017 # comma separated list of ip addresses to listen on – all local ips by default #bind_ip = 192.168.51.119 # directory for datafiles dbpath = /usr/local/mongodb/data # full path to pidfile (if not set, no pidfile is created) pidfilepath = /usr/local/mongodb/log/mongod.pid # Enables periodic logging of CPU utilization and I/O wait #cpu = true # Turn on/off security. Off is currently the default #noauth = true auth = true # Verbose logging output. #verbose = true # Inspect all client data for validity on receipt (useful for # developing drivers) #objcheck = true # Enable db quota management quota = true # Set oplogging level where n is # 0=off (default) # 1=W # 2=R # 3=both # 7=W+some reads #oplog = 0 # Diagnostic/debugging option #nocursors = true # Ignore query hints #nohints = true # Disable the HTTP interface (Defaults to localhost:27018). #nohttpinterface = true # Turns off server-side scripting. This will result in greatly limited # functionality #noscripting = true # Turns off table scans. Any query that would do a table scan fails. #notablescan = true # Disable data file preallocation. #noprealloc = true # Specify .ns file size for new databases. nssize = 16 # Accout token for Mongo monitoring server. #mms-token = <token> # Server name for Mongo monitoring server. #mms-name = <server-name> # Ping interval for Mongo monitoring server. #mms-interval = <seconds> # Replication Options # in replicated mongo databases, specify here whether this is a slave or master #slave = true #source = master.example.com # Slave only: specify a single database to replicate #only = master.example.com # or #master = true #source = slave.example.com EOF
启动脚本
cat > /etc/rc.d/init.d/mongod <<‘EOF‘ #!/bin/bash # # mongodb Startup script for the mongodb server # # chkconfig: - 64 36 # description: MongoDB Database Server # # processname: mongodb # # Source function library . /etc/rc.d/init.d/functions prog="mongod" mongod="/usr/local/mongodb/bin/mongod" OPTIONS=" -f /usr/local/mongodb/etc/mongod.conf" RETVAL=0 start() { echo -n $"Starting $prog: " $mongod $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /usr/local/mongodb/log/$prog return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc $prog RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /usr/local/mongodb/log/$prog return $RETVAL } reload() { echo -n $"Reloading $prog: " killproc $prog -HUP RETVAL=$? echo return $RETVAL } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; condrestart) if [ -f /usr/local/mongodb/log/$prog ]; then stop start fi ;; reload) reload ;; status) status $mongod RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}" RETVAL=1 esac exit $RETVAL EOF # 执行权限 chmod a+x /etc/rc.d/init.d/mongod # 添加到开机启动项 chkconfig --add mongod chkconfig mongod on
安装php mongo 扩展
wget http://pecl.php.net/get/mongo-1.2.2.tgz tar zxf mongo-1.2.2.tgz cd mongo-1.2.2 phpize ./configure make && make install
完成后在php.ini文件增加一行
[MongoDB] extension=mongo.so
成功的话phpinfo()会看到mongo一项
本文出自 “linux运维” 博客,谢绝转载!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。