Download the source code:(Put in the /usr/local/src directory)
To the official website http://www.mongodb.org/downloads Download the source code
HTTPS://FASTDL.MONGODB.ORG/LINUX/MONGODB-LINUX-X86_64-2.2.7.TGZ (64-bit)
Https://fastdl.mongodb.org/linux/mongodb-linux-i686-2.2.7.tgz (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
Ln-s/usr/local/mongodb/bin/mongod/usr/bin/mongodmongod-f/usr/local/mongodb/etc/mongodb.conf
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
#!/bin/sh
Mongod-f/usr/local/mongodb/etc/mongodb.conf
Vim/usr/local/mongodb/srv/mongodb-stop
Add the following content
#!/bin/bash
Pid= ' ps-o Pid,command ax | grep Mongod | awk '!/awk/&&!/grep/{print '} ';
if ["${pid}"! = ""]; Then
Kill-2 ${pid};
Fi
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/mongodb.pid
PATH=/usr/local/mongodb/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/mongodb/srv/mongodb-start
;;
stop)
echo -n "Stopping MongoDB... "
/usr/local/mongodb/srv/mongodb-stop
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop}" >&2
exit 1
;;
esac
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/ld-linux.so.2:bad ELF Interpreter: No file or directory
Workaround:
Yum Install ld-linux.so.2
Question two:
Mongo:error while loading shared libraries:libstdc++.so.6:cannot open Shared object file:no such file or directory
Workaround:
Yum whatprovides Libstdc++.so.6yum Install llibstdc++.so.6
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 2.6.21.7-2.fc8xen #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:
Reference: http://blog.csdn.net/a9529lty/article/details/6456969
Installing the MongoDB Client for PHP
Official website (Http://pecl.php.net/package/mongo)
Cd /usr/local/src
Wget -c http://pecl.php.net/get/mongo-1.4.4.tgz
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.
Extension=mongo.so
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