Get the App
SLTechnology News&Howtos  ›  Database  › 

How to install a single instance of Mongodb3.0.6

Shulou Source: shulou.com Published: 2022-05-31 15:54:36 10月04日 Update

This article will explain in detail how to install a single instance of Mongodb3.0.6. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

[root@b28-17-51] # mkdir-p / export/data

[root@b28-17-51] # mkdir-p / export/log

[root@b28-17-51 export] # tar-xvf mongodb-linux-x86_64-3.0.6.tgz

[root@b28-17-51 export] # mv mongodb-linux-x86_64-3.0.6 mongodb

[root@b28-17-51 log] # touch mongodb.log

[root@b28-17-51 mongodb] # mkdir etc

[root@b28-17-51 etc] # touch mongodb.pid

[root@b28-17-51 etc] # vi mongod.conf

Logpath=/export/log/mongodb.log

Logappend=true

Fork = true

Dbpath=/export/data/db

Pidfilepath = / export/mongodb/etc/mongodb.pid

Rest = true

Httpinterface = true

Port = 27017

[root@b28-17-51 export] # numactl-- interleave=all / export/mongodb/bin/mongod-- config / export/mongodb/etc/mongod.conf

Set up the Mongodb startup command:

[root@b28-17-51 export] # groupadd mongodb

[root@b28-17-51 export] # useradd-m mongodb-g mongodb

The script is as follows:

[root@yoon ~] # cd / etc/init.d/

[root@yoon init.d] # vi mongod

#! / bin/bash

# mongod-Startup script for mongod

# chkconfig: 35 80 15

# description: Mongo is a scalable, document-oriented database.

# processname: mongod

# config: / export/mongodb/etc/mongod.conf

# pidfile: / export/mongodb/etc/mongodb.pid

Source / etc/rc.d/init.d/functions

# things from mongod.conf get there by mongod reading it

If [$(id-u)! = "0"]; then

Echo "Permission Denied! Please use root to run again!"

Exit 1

Fi

Test-d / export/mongodb | | (mkdir-p / export/mongodb; chown mongod:mongod / export/mongodb)

# NOTE: if you change any OPTIONS here, you get what you pay for:

# this script assumes all options are in the config file.

CONFIGFILE= "/ export/mongodb/etc/mongod.conf"

SYSCONFIG= "/ etc/sysconfig/mongod"

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

DBPATH= `awk-F ='/ ^ dbpath/ {print $2}'"$CONFIGFILE" `

OPTIONS= "--config $CONFIGFILE"

Mongod=$ {MONGOD-/export/mongodb/bin/mongod}

Echo "db path is:" $DBPATH

Echo $mongod

MONGO_USER=mongodb

MONGO_GROUP=mongodb

[- f "$SYSCONFIG"] & & source "$SYSCONFIG"

Super () {

Su-$MONGO_USER-c "PATH=$PATH:/export/mongodb/bin/; $*"

}

Start ()

{

Echo-n $"Starting mongod:"

# echo-n "$MONGO_USER"numactl-- interleave=all"

# daemon-- user "$MONGO_USER"numactl-- interleave=all" $mongod $OPTIONS

# daemon-- user "$MONGO_USER" $mongod $OPTIONS

#

# su-$MONGO_USER-c "$mongod $OPTIONS"-m-p

# su-$MONGO_USER

# $mongod $OPTIONS

Daemon-- user "$MONGO_USER"numactl-- interleave=all" $mongod $OPTIONS

# super $mongod $OPTIONS

Echo $mongod$OPTIONS

RETVAL=$?

Echo

[$RETVAL-eq 0] & & touch / var/lock/subsys/mongod

}

Stop ()

{

Echo-n $"Stopping mongod:"

Killproc-p "$DBPATH" / mongod.lock-d 300 / export/mongodb/bin/mongod

RETVAL=$?

Echo

[$RETVAL-eq 0] & & rm-f / var/lock/subsys/mongod

}

Restart () {

Stop

Start

}

Ulimit-n 12000

RETVAL=0

Case "$1" in

Start)

Start

Stop)

Stop

Restart | reload | force-reload)

Restart

Condrestart)

[- f / var/lock/subsys/mongod] & & restart | |:

Status)

Status $mongod

RETVAL=$?

*)

Echo "Usage: $0 {start | stop | status | restart | reload | force-reload | condrestart}"

RETVAL=1

Esac

Exit $RETVAL

= =

[root@yoon ~] # service mongod start

[root@yoon ~] # service mongod stop

=

Set the boot to start Mongodb automatically

[root@yoon] # chkconfig-- add mongod

[root@yoon ~] # chkconfig mongod on

[root@yoon] # chkconfig mongod-- list

Mongod 0:off 1:off 2:on 3:on 4:on 5:on 6:off

This is the end of this article on "how to install a single instance of Mongodb3.0.6". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Articles examples more good practical content commands articles knowledge scripts references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Huawei Linux MySQL Docker