Linux installation Mongodb__linux

Source: Internet
Author: User
Tags create mongodb install mongodb mongodb usleep

Environment: Viretualbox Redhat7.0 mongoDb3.6

Steps:

1. Install Virtual machine: Please check the Linux installation Reahat Basic is the next step

2. Install MongoDB

Need tool Xshell If you don't please contact me to send you

MongoDB's tar package download address: Https://www.mongodb.com/download-center#atlas

To copy an installation package to a virtual machine using the Xshell tool

Unpack the installation package TAR-ZXVF Xxxxxxxxxx.tar

Move to installation directory MV Mongodb-linux-x86_64-xxx/usr/local/mongodb

Add environment variable echo "Export path=\ $PATH:/usr/local/mongodb/bin" After decompression moved past there will be a directory, so need to configure "" >/etc/profile.d/mongodb.sh (This inside to Watch out. )

Make environment variables effective source/etc/profile.d/mongodb.sh

Create MongoDB users and Groups Useradd-r-m-s/sbin/nologin Mongod

Create a startup database and start log mkdir-p/data/mongodb/{db,log}/"Why is this please view the users and groups configured in the script"

Modify Permissions Chown-r mongod:mongod/data/mongodb/

Configure MongoDB Profile: vi/etc/mongod.conf

# mongod.conf

# for documentation of the all options, and:
#   http://docs.mongodb.org/manual/reference/ configuration-options/

# Where to write logging data.
Systemlog:
  destination:file
  logappend:true
  path:/data/mongodb/log/mongod.log

# Where and how to Store data.
Storage:
  dbpath:/data/mongodb/db
  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

# Network Interfaces
NET:
  port:27017
  bindip:127.0.0.1  # Listen to local interface only, comment to Listen on all interfaces.
   #security:

#operationProfiling:

#replication:

#sharding:

# # Enterprise-only Options

#auditLog:

#snmp:

Note:


If the MongoDB port is not between 27017-27019 and 28017-28019, you need to perform the following steps:


# yum-y Install Policycoreutils-python


# semanage Port-a-T mongod_port_t-p TCP <port_number> 27017



Create MongoDB from boot script Vi/etc/init.d/mongod

#!/bin/bash # Mongod-startup script for Mongod # chkconfig:35 # Description:mongo is a scalable, Document-orie
nted database. # processname:mongod # config:/etc/mongod.conf # pidfile:/var/run/mongodb/mongod.pid. /etc/rc.d/init.d/functions # Things from mongod.conf to there by Mongod reading it # note:if your change any OPTIONS h
Ere, you'll get what your pay for: # This script assumes all options are in the config file. Configfile= "/etc/mongod.conf" options= "-F $CONFIGFILE" sysconfig= "/etc/sysconfig/mongod" pidfilepath= ' awk-f ' [: =] '- V ignorecase=1 '/^[[:blank:]]* (processmanagement\.)? Pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $} ' "$CONFIGFILE" | Tr-d "[: blank:]\"] | cut-d "#" F 1 ' Mongod=${mongod-/usr/local/mongodb/bin/mongod} mongo_user=mongod Mongo_group=mongod if [-F "$SYSCONFI G "]; Then. "$SYSCONFIG" fi piddir= ' dirname $PIDFILEPATH ' # Handle NUMA access to CPUs (SERVER-3574) # This verifies the existence O F Numactl 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 Start () {# make Sure the default Pidfile directory exists if [!-D $PIDDIR]; Then install-d-M 0755-o $MONGO _user-g $MONGO _group $PIDDIR fi # recommended ulimit values for Mongod or MONGO S # http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings # ulimit-f Unlimited ulimit-t Unli mited Ulimit-v Unlimited ulimit-n 64000 ulimit-m Unlimited ulimit-u 64000 echo-n $ "Starting Mongod:" Da
  Emon--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_KILLP
  Roc "$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 pro
Cess 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 $del
Ay seconds if process does not respond fast enough to # the initial TERM. Mongo_killproc () {local pid_file=$1 local procname=$2 local-i delay=300 local-i duration=10 local pid= ' PIDOFP  Roc-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 c
  Heckpid $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 when the 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 $mongod retval=$?
  ;; *) echo "Usage: $ {Start|stop|status|restart|reload|force-reload|condrestart}" retval=1 Esac exit $RETVAL


Set up the MongoDB service to boot from

chmod +x/etc/init.d/mongod chkconfig mongod on Start MongoDB Services service Mongod start


If startup is unsuccessful:

The primary view is whether the configured environment variable in the startup script. sh file is correct, and whether the permissions for DB log are the users and groups configured in the script, and can be executed, I give the 777




Verify Startup success:

Service Mongod Status

Mongod.service-sysv:mongo is a scalable, document-oriented database.
   Loaded:loaded (/etc/rc.d/init.d/mongod)
   active:active (running) since Fri-2017-12-15 EST; 31min ago
  Pr ocess:7648 Execstop=/etc/rc.d/init.d/mongod Stop (code=exited, status=0/success)
  process:7677 ExecStart=/etc/ Rc.d/init.d/mongod Start (code=exited, status=0/success)
 Main pid:7688 (mongod)
   Cgroup:/system.slice/ Mongod.service
           └─7688/usr/local/mongodb/mongodb-linux-x86_64-3.6.0/bin/mongod-f/etc/mongod.conf

Dec 15 23:34:49 Localhost.localdomain systemd[1]: Starting Sysv:mongo is a scalable, document-oriented database ....
Dec 23:34:49 localhost.localdomain runuser[7684]: Pam_unix (runuser:session): Session opened to User Mongod by (uid=0) C9/>dec 23:34:50 Localhost.localdomain mongod[7677]: Starting mongod: [  OK  ]
Dec 23:34:50 localhost . Localdomain Systemd[1]: Started Sysv:mongo is a scalable, document-oriented database.

MongoDB Editor:

Enter MONGO:

> Db.foo.find ();
{"_id": ObjectId ("5a34a3de8420293d5f46b0ee"), "name": "Xiaonanhai", "Age": ""}
> Show DBS;
Admin   0.000GB
config  0.000GB
local   0.000GB
test    0.000GB
> 



Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.