ITPub博客

首页 > 数据库 > NoSQL > mongodbe3.2.8 yum install&uninstall

mongodbe3.2.8 yum install&uninstall

原创 NoSQL 作者:ilsyx 时间:2016-08-10 10:43:01 0 删除 编辑

1  描述

mongodb entriprise3.2手册中支持RHEL7系统, 因此选择最小化安装OEL7U2 x64位操作系统,根据mongodb手册,使用yum命令安装与卸载mongodb enterprise。 (本文mongodb enterprise版本为3.2.8)

利用yum安装的mongodb实际是按照redhat的管理系统的风格将mongodb的相关文件放在了操作系统的各个对应目录下。可通过rpm -qpl 命令查看软件包的安装位置。本质mongodb的命令集与tarball打包的一样。 只不过将mongodb命令分组归类到几个rpm包里。

使用操作系统service管理方式启动mongodb实际是调用的mongod, 关闭mongodb是利用的kill命令。

2  过程设计

最小化安装操作系统

配置网络

禁用selinux

配置yum安装源

创建mongod用户

使用yum命令安装mongodb enterprise

使用yum命令卸载mongodb enterprise

 

3  详细步骤操作

3.1 最小化安装操作系统(略)

3.2 配置网络(略)

3.3 禁用selinux(略)

3.4 配置yum安装源

3.4.1   Mongodb官网文档提供的yum源

[root@localhost ~]# cat /etc/yum.repos.d/mongodb-enterprise.repo

[mongodb-enterprise]

name=MongoDB Enterprise Repository

baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/stable/$basearch/

gpgcheck=1

enabled=1

gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

3.4.2   以本地操作系统iso作为yum源

[root@localhost ~]# cat /etc/yum.repos.d/public-yum-ol7.repo

[rhel_7_iso]

name=local iso

baseurl=file:///mnt/cdrom/

gpgcheck=1

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-oracle

 

3.5 创建mongod用户

[root@localhost ~]# useradd mongod

[root@localhost ~]# passwd mongod

Changing password for user mongodb.

New password:

BAD PASSWORD: The password contains the user name in some form

Retype new password:

passwd: all authentication tokens updated successfully.

[root@localhost ~]#

3.6 使用yum命令安装mongodb enterprise

[mongod@localhost ~]$ sudo yum install -y mongodb-enterprise

 

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

 

    #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.

 

[sudo] password for mongod:

Loaded plugins: ulninfo

mongodb-enterprise                                                                                                  | 2.5 kB  00:00:00    

rhel_7_iso                                                                                                          | 3.6 kB  00:00:00    

mongodb-enterprise/7Server/x86_64/primary_db                                                                        |  47 kB  00:00:00    

Resolving Dependencies

--> Running transaction check

---> Package mongodb-enterprise.x86_64 0:3.2.8-1.el7 will be installed

--> Processing Dependency: mongodb-enterprise-tools = 3.2.8 for package: mongodb-enterprise-3.2.8-1.el7.x86_64

--> Processing Dependency: mongodb-enterprise-shell = 3.2.8 for package: mongodb-enterprise-3.2.8-1.el7.x86_64

--> Processing Dependency: mongodb-enterprise-server = 3.2.8 for package: mongodb-enterprise-3.2.8-1.el7.x86_64

--> Processing Dependency: mongodb-enterprise-mongos = 3.2.8 for package: mongodb-enterprise-3.2.8-1.el7.x86_64

--> Running transaction check

---> Package mongodb-enterprise-mongos.x86_64 0:3.2.8-1.el7 will be installed

---> Package mongodb-enterprise-server.x86_64 0:3.2.8-1.el7 will be installed

--> Processing Dependency: net-snmp for package: mongodb-enterprise-server-3.2.8-1.el7.x86_64

--> Processing Dependency: cyrus-sasl-plain for package: mongodb-enterprise-server-3.2.8-1.el7.x86_64

--> Processing Dependency: cyrus-sasl-gssapi for package: mongodb-enterprise-server-3.2.8-1.el7.x86_64

--> Processing Dependency: cyrus-sasl for package: mongodb-enterprise-server-3.2.8-1.el7.x86_64

--> Processing Dependency: libsensors.so.4()(64bit) for package: mongodb-enterprise-server-3.2.8-1.el7.x86_64

--> Processing Dependency: libnetsnmpmibs.so.31()(64bit) for package: mongodb-enterprise-server-3.2.8-1.el7.x86_64

--> Processing Dependency: libnetsnmpagent.so.31()(64bit) for package: mongodb-enterprise-server-3.2.8-1.el7.x86_64

--> Processing Dependency: libnetsnmp.so.31()(64bit) for package: mongodb-enterprise-server-3.2.8-1.el7.x86_64

---> Package mongodb-enterprise-shell.x86_64 0:3.2.8-1.el7 will be installed

---> Package mongodb-enterprise-tools.x86_64 0:3.2.8-1.el7 will be installed

--> Running transaction check

---> Package cyrus-sasl.x86_64 0:2.1.26-19.2.el7 will be installed

---> Package cyrus-sasl-gssapi.x86_64 0:2.1.26-19.2.el7 will be installed

---> Package cyrus-sasl-plain.x86_64 0:2.1.26-19.2.el7 will be installed

---> Package lm_sensors-libs.x86_64 0:3.3.4-11.el7 will be installed

---> Package net-snmp.x86_64 1:5.7.2-24.el7 will be installed

---> Package net-snmp-agent-libs.x86_64 1:5.7.2-24.el7 will be installed

---> Package net-snmp-libs.x86_64 1:5.7.2-24.el7 will be installed

--> Finished Dependency Resolution

 

Dependencies Resolved

 

===========================================================================================================================================

 Package                                   Arch                   Version                         Repository                          Size

===========================================================================================================================================

Installing:

 mongodb-enterprise                        x86_64                 3.2.8-1.el7                     mongodb-enterprise                 5.8 k

Installing for dependencies:

 cyrus-sasl                                x86_64                 2.1.26-19.2.el7                 rhel_7_iso                          87 k

 cyrus-sasl-gssapi                         x86_64                 2.1.26-19.2.el7                 rhel_7_iso                          40 k

 cyrus-sasl-plain                          x86_64                 2.1.26-19.2.el7                 rhel_7_iso                          38 k

 lm_sensors-libs                           x86_64                 3.3.4-11.el7                    rhel_7_iso                          40 k

 mongodb-enterprise-mongos                 x86_64                 3.2.8-1.el7                     mongodb-enterprise                 5.7 M

 mongodb-enterprise-server                 x86_64                 3.2.8-1.el7                     mongodb-enterprise                  13 M

 mongodb-enterprise-shell                  x86_64                 3.2.8-1.el7                     mongodb-enterprise                 7.3 M

 mongodb-enterprise-tools                  x86_64                 3.2.8-1.el7                     mongodb-enterprise                  45 M

 net-snmp                                  x86_64                 1:5.7.2-24.el7                  rhel_7_iso                         320 k

 net-snmp-agent-libs                       x86_64                 1:5.7.2-24.el7                  rhel_7_iso                         702 k

 net-snmp-libs                             x86_64                 1:5.7.2-24.el7                  rhel_7_iso                         746 k

 

Transaction Summary

===========================================================================================================================================

Install  1 Package (+11 Dependent packages)

 

Total download size: 73 M

Installed size: 236 M

Downloading packages:

warning: /mnt/cdrom/Packages/cyrus-sasl-2.1.26-19.2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY

Public key for cyrus-sasl-2.1.26-19.2.el7.x86_64.rpm is not installed

warning: /var/cache/yum/x86_64/7Server/mongodb-enterprise/packages/mongodb-enterprise-3.2.8-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID ea312927: NOKEY

Public key for mongodb-enterprise-3.2.8-1.el7.x86_64.rpm is not installed

(1/5): mongodb-enterprise-3.2.8-1.el7.x86_64.rpm                                                                    | 5.8 kB  00:00:00    

(2/5): mongodb-enterprise-mongos-3.2.8-1.el7.x86_64.rpm                                                             | 5.7 MB  00:00:10    

(3/5): mongodb-enterprise-server-3.2.8-1.el7.x86_64.rpm                                                             |  13 MB  00:00:25    

(4/5): mongodb-enterprise-shell-3.2.8-1.el7.x86_64.rpm                                                              | 7.3 MB  00:00:28     

(5/5): mongodb-enterprise-tools-3.2.8-1.el7.x86_64.rpm                                                              |  45 MB  00:00:50    

-------------------------------------------------------------------------------------------------------------------------------------------

Total                                                                                                      957 kB/s |  73 MB  00:01:17    

Retrieving key from file:///mnt/cdrom/RPM-GPG-KEY-oracle

Importing GPG key 0xEC551F03:

 Userid     : "Oracle OSS group (Open Source Software group) <build@oss.oracle.com>"

 Fingerprint: 4214 4123 fecf c55b 9086 313d 72f9 7b74 ec55 1f03

 From       : /mnt/cdrom/RPM-GPG-KEY-oracle

Retrieving key from https://www.mongodb.org/static/pgp/server-3.2.asc

Importing GPG key 0xEA312927:

 Userid     : "MongoDB 3.2 Release Signing Key <packaging@mongodb.com>"

 Fingerprint: 42f3 e95a 2c4f 0827 9c49 60ad d68f a50f ea31 2927

 From       : https://www.mongodb.org/static/pgp/server-3.2.asc

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : cyrus-sasl-2.1.26-19.2.el7.x86_64                                                                                      1/12

  Installing : 1:net-snmp-libs-5.7.2-24.el7.x86_64                                                                                    2/12

  Installing : lm_sensors-libs-3.3.4-11.el7.x86_64                                                                                    3/12

  Installing : cyrus-sasl-gssapi-2.1.26-19.2.el7.x86_64                                                                               4/12

  Installing : cyrus-sasl-plain-2.1.26-19.2.el7.x86_64                                                                                5/12

  Installing : 1:net-snmp-agent-libs-5.7.2-24.el7.x86_64                                                                              6/12

  Installing : 1:net-snmp-5.7.2-24.el7.x86_64                                                                                         7/12

  Installing : mongodb-enterprise-server-3.2.8-1.el7.x86_64                                                                           8/12

  Installing : mongodb-enterprise-shell-3.2.8-1.el7.x86_64                                                                            9/12

  Installing : mongodb-enterprise-tools-3.2.8-1.el7.x86_64                                                                           10/12

  Installing : mongodb-enterprise-mongos-3.2.8-1.el7.x86_64                                                                          11/12

  Installing : mongodb-enterprise-3.2.8-1.el7.x86_64                                                                                 12/12

  Verifying  : cyrus-sasl-plain-2.1.26-19.2.el7.x86_64                                                                                1/12

  Verifying  : mongodb-enterprise-shell-3.2.8-1.el7.x86_64                                                                            2/12

  Verifying  : cyrus-sasl-gssapi-2.1.26-19.2.el7.x86_64                                                                               3/12

  Verifying  : 1:net-snmp-5.7.2-24.el7.x86_64                                                                                         4/12

  Verifying  : lm_sensors-libs-3.3.4-11.el7.x86_64                                                                                    5/12

  Verifying  : 1:net-snmp-libs-5.7.2-24.el7.x86_64                                                                                    6/12

  Verifying  : cyrus-sasl-2.1.26-19.2.el7.x86_64                                                                                      7/12

  Verifying  : 1:net-snmp-agent-libs-5.7.2-24.el7.x86_64                                                                              8/12

  Verifying  : mongodb-enterprise-mongos-3.2.8-1.el7.x86_64                                                                           9/12

  Verifying  : mongodb-enterprise-3.2.8-1.el7.x86_64                                                                                 10/12

  Verifying  : mongodb-enterprise-server-3.2.8-1.el7.x86_64                                                                          11/12

  Verifying  : mongodb-enterprise-tools-3.2.8-1.el7.x86_64                                                                           12/12

 

Installed:

  mongodb-enterprise.x86_64 0:3.2.8-1.el7                                                                                                  

 

Dependency Installed:

  cyrus-sasl.x86_64 0:2.1.26-19.2.el7                                  cyrus-sasl-gssapi.x86_64 0:2.1.26-19.2.el7                         

  cyrus-sasl-plain.x86_64 0:2.1.26-19.2.el7                            lm_sensors-libs.x86_64 0:3.3.4-11.el7                              

  mongodb-enterprise-mongos.x86_64 0:3.2.8-1.el7                       mongodb-enterprise-server.x86_64 0:3.2.8-1.el7                     

  mongodb-enterprise-shell.x86_64 0:3.2.8-1.el7                        mongodb-enterprise-tools.x86_64 0:3.2.8-1.el7                      

  net-snmp.x86_64 1:5.7.2-24.el7                                       net-snmp-agent-libs.x86_64 1:5.7.2-24.el7                          

  net-snmp-libs.x86_64 1:5.7.2-24.el7                                 

 

Complete!

[mongod@localhost ~]$

3.7 使用yum命令卸载mongodb enterprise

要完全删除mongodb ,需要删除mongodb 应用软件包,配置文件,数据文件和日志文件。如下:

3.7.1   停止数据库

[mongod@localhost ~]$ sudo service mongod stop

[sudo] password for mongod:

Stopping mongod (via systemctl):                           [  OK  ]

[mongod@localhost ~]$

3.7.2   删除应用软件包

[mongod@localhost ~]$ sudo yum erase $(rpm -qa | grep mongodb-enterprise)

Loaded plugins: ulninfo

Resolving Dependencies

--> Running transaction check

---> Package mongodb-enterprise.x86_64 0:3.2.8-1.el7 will be erased

---> Package mongodb-enterprise-mongos.x86_64 0:3.2.8-1.el7 will be erased

---> Package mongodb-enterprise-server.x86_64 0:3.2.8-1.el7 will be erased

---> Package mongodb-enterprise-shell.x86_64 0:3.2.8-1.el7 will be erased

---> Package mongodb-enterprise-tools.x86_64 0:3.2.8-1.el7 will be erased

--> Finished Dependency Resolution

 

Dependencies Resolved

 

======================================================================================================================================================================

 Package                                          Arch                          Version                              Repository                                  Size

======================================================================================================================================================================

Removing:

 mongodb-enterprise                               x86_64                        3.2.8-1.el7                          @mongodb-enterprise                        0.0 

 mongodb-enterprise-mongos                        x86_64                        3.2.8-1.el7                          @mongodb-enterprise                         17 M

 mongodb-enterprise-server                        x86_64                        3.2.8-1.el7                          @mongodb-enterprise                         36 M

 mongodb-enterprise-shell                         x86_64                        3.2.8-1.el7                          @mongodb-enterprise                         22 M

 mongodb-enterprise-tools                         x86_64                        3.2.8-1.el7                          @mongodb-enterprise                        156 M

 

Transaction Summary

======================================================================================================================================================================

Remove  5 Packages

 

Installed size: 230 M

Is this ok [y/N]: y

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Erasing    : mongodb-enterprise-3.2.8-1.el7.x86_64                                                                                                              1/5

  Erasing    : mongodb-enterprise-server-3.2.8-1.el7.x86_64                                                                                                       2/5

warning: /var/log/mongodb/mongod.log saved as /var/log/mongodb/mongod.log.rpmsave

warning: /etc/mongod.conf saved as /etc/mongod.conf.rpmsave

  Erasing    : mongodb-enterprise-shell-3.2.8-1.el7.x86_64                                                                                                        3/5

  Erasing    : mongodb-enterprise-mongos-3.2.8-1.el7.x86_64                                                                                                       4/5

  Erasing    : mongodb-enterprise-tools-3.2.8-1.el7.x86_64                                                                                                        5/5

  Verifying  : mongodb-enterprise-server-3.2.8-1.el7.x86_64                                                                                                       1/5

  Verifying  : mongodb-enterprise-mongos-3.2.8-1.el7.x86_64                                                                                                       2/5

  Verifying  : mongodb-enterprise-tools-3.2.8-1.el7.x86_64                                                                                                        3/5

  Verifying  : mongodb-enterprise-shell-3.2.8-1.el7.x86_64                                                                                                        4/5

  Verifying  : mongodb-enterprise-3.2.8-1.el7.x86_64                                                                                                              5/5

 

Removed:

  mongodb-enterprise.x86_64 0:3.2.8-1.el7               mongodb-enterprise-mongos.x86_64 0:3.2.8-1.el7         mongodb-enterprise-server.x86_64 0:3.2.8-1.el7       

  mongodb-enterprise-shell.x86_64 0:3.2.8-1.el7         mongodb-enterprise-tools.x86_64 0:3.2.8-1.el7        

 

Complete!

[mongod@localhost ~]$

3.7.3   删除数据文件和日志文件

[mongod@localhost ~]$ sudo rm -r /var/log/mongodb

[mongod@localhost ~]$ sudo rm -r /var/lib/mongo

4  相关文件

4.1.1   mongodb相关文件

默认安装情况下 mongodb instance 数据文件目录为/var/lib/mongo , 日志文件目录为/var/log/mongodb . mongodb instance 操作系统进程由mongod 用户运行。如果想改变 数据文件目录和日志文件目录,可以修改/etc/mongod.conf中的 systemLog.path和storage.dbPath参数。

默认/var/lib/mongo与/var/log/mongodb目录属组为mongod,如果改变mongodb instance运行用户,记得数据文件目录与日志文件目录属组一并修改。

[mongod@localhost ~]$ ls -l /var/lib/|grep mongo

drwxr-xr-x  4 mongod  mongod  4096 Aug  8 17:17 mongo

[mongod@localhost ~]$ ls -l /var/log/|grep mongo

drwxr-xr-x  2 mongod mongod     23 Aug  8 16:56 mongodb

Mongodb默认配置文件内容

[root@localhost ~]# cat /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: /var/log/mongodb/mongod.log

 

# Where and how to store data.

storage:

  dbPath: /var/lib/mongo

  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:

[root@localhost ~]#

4.1.2   操作系统相关文件

查看操作系统服务调用/etc/init.d/mongod文件时,会发现本质使用的mongod命令来启动,关闭mongodb利用操作系统kill进程。

[root@localhost init.d]# cat /etc/init.d/mongod

#!/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 change any OPTIONS here, you get what you pay for:

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

CONFIGFILE="/etc/mongod.conf"

OPTIONS=" -f $CONFIGFILE"

 

mongod=${MONGOD-/usr/bin/mongod}

 

MONGO_USER=mongod

MONGO_GROUP=mongod

 

# All variables set before this point can be 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 $2}' "$CONFIGFILE" | tr -d "[:blank:]\"'

" | awk -F'#' '{print $1}'`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

 

  # Recommended ulimit values for mongod or mongos

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

  #

  ulimit -f unlimited

  ulimit -t unlimited

  ulimit -v unlimited

  ulimit -n 64000

  ulimit -m unlimited

  ulimit -u 64000

 

  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 300 seconds for process to go away.

# If process is still alive after 300 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 when process is dead.

  return $RC

}

 

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@localhost init.d]#

5  基本使用命令

5.1.1   配置数据库参数文件

Mongodb默认配置文件内容

[root@localhost ~]# cat /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: /var/log/mongodb/mongod.log

 

# Where and how to store data.

storage:

  dbPath: /var/lib/mongo

  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:

[root@localhost ~]#

 

5.1.2   基本启动停止数据库

[mongod@localhost ~]$ sudo service mongod start

[sudo] password for mongod:

Starting mongod (via systemctl):                           [  OK  ]

[mongod@localhost ~]$ sudo 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 Mon 2016-08-08 17:15:34 EDT; 3 days ago

     Docs: man:systemd-sysv-generator(8)

  Process: 1627 ExecStop=/etc/rc.d/init.d/mongod stop (code=exited, status=0/SUCCESS)

  Process: 1666 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=0/SUCCESS)

 Main PID: 1677 (mongod)

   CGroup: /system.slice/mongod.service

           └─1677 /usr/bin/mongod -f /etc/mongod.conf

 

Aug 08 17:15:33 localhost.localdomain systemd[1]: Starting SYSV: Mongo is a scalable, ....

Aug 08 17:15:33 localhost.localdomain runuser[1673]: pam_unix(runuser:session): sessio...)

Aug 08 17:15:34 localhost.localdomain mongod[1666]: Starting mongod: [  OK  ]

Aug 08 17:15:34 localhost.localdomain systemd[1]: Started SYSV: Mongo is a scalable, d....

Aug 11 19:13:34 localhost.localdomain systemd[1]: Started SYSV: Mongo is a scalable, d....

Hint: Some lines were ellipsized, use -l to show in full.

[mongod@localhost ~]$ sudo service mongod stop

Stopping mongod (via systemctl):                           [  OK  ]

[mongod@localhost ~]$ sudo service mongod status

● mongod.service - SYSV: Mongo is a scalable, document-oriented database.

   Loaded: loaded (/etc/rc.d/init.d/mongod)

   Active: inactive (dead) since Thu 2016-08-11 19:14:07 EDT; 4s ago

     Docs: man:systemd-sysv-generator(8)

  Process: 10534 ExecStop=/etc/rc.d/init.d/mongod stop (code=exited, status=0/SUCCESS)

  Process: 1666 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=0/SUCCESS)

 Main PID: 1677 (code=exited, status=0/SUCCESS)

 

Aug 08 17:15:33 localhost.localdomain systemd[1]: Starting SYSV: Mongo is a scalable, ....

Aug 08 17:15:33 localhost.localdomain runuser[1673]: pam_unix(runuser:session): sessio...)

Aug 08 17:15:34 localhost.localdomain mongod[1666]: Starting mongod: [  OK  ]

Aug 08 17:15:34 localhost.localdomain systemd[1]: Started SYSV: Mongo is a scalable, d....

Aug 11 19:13:34 localhost.localdomain systemd[1]: Started SYSV: Mongo is a scalable, d....

Aug 11 19:13:56 localhost.localdomain systemd[1]: Stopping SYSV: Mongo is a scalable, ....

Aug 11 19:14:07 localhost.localdomain mongod[10534]: Stopping mongod: [  OK  ]

Aug 11 19:14:07 localhost.localdomain systemd[1]: Stopped SYSV: Mongo is a scalable, d....

Hint: Some lines were ellipsized, use -l to show in full.

5.1.3   本地mongo shell连接数据库

在数据库启动后,使用mongo shell连接数据(mongo shell默认连接本地的test数据库)

[mongod@localhost ~]$ mongo

MongoDB shell version: 3.2.8

connecting to: test

Server has startup warnings:

2016-08-11T21:02:32.308-0400 I CONTROL  [initandlisten]

2016-08-11T21:02:32.308-0400 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 64000 files. Number of pr

ocesses should be at least 32000 : 0.5 times number of files.MongoDB Enterprise > show dbs

local  0.000GB

MongoDB Enterprise > exit

bye

[mongod@localhost ~]$

5.1.4   网络连接数据库

MongoDB连接远程服务器的命令格式如下:

mongo 远程主机ip或DNS:MongoDB端口号/数据库名 -u user -p password

 

由于本文数据库参数mongodb.conf为初始配置,初始只允许本机访问,需修改bind_id 值为0.0.0.0 , 重启mongodb , 关闭系统防火墙或添加 允许访问端口。

 

[root@localhost ~]# systemctl disable firewalld

Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@localhost ~]# systemctl stop firewalld

或开放系统27017端口

[root@localhost ~]# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT

 

远程连接测试

远程机器使用mongo shell连接数据库(远程机器为windows机器,使用mongo shell 访问mongodb 172.16.196.149 )

C:\Program Files\MongoDB\Server\3.2\bin>mongo.exe 172.16.196.149

2016-08-19T15:07:31.587+0800 I CONTROL  [main] Hotfix KB2731284 or later update

is not installed, will zero-out data files

MongoDB shell version: 3.2.9

connecting to: 172.16.196.149/test

Server has startup warnings:

2016-08-11T21:02:32.308-0400 I CONTROL  [initandlisten]

2016-08-11T21:02:32.308-0400 I CONTROL  [initandlisten] ** WARNING: soft rlimits

 too low. rlimits set to 4096 processes, 64000 files. Number of processes should

 be at least 32000 : 0.5 times number of files.

MongoDB Enterprise >

 

连接mongodb test 数据库成功。

6  资料参考引用

https://docs.mongodb.com/manual/installation/

 

Supported Platforms

Platform

3.2

3.0

2.6

2.4

2.2

Amazon Linux

?

?

?

?

?

Debian 7

?

?

?

?

?

Fedora 8+

 

 

?

?

?

RHEL/CentOS 6.2+

?

?

?

?

?

RHEL/CentOS 7.0+

?

?

?

 

 

SLES 11

?

?

?

?

?

SLES 12

?

 

 

 

 

Solaris 64-bit

?

?

?

?

?

Ubuntu 12.04

?

?

?

?

?

Ubuntu 14.04

?

?

?

 

 

Ubuntu 16.04

?

 

 

 

 

Microsoft Azure

?

?

?

?

?

Windows Vista/Server 2008R2/2012+

?

?

?

?

?

OSX 10.7+

?

?

?

?

 

 

https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-red-hat/

http://www.jb51.net/article/52508.htm

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/11780477/viewspace-2123256/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-06-12

  • 博文量
    203
  • 访问量
    662442