MongoDB 3.6 Department Record

Source: Internet
Author: User
Tags mkdir usleep

[Email protected] ~]# Groupadd Mongod

[Email protected] ~]# useradd-s/sbin/nologin-m-G Mongod Mongod


[Email protected] ~]# tar zxvf mongodb-linux-x86_64-3.6.3.tgz-c/usr/local/

[Email protected] ~]# cd/usr/local

[Email protected] local]# MV mongodb-linux-x86_64-3.6.3 MongoDB


[Email protected] ~]# mkdir-p/usr/local/mongodb/data

[Email protected] ~]# mkdir-p/usr/local/mongodb/logs


[Email protected] ~]# chown-r mongod:mongod/usr/local/mongodb/data/

[Email protected] ~]# chown-r mongod:mongod/usr/local/mongodb/logs/


[Email protected] ~]# mkdir-p/var/run/mongodb

[Email protected] ~]# chown-r Mongod:mongod/var/run/mongodb


[Email protected] ~]# vi/etc/security/limits.conf

Mongod Soft Nofile 64000

Mongod Hard Nofile 64000

Mongod Soft Nproc 32000

Mongod Hard Nproc 32000


[Email protected] ~]# Vi/etc/profile

Path= $PATH:/usr/local/mongodb/bin

[Email protected] ~]# Source/etc/profile


[Email protected] ~]# vi/etc/mongod.conf

# mongod.conf

# for documentation of all options, see:

# http://docs.mongodb.org/manual/reference/configuration-options/

# Where to write logging data.

Systemlog:

Destination:file

Logappend:true

Path:/usr/local/mongodb/logs/mongod.log


# Where and how to store data.

Storage

DbPath:/usr/local/mongodb/data

Journal

Enabled:true

# Engine:

# Mmapv1:

# Wiredtiger:


# How the process runs

Processmanagement:

Fork:true # Fork and run in background

Pidfilepath:/var/run/mongodb/mongod.pid # Location of Pidfile

TimeZoneInfo:/usr/share/zoneinfo


# Network Interfaces

Net

port:27017

bindip:192.168.1.201 # Listen to local interface only, comment to Listen on all interfaces.


#security:


#operationProfiling:


#replication:


#sharding:


# # Enterprise-only Options


#auditLog:


#snmp:


[Email protected] ~]# Vi/etc/init.d/mongodb

#!/bin/bash


# Mongod-startup Script for Mongod


# chkconfig:35 85 15

# Description:mongo is a scalable, document-oriented database.

# Processname:mongod

# config:/etc/mongod.conf


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


# note:if You the change any OPTIONS here and you get the "What do pay for:

# This script assumes all options is in the config file.

Configfile= "/etc/mongod.conf"

Options= "-F $CONFIGFILE"


Mongod=${mongod-/usr/local/mongodb/bin/mongod}


Mongo_user=mongod

Mongo_group=mongod


# All variables set before the can is overridden by users, by

# setting them directly in the SYSCONFIG file. Use this to explicitly

# Override these values, at your own risk.

Sysconfig= "/etc/sysconfig/mongod"

If [-F "$SYSCONFIG"]; Then

. "$SYSCONFIG"

Fi


# Handle NUMA access to CPUs (SERVER-3574)

# This verifies the existence of NUMACTL as well as testing that the command works

Numactl_args= "--interleave=all"

If which numactl >/dev/null 2>/dev/null && numactl $NUMACTL _args ls/>/dev/null 2>/dev/null

Then

Numactl= "NUMACTL $NUMACTL _args"

Else

Numactl= ""

Fi


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

Pidfilepath= "' awk-f ' [: =] '-v ignorecase=1 '/^[[:blank:]]* (processmanagement\.)? Pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print "$CONFIGFILE \" | tr-d \ "[: blank:]\\" ' \ "| Awk-f ' # ' {print '} ' "

Piddir= ' DirName $PIDFILEPATH '


Start ()

{

# Make sure the default Pidfile directory exists

if [!-D $PIDDIR]; Then

Install-d-M 0755-o $MONGO _user-g $MONGO _group $PIDDIR

Fi


# Make sure the pidfile does not exist

If [-F "$PIDFILEPATH"]; Then

echo "Error starting Mongod. $PIDFILEPATH exists. "

Retval=1

Return

Fi


# Recommended Ulimit values for Mongod or MONGOs

# See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

#

If Test-f/sys/kernel/mm/transparent_hugepage/enabled; Then

echo Never >/sys/kernel/mm/transparent_hugepage/enabled

Fi

If Test-f/sys/kernel/mm/transparent_hugepage/defrag; Then

echo Never >/sys/kernel/mm/transparent_hugepage/defrag

Fi

Ulimit-f Unlimited

Ulimit-t Unlimited

Ulimit-v Unlimited

Ulimit-n 64000

Ulimit-m Unlimited

Ulimit-u 64000

Ulimit-l Unlimited


Echo-n $ "Starting Mongod:"

Daemon--user "$MONGO _user"--check $mongod "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1"

Retval=$?

Echo

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

}


Stop ()

{

Echo-n $ "Stopping Mongod:"

Mongo_killproc "$PIDFILEPATH" $mongod

Retval=$?

Echo

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

}


Restart () {

Stop

Start

}


# Send term signal-to-process and wait up-to-seconds for process to go away.

# IF process is still alive after seconds, send KILL signal.

# built-in Killproc () (found in/etc/init.d/functions) is on certain versions of Linux

# where it sleeps for the full $delay seconds if process does not respond fast enough to

# The initial term signal.

Mongo_killproc ()

{

Local pid_file=$1

Local procname=$2

Local-i delay=300

Local-i duration=10

Local pid= ' Pidofproc-p "${pid_file}" ${procname} '


Kill-term $pid >/dev/null 2>&1

Usleep 100000

Local-i x=0

While [$x-le $delay] && checkpid $pid; Do

Sleep $duration

x=$ (($x + $duration))

Done


Kill-kill $pid >/dev/null 2>&1

Usleep 100000


Checkpid $pid # returns 0 only if the process exists

Local rc=$?

["$RC"-eq 0] && failure "${procname} shutdown" | | Rm-f "${pid_file}"; Success "${procname} shutdown"

rc=$ ((! $RC)) # Invert return code so we return 0 if process is dead.

Return $RC

}


Retval=0


Case "$" in

Start

Start

;;

Stop

Stop

;;

Restart|reload|force-reload)

Restart

;;

Condrestart)

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

;;

Status

Status $mongod

Retval=$?

;;

*)

echo "Usage: $ {Start|stop|status|restart|reload|force-reload|condrestart}"

Retval=1

Esac


Exit $RETVAL


[Email protected] ~]# chmod a+x/etc/init.d/mongod


[[email protected] ~]#/etc/init.d/mongod start

Starting Mongod: [OK]

[Email protected] ~]#/etc/init.d/mongod status

Mongod (PID 1263) is running ...


MongoDB 3.6 Department Record

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: info-contact@alibabacloud.com 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.