Centos6.5 install and configure mongodb

mongodb download the latest version of mongodb from the official website, and install it according to the instructions on the official website:

**First run the following command: **

curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.3.tgz

**Secondly, use tar to decompress, follow the following command **

tar -zxvf mongodb-linux-x86_64-2.6.3.tgz

**Third, create a new mongodb folder and copy the decompressed mongodb-linux-x86_64-2.6.3 to mongodb. **

Follow the command

mkdir -p mongodb
cp -R -n mongodb-linux-x86_64-2.6.3/ mongodb

Fourth, change the environment variables, find the bashrc file under the path /etc/

export PATH=<mongodb-install-directory>:$PATH

Just replace it with your mongodb path

Fifth, create the path of mongodb dbdata

mkdir -p  /usr/local/mongo/data  
mongod --dbpath /usr/local/mongo/data

**Sixth, enter the mongo folder, run the mongo command, and start mongo. **

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!

Download the required software (download to /usr/local/src directory)

# 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

(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

**Install spidermonkey library, **

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

Install pcre

tar zxf pcre-8.12.tar.gz
cd pcre-8.12./configure --enable-utf8 --enable-unicode-properties
make && make install
cd ..

Install MongoDB

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&#39;s scons&#39; 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

Create configuration file

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

**See if it is up, but it is not wise to use this method to manage the mongodb server, let's improve it: **

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

Add the following content

#! /bin/sh
mongod -f /usr/local/mongo/etc/mongo.conf
vim /usr/local/mongo/srv/mongodb-stop

Add the following content

#! /bin/bash
pid=`ps -o pid,command ax | grep mongod | awk '!/awk/ && !/grep/ {print $1}'`;if["${pid}"!=""]; then
 kill -2 ${pid};
fi

Add execution permissions

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

#! /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

Add service

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

Centos6.5 install and configure mongodb
Install and configure keepalived under CentOS 5.9
CentOS 8 - install and configure NFS service
CentOS Minimal install and configure TIPS
Install and configure FreeIPA in Centos7
Install centos7 and connect
Install MongoDB on CentOS 7
Centos7 install mongodb 4.x
VMware Fusion install CentOS7 and configure the network
How to install and configure Elasticsearch on CentOS 7
How to install and configure VNC on CentOS 8
How to install and configure Redis on CentOS 8
How to install and configure phpMyAdmin on CentOS 6
How to install and configure Owncloud on CentOS 8
How to install and configure Redmine on CentOS 8
centos7 install python3 and ipython
Know Linux and install CentOS
CentOs7.3 compile and install Nginx 1.9.9
CentOS 7 install Mono and MonoDevelop
CentOS6.5 install Java 8 and Tomcat8
Centos compile and install Git
Centos7.5 installation and configuration MongoDB4.0.4
ubuntu install and configure GitLab
CentOS7 install python3 and pip3
CentOS7 install OracleJDK and JRE
CentOS6.5 install Java 8 and Tomcat8
CentOS6 install and crack Jira 7
CentOS6.5 install Java 8 and Tomcat8
Centos7 compile and install ntp-4.2.8p11
CentOS 6.9 compile and install python
CentOS6 install and crack confluence
CentOS 6 compile and install python 3
Install MongoDB database under CentOS7
CentOS6 install and crack Jira 7
CentOS 6.8 under linux install mongodb
How to install and configure NFS server on CentOS 8
1.5 Install Centos7
Centos 7 install jdk and package service service
CentOS7 yum install and start mysql
CentOS Yum compile and install MySQL 5.6
Compile and install LAMP under Centos 5.2
CentOS 8 install Git and basic configuration
Install and configure MySQL on Ubuntu
CentOS 6.x compile and install Nginx
Install and configure Docker in Ubuntu
CentOS7 compile and install L(A|N)MP environment
CentOS7.3 install iptables and detailed use
CentOS quickly install Python3 and pip3
CentOS7 yum install and start mysql
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple
Centos7 uninstall openJdk, and install JDK1.8
Install Python3 and ansible under CentOS8
Install and use docker under CentOS 6.8
CentOS7 install and use SQL Server
Configure python3 environment on centos7 and
How to install MongoDB on CentOS 7
Install Python3 and Py under CentOS7
Linux CentOS6 compile and install Pyt
Nginx-ubuntu install Nginx and configure https
virtualBox install centos, and build tomcat
How to install MongoDB on CentOS 8