mongodb download the latest version of mongodb from the official website, and install it according to the instructions on the official website:
curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.3.tgz
tar -zxvf mongodb-linux-x86_64-2.6.3.tgz
Follow the command
mkdir -p mongodb
cp -R -n mongodb-linux-x86_64-2.6.3/ mongodb
export PATH=<mongodb-install-directory>:$PATH
Just replace it with your mongodb path
mkdir -p /usr/local/mongo/data
mongod --dbpath /usr/local/mongo/data
The above installation method is relatively simple, but there is a problem, that is, mongo must be started at the same time as the data, which is to run mongod --dbpath /usr/local/mongo/data, which is more cumbersome. The following introduces a once and for all installation method. The start of mongo is added to the service. However, the version to be installed must be determined. In this example, use mongodb-src-r1.8.1.tar.gz to refer to the blog: http://www.9958.pw/post/centos_mongodb Note: Each version must be consistent with the blog. Let’s reprint this article on the rin blog!
# wget http://downloads.mongodb.org/src/mongodb-src-r1.8.1.tar.gz#wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz#wget http://sourceforge.net/projects/pcre/files/pcre/8.12/pcre-8.12.tar.bz2
(Note: scons must be 2.0.1, the specific download address is http://prdownloads.sourceforge.net/scons/scons-2.0.1.tar.gz):
# yum install -y python-devel
Install scons:Download scons (http://www.scons.org/download.php)
tar zxf scons-2.0.1.tar.gz
cd scons-2.0.1
python setup.py install
Download the js api library js-1.7.0.tar.gz that supports c (http://ftp.mozilla.org/pub/mozilla.org/js/)
yum install -y boost boost-devel
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 ../..
tar zxf pcre-8.12.tar.gz
cd pcre-8.12./configure --enable-utf8 --enable-unicode-properties
make && make install
cd ..
tar zxf mongodb-src-r1.8.1.tar.gz
cd mongodb-src-r1.8.1
scons all //scons may not find the pcre library(modify/etc/ld.so.conf is also useless,It's scons' own problem), Then you need to open mongodb-src-r1.8.SConstruct under 0, find [linux2"== os.sys.platform:], add the installation path of the pcrecpp library after LIBPATH, add the name of the pcrecpp library after LIBS, and then re-scons all(Operation: vim SConstruct;It turned out: env.Append( LIBPATH=["/usr/lib64" , "/lib64" ] ) ;modify后env.Append( LIBPATH=["/usr/lib64" , "/lib64" ,"/usr/local/pcre/lib"]);Next in env.Append( LIBS=["pthread"] )Add env.Append( LIBS=["libpcrecpp"] ) )
scons --prefix=/usr/local/mongo install
If you need to install lib and head, use the following method to install
scons --prefix=/usr/local/mongo --full install
mkdir -p /usr/local/mongo/etc /usr/local/mongo/data /usr/local/mongo/log//usr/local/mongo/repair
vim /usr/local/mongo/etc/mongo.conf
In mongo.Add the following content to conf
dbpath =/usr/local/mongo/data
logpath =/usr/local/mongo/mongodb.log
repairpath =/usr/local/mongo/repair
pidfilepath =/usr/local/mongo/mongodb.pid
directoryperdb =true
logappend =true
noauth =true
port =27017
maxConns =1024
fork =true
rest =true
quota =true
quotaFiles =1024
nssize =16
Start mongodb
ln -s /usr/local/mongo/bin/mongod /usr/bin/mongod
mongod -f /usr/local/mongo/etc/mongo.conf
mkdir -p /usr/local/mongo/srv
vim /usr/local/mongo/srv/mongodb-start
#! /bin/sh
mongod -f /usr/local/mongo/etc/mongo.conf
vim /usr/local/mongo/srv/mongodb-stop
#! /bin/bash
pid=`ps -o pid,command ax | grep mongod | awk '!/awk/ && !/grep/ {print $1}'`;if["${pid}"!=""]; then
kill -2 ${pid};
fi
chmod a+x /usr/local/mongo/srv/mongodb-start
chmod a+x /usr/local/mongo/srv/mongodb-stop
vim /etc/rc.d/init.d/mongodb
#! /bin/sh
#
# mongodb – this script starts and stops the mongodb daemon
#
# chkconfig:-8515
# description: MongoDB is a non-relational database storage system.
# processname: mongodb
# config:/usr/local/mongo/etc/mongo.conf
# pidfile:/usr/local/mongo/mongodb.pid
PATH=/usr/local/mongo/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=mongodb
test -x $DAEMON || exit 0set-e
case"$1"in
start)
echo -n "Starting MongoDB... "/usr/local/mongo/srv/mongodb-start
;;
stop)
echo -n "Stopping MongoDB... "/usr/local/mongo/srv/mongodb-stop
;;*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop}">&2
exit 1;;
esac
exit 0
chmod a+x /etc/rc.d/init.d/mongodb
chkconfig --add mongodb
chkconfig --level 345 mongodb on/etc/rc.d/init.d/mongodb start
Recommended Posts