Installation and configuration of MongoDB database under linux/centos6.3

Source: Internet
Author: User
Tags chmod create mongodb mongodb client mongodb server

Download the source code:(Put in the /usr/local/src directory)

To the official website Download the source code


Https:// (32-bit)

Note: 32-bit system installs 32-bit, 64-bit system installs 64-bit!

Installing MongoDB

#Create a mongodb installation related directory

mkdir -pv /usr/local/mongodb
mkdir -pv /usr/local/mongodb/etc
mkdir -pv /usr/local/mongodb/data
mkdir -pv /usr/local/mongodb/logs
mkdir -pv /usr/local/mongodb/repair

#Move the bin folder in the unpacked package to the installation directory

cd /usr/local/src/
tar -xzvf ./mongodb-linux-i686-2.2.7.tgz
cd ./mongodb-linux-i686-2.2.7
mv ./bin /usr/local/mongodb

#Create mongodb user and mongodb user group

groupadd mongodb
useradd -g mongodb -s /usr/sbin/nologin mongodb
chown -R mongodb:mongodb /usr/local/mongodb

#Create a configuration file mongodb.conf
vim /usr/local/mongodb/etc/mongodb.conf


Add the following content:

DBPath =/usr/local/mongodb/data
LogPath =/usr/local/mongodb/logs/mongodb.log

Fork = True

#start mongodb


See if it's starting up, but it's unwise to manage the MongoDB server in this way, and we'll refine it:

mkdir -p /usr/local/mongodb/srv
vim /usr/local/mongodb/srv/mongodb-start

Add the following content



Add the following content

Pid= ' ps-o Pid,command ax | grep Mongod | awk '!/awk/&&!/grep/{print '} ';
if ["${pid}"! = ""]; Then
Kill-2 ${pid};

Add Execute Permissions

chmod a+x /usr/local/mongodb/srv/mongodb-start
chmod a+x /usr/local/mongodb/srv/mongodb-stop

vim /etc/rc.d/init.d/mongodb

Add the following content

#! /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/mongodb/etc/mongodb.conf
# pidfile: /usr/local/mongodb/

test -x $DAEMON || exit 0
set -e
case "$1" in
		echo -n "Starting MongoDB... "
		echo -n "Stopping MongoDB... "
		echo "Usage: $N {start|stop}" >&2
		exit 1
exit 0

Add Service

chmod a+x /etc/rc.d/init.d/mongodb
chkconfig --add mongodb
chkconfig --level 345 mongodb on
service mongodb start  // 或 /etc/rc.d/init.d/mongodb start

" Backup: Previous practices "

#Set boot

Echo "/usr/local/mongodb/bin/mongod--dbpath=/usr/local/mongodb/data--logpath=/usr/local/mongodb/logs/ Mongodb.log--fork ">>/etc/rc .local

#Start mongodb

/usr/local/mongodb/bin/mongod--dbpath=/usr/local/mongodb/data--logpath/usr/local/mongodb/logs/mongodb.log-- Fork

Join the firewall #Add port 27017 to the firewall (reference: CentOS6.3 compile and install memcached)

Note: the database port and the Web port, respectively 27017 and 28017, open the http://localhost:28017 in the browser, and you can see some related information.

Service iptables Restart     //restart Firewall

Problems that may occur:

Question one:

-bash:/usr/local/bin/mongo:/lib/ ELF Interpreter: No file or directory


Yum Install

Question two:

Mongo:error while loading shared open Shared object file:no such file or directory


Yum whatprovides Install

Question three: View the contents of the log as follows

Tue Jan  4 09:51:37 MongoDB starting:pid=2794 port=27017 dbpath=/var/lib/mongodb 32-bit

* * Note:when using MongoDB, limited to about 2 gigabytes of data
* *       See Http://blog. MongoDB. org/post/137788967/32-bit-limitations

Tue Jan  4 09:51:37 db version v1.6.5, pdfile version 4.5
T UE Jan  4 09:51:37 git version:0eb017e9b2828155a67c5612183337b89e12e291
Tue Jan  4 09:51:37 sys info:linux DOMU-12-31-39-01-70-B4 #1 SMP Fri Feb 12:39:36 EST. i686 boost_lib_version=1_37
************* *
Old lock file:/var/lib/mongodb/mongod.lock.  probably means unclean shutdown
recommend removing file and RU Nning--repair
See:http://dochub.mongodb. Org/core/repair For more information
Tue Jan  4 09:51:37 exception in Initandlisten std::exception:old lock file, terminating
Tue Jan  4 09:51:37 dbexit:


Installing the MongoDB Client for PHP

Official website (Http://

Cd /usr/local/src
Wget -c
Tar -xzvf ./mongo-1.4.4.tgz
Cd ./mongo-1.4.4
/usr/local/php/bin/phpize # Use PHP's phpize command to install extensions
./configure --with-php-config=/usr/local/php/bin/php-config
Make && make install 

When you're done, edit your php.ini file to add a line.

Extended reading:

Installing MongoDB under Windows

PHP5 do not recompile, how do I install a self-installed extension, such as a SOAP extension?

MongoDB Basic Management Command

Single-Machine build Elasticsearch and MongoDB River data synchronization

Installation and configuration of MongoDB database under linux/centos6.3

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: 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.