Installation of mongodb service in yum under Mongodb - Centos7

Keywords: MongoDB yum SELinux SSL

Installation of mongodb service in yum under Mongodb - Centos7

 Full stack operation and maintenance Concern

2016.06.13 18:33* Words 188 Reading 7326 Comments 1 Like 8

mongodb.png

Installation of MongoDB services under centos7 can be done either by YUM or by binary decompression. Here, YUM is used.

Inspection before installation

  • Check how many hosts the system has in order to add the corresponding yum source
  • Ensure that SELINUX is disable d
## Inspection system
root@pts/1 $ uname -a
Linux milian-mysql-slave 3.10.0-229.4.2.el7.x86_64 #1 SMP Wed May 13 10:06:09 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

## Prohibit selinux
root@pts/1 $ cat /etc/selinux/config |grep -v '#' |grep -i selinux
SELINUX=disabled
SELINUXTYPE=targeted 

## If not, you need to modify the configuration and restart it
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config 

Add Yum source

According to the information provided by the mongodb website, add yum source as follows

cat /etc/yum.repos.d/mongodb-3.2.repos
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

*** Here you can modify gpgcheck=0 to omit gpg validation***

Install mongodb

Update packages before installation (optional operation)

yum update

*** Installation***

yum -y install mongodb-org mongodb-org-server

Configure, start and use mongodb

Centos7 began to adopt system D to manage services

*** Configuration***

fork=true   ## Allow programs to run in the background
#auth=true  ## Start certification
logpath=/data/db/mongodb/logs/mongodb.log   
logappend=true      # Logging mode: set true to append. The default is override
dbpath=/data/db/mongodb/data/    ## Data Storage Catalogue
pidfilepath=/data/db/mongodb/logs/mongodb.pid    # Process ID, if not specified, there will be no PID file at startup. Default default.
port=27017
#bind_ip=192.168.2.73   # Bind addresses. By default, 127.0.0.1 can only be connected locally.
# Set to true, modify the data directory storage mode, each database file is stored in different folders of the DBPATH specified directory.
# With this option, configurable MongoDB stores data on different disk devices to improve write throughput or disk capacity. The default is false.
# It is recommended to configure secondary options at the outset
directoryperdb=true

# Log prohibition 
# Enabling operation logs for journals to ensure write persistence and data consistency creates journal directories under the dbpath directory
nojournal = true   

## max connections
# Maximum number of connections. Default: Depends on system (i.e., ulimit and file descriptor) constraints.
# MongoDB does not restrict its own connections. When the setting is greater than the system limit, it is invalid, and the system limit shall prevail.
# Set the value above the connection pool and the total number of connections to prevent rush-hour connections.
# Note: This value cannot be set to be greater than 20000.
maxConns=1024

But the actual configuration configures 1024 in the system alarm -- maxConns too high, can only handle 819, temporarily find out what the reason is.

*** Start Mongo ***

## Check whether mongodb allows the system to start
systemctl is-enabled mongodb

## Start the mongodb system
systemctl enable mongodb

## start-up
systemctl start mongodb

## View startup status
systemctl status mongodb 

## Stop it
systemctl stop mongodb

*** Use Mongo ***

root@pts/4 $ mongo --help
MongoDB shell version: 3.0.6
usage: mongo [options] [db address] [file names (ending in .js)]
db address can be:
  foo                   foo database on local machine
  192.169.0.5/foo       foo database on 192.168.0.5 machine
  192.169.0.5:9999/foo  foo database on 192.168.0.5 machine on port 9999
Options:
  --shell                            run the shell after executing files
  --nodb                             don't connect to mongod on startup - no 
                                     'db address' arg expected
  --norc                             will not run the ".mongorc.js" file on 
                                     start up
  --quiet                            be less chatty
  --port arg                         port to connect to
  --host arg                         server to connect to
  --eval arg                         evaluate javascript
  -h [ --help ]                      show this usage information
  --version                          show version information
  --verbose                          increase verbosity
  --ipv6                             enable IPv6 support (disabled by default)
  --ssl                              use SSL for all connections
  --sslCAFile arg                    Certificate Authority file for SSL
  --sslPEMKeyFile arg                PEM certificate/key file for SSL
  --sslPEMKeyPassword arg            password for key in PEM file for SSL
  --sslCRLFile arg                   Certificate Revocation List file for SSL
  --sslAllowInvalidHostnames         allow connections to servers with 
                                     non-matching hostnames
  --sslAllowInvalidCertificates      allow connections to servers with invalid 
                                     certificates
  --sslFIPSMode                      activate FIPS 140-2 mode at startup

Authentication Options:
  -u [ --username ] arg              username for authentication
  -p [ --password ] arg              password for authentication
  --authenticationDatabase arg       user source (defaults to dbname)
  --authenticationMechanism arg      authentication mechanism
  --gssapiServiceName arg (=mongodb) Service name to use when authenticating 
                                     using GSSAPI/Kerberos
  --gssapiHostName arg               Remote host name to use for purpose of 
                                     GSSAPI/Kerberos authentication

file names: a list of files to run. files have to end in .js and will exit after unless --shell is specified

*** Example***

root@pts/2 $ mongo localhost/test
MongoDB shell version: 3.0.6
connecting to: localhost/test
Server has startup warnings: 
2015-09-08T14:29:50.163+0800 I CONTROL  [initandlisten] 
2015-09-08T14:29:50.163+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-09-08T14:29:50.163+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-09-08T14:29:50.163+0800 I CONTROL  [initandlisten] 
2015-09-08T14:29:50.163+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-09-08T14:29:50.163+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-09-08T14:29:50.163+0800 I CONTROL  [initandlisten] 
> show dbs
local             0.078GB
weic              0.203GB
weictest          0.078GB
> use weic
switched to db weic
> show collections
actorAudio
attention
audio
system.indexes
tagInfo
> db.tagInfo.findOne()
{
    "_id" : ObjectId("563c871f8105044098c6c761"),
    "id" : NumberLong(1),
    "name" : "A soft voice"
}
> 

Posted by XTTX on Tue, 05 Feb 2019 21:48:17 -0800