Download required software (download to the/usr/local/src directory)
The code is as follows: |
Copy code |
# 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 |
Install python:
The code is as follows: |
Copy code |
# Yum install-y python-devel
|
Install scons: Download scons (http://www.scons.org/download.php)
The code is as follows: |
Copy code |
Tar zxf scons-2.0.1.tar.gz Cd scons-2.0.1 Python setup. py install |
Install spidermonkey Library, download js api library js-1.7.0.tar.gz (http://ftp.mozilla.org/pub/mozilla.org/js/) that supports c)
The code is as follows: |
Copy code |
Yum install-y 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 ../.. |
Install pcre
The code is as follows: |
Copy code |
Tar zxf pcre-8.12.tar.gz Cd pcre-8.12 ./Configure -- enable-utf8 -- enable-unicode-properties Make & make install Cd .. |
Install MongoDB
The code is as follows: |
Copy code |
Tar zxf mongodb-src-r1.8.1.tar.gz Cd mongodb-src-r1.8.1 Scons all // scons may fail to find the pcre library (modify/etc/ld. so. conf is useless, is the scons itself), then you need to open the mongodb-src-r1.8.0 under the SConstruct, find [linux2 "= OS. sys. platform:], add the installation path of the pcrecpp Library after LIBPATH, add the pcrecpp Library name after LIBS, and then re-scons all (Operation: vim SConstruct; original: env. append (LIBPATH = ["/usr/lib64", "/lib64"]); after modification, env. append (LIBPATH = ["/usr/lib64", "/lib64", "/usr/local/pcre/lib"]); next in env. append (LIBS = ["pthread"]) followed by env. append (LIBS = ["libpcrecpp"]) Scons -- prefix =/usr/local/mongo install To install lib and head, use the following method: Scons -- prefix =/usr/local/mongo -- full install |
Create a configuration file
The code is as follows: |
Copy code |
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 Add the following content to mongo. 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
The code is as follows: |
Copy code |
Ln-s/usr/local/mongo/bin/mongod/usr/bin/mongod Mongod-f/usr/local/mongo/etc/mongo. conf |
Check whether it is started, but it is unwise to use this method to manage the mongodb server. Let's improve it:
The code is as follows: |
Copy code |
Mkdir-p/usr/local/mongo/srv Vim/usr/local/mongo/srv/mongodb-start |
Add the following content
The code is as follows: |
Copy code |
#! /Bin/sh Mongod-f/usr/local/mongo/etc/mongo. conf Vim/usr/local/mongo/srv/mongodb-stop |
Add the following content
The code is as follows: |
Copy code |
#! /Bin/bash Pid = 'PS-o pid, command ax | grep mongod | awk '! /Awk /&&! /Grep/{print $1 }''; If ["$ {pid }"! = ""]; Then Kill-2 $ {pid }; Fi |
Add execution permission
The code is as follows: |
Copy code |
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 |
Add the following content
The code is as follows: |
Copy code |
#! /Bin/sh # # Mongodb-this script starts and stops the mongodb daemon # # Chkconfig:-85 15 # 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 0 Set-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 |
Add Service
The code is as follows: |
Copy code |
Chmod a + x/etc/rc. d/init. d/mongodb Chkconfig -- add mongodb Chkconfig -- level 345 mongodb on /Etc/rc. d/init. d/mongodb start |