How to compile and install MongoDB in CentOS

Source: Internet
Author: User
Tags install mongodb mkdir mongodb mongodb server php mongodb centos

CentOS5 compiling and installing mongodb

Mongodb has a compiled binary package, which can be decompressed to the corresponding directory.
The following describes how to edit and install the SDK from the source code.

Before installation:

Install scons

Wget http://prdownloads.sourceforge.net/scons/scons-2.3.4.tar.gz
Python setup. py install

Download and install mongodb source code:

Wget https://github.com/mongodb/mongo/archive/r2.2.7-rc0.tar.gz
Tar xvf r2.2.7-rc0.tar.gz-C/usr/src
Cd/usr/src/mongo-r2.2.7-rc0
Scons -- prefix =/usr/local/mongo install

Configuration:

Mkdir-p/usr/local/mongo/etc
Cp/usr/src/mongo-r2.2.7-rc0/rpm/ipvd. conf/usr/local/mongo/etc

Note: If necessary, edit the mongod. conf configuration file and specify the data storage directory.
For example, my configuration:

Logpath =/var/log/mongo/mongod. log
Logappend = true
Fork = true
Dbpath =/data0/mongodb
Pidfilepath =/var/run/mongodb/mongod. pid

Start:

/Usr/local/mongo/bin/mongod -- config =/usr/local/mongo/etc/mongod. conf

Test connection:

[Root @ localhost ~] #/Usr/local/mongo/bin/mongo
MongoDB shell version: 2.2.7-rc0
Connecting to: test
> Show dbs;
Local 0.078125 GB
Mydb 0.203125 GB
Sina 0.453125 GB
Wiki_bak 0.203125 GB


Compile and install MongoDB on CentOS6

1. Install the dependent software package
# Yum install pcre-devel python-devel scons

2. Download the latest source code package from the official website.
Http://www.mongodb.org/downloads

3. Use the Py compilation tool scons for compilation and installation
# Tar zxf mongdb-src.tar.gz
// Extract
# Cd mongodb-src
# Scons-j 8 all // use 8 threads for parallel compilation. We recommend that you use the number of CPU cores.
# Scons-prefix =/usr/local/mongo install
// If you need the lib library and include header files, add the-full parameter as follows:
# Scons-prefix =/usr/local/mongo-full install

4. Add mongodb users and configurations
# Useradd mongodb-M-s/sbin/nologin

// Create a directory and customize it as needed
# Mkdir-pv/etc/mongo // configuration file path
# Mkdir-pv/var/lib/mongo // data storage path
# Mkdir-pv/var/log/mongo // log file path
# Mkdir-pv/var/run/mongodb // Pid path

// Copy the configuration file in the source code package to/etc/mongo
# Cp mongodb-src/rpm/mongod. conf/etc/mongo

// Grant log and data path access permissions to the mongodb User Group
# Chown-R mongodb. mongodb/var/log/mongodb
# Chown-R mongodb. mongodb/var/lib/mongodb

5. Edit the configuration file
# Vi/etc/mongo/mongod. conf
-- Refer to the following path for configuration instructions --
Dbpath =/var/lib/mongo
Logpath =/var/log/mongo
Pidfilepath =/var/run/mongodb/mongod. pid
Directoryperdb = true
Logappend = true
Noauth = true
Port = 27017
MaxConns = 1024
Fork = true
Rest = true
Quota = true
QuotaFiles = 1024.
Nssize = 16
-- End of configuration reference --

6. Configure the Boot File
// Save The following script as mongod and place it under/etc/rc. d/init. d/, and grant the execution permission.

#! /Bin/sh
#
# Mongodb init file for starting up the MongoDB server
#
# Chkconfig:-20 80
# Description: Starts and stops the MongDB daemon that handles all \
# Database requests.

# Source function library.
./Etc/rc. d/init. d/functions

Exec = "/usr/local/mongo/bin/mongod"
Prog = "mongod"
Logfile = "/var/log/mongodb. log"
Options = "-f/etc/mongo/mongod. conf"

[-E/etc/sysconfig/$ prog] &./etc/sysconfig/$ prog

Lockfile = "/var/lock/subsys/mongod"

Start (){
[-X $ exec] | exit 5
Echo-n $ "Starting $ prog :"
Daemon -- user mongodb "$ exec -- quiet $ options run >>$ logfile 2> & 1 &"
Retval =$?
Echo
[$ Retval-eq 0] & touch $ lockfile
Return $ retval
}

Stop (){
Echo-n $ "Stopping $ prog :"
Killproc $ prog
Retval =$?
Echo
[$ Retval-eq 0] & rm-f $ lockfile
Return $ retval
}

Restart (){
Stop
Start
}

Reload (){
Restart
}

Force_reload (){
Restart
}

Rh_status (){
# Run checks to determine if the service is running or use generic status
Status $ prog
}

Rh_status_q (){
Rh_status>/dev/null 2> & 1
}


Case "$1" in
Start)
Rh_status_q & exit 0
$1
;;
Stop)
Rh_status_q | exit 0
$1
;;
Restart)
$1
;;
Reload)
Rh_status_q | exit 7
$1
;;
Force-reload)
Force_reload
;;
Status)
Rh_status
;;
Condrestart | try-restart)
Rh_status_q | exit 0
Restart
;;
*)
Echo $ "Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload }"
Exit 2
Esac
Exit $?

# Chkconfig-add mongod
// Set to start upon startup
# Service producer d start
// Start and test whether Port 27017 is enabled. If the configuration is incorrect, check the log output information in/var/log/mongo.

7. PHP MongoDB extension installation

Search for mongo from http://pecl.php.net/and get the latest stable version of the extension package
# Tar zxf mongo-1.3.0.tgz
# Cd mongo-1.3.0
#/Usr/local/php/bin/phpize
#./Configure-with-php-config =/usr/local/php/bin/php-config // note the php-config installation path
# Make & make install
// Decompress and configure for installation

Edit the php. ini configuration file and add it to the last line.

Extension = mongo. so

// If no other extensions have been installed before, specify the extension_dir extension directory first.
After the installation is complete, restart PHP and check that the phpinfo mongo project appears.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.