CentOS7 installation configuration mongodb3.2

Posted by Collin on Mon, 20 Jul 2020 18:21:42 +0200

1. Download Dependent Packages

yum -y install wget

2. Create a file directory

mkdir -p /app/install
mkdir–p /app/data/mongodb
mkdir–p /app/log/mongodb

3. Download mongodb

cd /app/install
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.16.tgz
tar zxvf mongodb-linux-x86_64-3.2.16.tgz
mv mongodb-linux-x86_64-3.2.16 ../mongodb

The configuration information is as follows:

dbpath = /app/data/mongodb                              #Data File Storage Directory
logpath = /app/log/mongodb/mongodb.log                  #Log File Storage Directory
port = 27017                                            #port
fork = true                                             #Enabled as a daemon, running in the background
nohttpinterface = true

5. Configure boot-up self-starting mongodb

Create a new mongod file at/etc/init.d:

vim /etc/init.d/mongod

The configuration is as follows:

#!/bin/bash
#
#chkconfig: 2345 80 90
#description: mongodb

start() {
  /app/mongodb/bin/mongod --config /app/mongodb/bin/mongodb.conf
}

stop() {
   /app/mongodb/bin/mongod --config /app/mongodb/bin/mongodb.conf --shutdown
}

case "$1" in
start)
start
  ;;

         stop)
stop
  ;;

restart)
stop
start
  ;;
   *)
echo
 $"Usage: $0 {start|stop|restart}"
exit 1
esac

Add Service and Start Up

chmod +x /etc/init.d/mongod
chkconfig –add mongod
chkconfig –list mongod
service mongod start

6. Add mongodb's bin directory to PATH environment variable, edit/etc/profile file

vim /etc/profile

Add the following information at the end of the file:

export PATH=$PATH:/app/mongodb/bin

Execute the following command to make the changes effective:

source/etc/profile

7. Create mongodb user and set login password:

Logon command:

mongo

>user admin
>db.createUser({user:'admin',pwd:'admin', roles:[{role:'userAdminAnyDatabase', >db:'admin'}]})

View users:

>use admin
>show collections
>db.system.users.find().pretty()

Topics: MongoDB Linux vim yum