MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Passaggi per installare MongoDB su Amazon Linux

In questo tutorial, spiegheremo i passaggi per installare MongoDB su Amazon Linux. Prima di iniziare con il tutorial vediamo quali sono le dipendenze per installare MongoDB su Amazon Linux.

Prerequisiti per installare MongoDB su Amazon Linux EC2

  • Devi avere un'istanza EC2 in esecuzione con Amazon Linux
  • È necessario l'accesso root/sudo a questa istanza EC2.

Questi passaggi seguenti supportano EC2 Amazon Linux:

  • Amazon Linux 2
  • Amazon Linux (2013.03 o successivo)
MongoDB supporta solo le versioni a 64 bit di queste piattaforme per altre piattaforme di supporto, controlla questo link

Vediamo quali sono i passaggi per installare MongoDB su Amazon Linux.

Fase 1:crea un repository YUM per l'installazione di MongoDB

– su Amazon Linux (2013.03 o successivo)

Crea un file di repository yum per MongoDB in cui verrà installato con il comando yum. /etc/yum.repos.d/mongodb-org-4.2.repo.

Repository MongoDB Yum per Amazon Linux (2013.03 o successivo)

[ec2-user@MongoDB-Server ~]$ sudo vi /etc/yum.repos.d/mongodb-org-4.2.repo
#Copy paste below content and save it
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

Repository MongoDB Yum per Amazon Linux 2

[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

Un altro metodo per installare MongoDB è tramite i file .rpm, puoi scaricare direttamente il repository MongoDB dalla pagina di download ufficiale (https://repo.mongodb.org/yum/redhat/).

Fase 2:comando YUM per installare MongoDB per Amazon Linux

Comando:

$ sudo yum install -y mongodb-org

Uscita demo:

[ec2-user@MongoDB-Server ~]$ sudo yum install -y mongodb-org
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main                                                                                                        | 2.1 kB  00:00:00
amzn-updates                                                                                                     | 2.5 kB  00:00:00
mongodb-org-4.2                                                                                                  | 2.5 kB  00:00:00
(1/6): amzn-updates/latest/group_gz                                                                              | 4.4 kB  00:00:00
(2/6): amzn-main/latest/group_gz                                                                                 | 4.4 kB  00:00:00
(3/6): amzn-updates/latest/updateinfo                                                                            | 629 kB  00:00:00
(4/6): mongodb-org-4.2/primary_db                                                                                |  22 kB  00:00:00
(5/6): amzn-main/latest/primary_db                                                                               | 4.0 MB  00:00:00
(6/6): amzn-updates/latest/primary_db                                                                            | 2.9 MB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package mongodb-org.x86_64 0:4.2.3-1.amzn1 will be installed
--> Processing Dependency: mongodb-org-tools = 4.2.3 for package: mongodb-org-4.2.3-1.amzn1.x86_64
--> Processing Dependency: mongodb-org-shell = 4.2.3 for package: mongodb-org-4.2.3-1.amzn1.x86_64
--> Processing Dependency: mongodb-org-server = 4.2.3 for package: mongodb-org-4.2.3-1.amzn1.x86_64
--> Processing Dependency: mongodb-org-mongos = 4.2.3 for package: mongodb-org-4.2.3-1.amzn1.x86_64
--> Running transaction check
---> Package mongodb-org-mongos.x86_64 0:4.2.3-1.amzn1 will be installed
---> Package mongodb-org-server.x86_64 0:4.2.3-1.amzn1 will be installed
---> Package mongodb-org-shell.x86_64 0:4.2.3-1.amzn1 will be installed
---> Package mongodb-org-tools.x86_64 0:4.2.3-1.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================
 Package                              Arch                     Version                          Repository                         Size
========================================================================================================================================
Installing:
 mongodb-org                          x86_64                   4.2.3-1.amzn1                    mongodb-org-4.2                   5.8 k
Installing for dependencies:
 mongodb-org-mongos                   x86_64                   4.2.3-1.amzn1                    mongodb-org-4.2                    14 M
 mongodb-org-server                   x86_64                   4.2.3-1.amzn1                    mongodb-org-4.2                    25 M
 mongodb-org-shell                    x86_64                   4.2.3-1.amzn1                    mongodb-org-4.2                    17 M
 mongodb-org-tools                    x86_64                   4.2.3-1.amzn1                    mongodb-org-4.2                    62 M

Transaction Summary
========================================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 118 M
Installed size: 281 M
Downloading packages:
warning: /var/cache/yum/x86_64/latest/mongodb-org-4.2/packages/mongodb-org-4.2.3-1.amzn1.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 058f8b6b: NOKEY
Public key for mongodb-org-4.2.3-1.amzn1.x86_64.rpm is not installed
(1/5): mongodb-org-4.2.3-1.amzn1.x86_64.rpm                                                                      | 5.8 kB  00:00:00
(2/5): mongodb-org-mongos-4.2.3-1.amzn1.x86_64.rpm                                                               |  14 MB  00:00:00
(3/5): mongodb-org-server-4.2.3-1.amzn1.x86_64.rpm                                                               |  25 MB  00:00:00
(4/5): mongodb-org-tools-4.2.3-1.amzn1.x86_64.rpm                                                                |  62 MB  00:00:01
(5/5): mongodb-org-shell-4.2.3-1.amzn1.x86_64.rpm                                                                |  17 MB  00:00:02
----------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                    34 MB/s | 118 MB  00:00:03
Retrieving key from https://www.mongodb.org/static/pgp/server-4.2.asc
Importing GPG key 0x058F8B6B:
 Userid     : "MongoDB 4.2 Release Signing Key <[email protected]>"
 Fingerprint: e162 f504 a20c df15 827f 718d 4b7c 549a 058f 8b6b
 From       : https://www.mongodb.org/static/pgp/server-4.2.asc
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mongodb-org-server-4.2.3-1.amzn1.x86_64                                                                              1/5
  Installing : mongodb-org-mongos-4.2.3-1.amzn1.x86_64                                                                              2/5
  Installing : mongodb-org-tools-4.2.3-1.amzn1.x86_64                                                                               3/5
  Installing : mongodb-org-shell-4.2.3-1.amzn1.x86_64                                                                               4/5
  Installing : mongodb-org-4.2.3-1.amzn1.x86_64                                                                                     5/5
  Verifying  : mongodb-org-shell-4.2.3-1.amzn1.x86_64                                                                               1/5
  Verifying  : mongodb-org-tools-4.2.3-1.amzn1.x86_64                                                                               2/5
  Verifying  : mongodb-org-mongos-4.2.3-1.amzn1.x86_64                                                                              3/5
  Verifying  : mongodb-org-server-4.2.3-1.amzn1.x86_64                                                                              4/5
  Verifying  : mongodb-org-4.2.3-1.amzn1.x86_64                                                                                     5/5

Installed:
  mongodb-org.x86_64 0:4.2.3-1.amzn1

Dependency Installed:
  mongodb-org-mongos.x86_64 0:4.2.3-1.amzn1    mongodb-org-server.x86_64 0:4.2.3-1.amzn1    mongodb-org-shell.x86_64 0:4.2.3-1.amzn1
  mongodb-org-tools.x86_64 0:4.2.3-1.amzn1

Complete!
[ec2-user@MongoDB-Server ~]$

Puoi anche scaricare MongoDB dal link sottostante:

Pagina di download di MongoDB

Directory predefinite per MongoDB

File di dati in /var/lib/mongo

File di registro in /var/log/mongodb

Passo 3:Impostazioni consigliate per Linux ulimit:

limit fsize unlimited unlimited    # (file size)
limit cpu unlimited unlimited      # (cpu time)
limit as unlimited unlimited       # (virtual memory size)
limit memlock unlimited unlimited  # (locked-in-memory size)
limit nofile 64000 64000           # (open files)
limit nproc 64000 64000            # (processes/threads)

Puoi controllare ulimit impostato sul tuo sistema Linux con il comando seguente.

$ ulimit -a

Come modificare i valori ulimit in Linux

Ogni volta che aggiorni le impostazioni di ulimit, riavvia il servizio, per assicurarti che le modifiche abbiano effetto sul sistema per il servizio MongoDB “sudo service mongod start "

Fase 4:comando per avviare il servizio MongoDB

$ sudo service mongod start

Uscita demo:

[ec2-user@MongoDB-Server ~]$ sudo service mongod start
Starting mongod:                                           [  OK  ]
[ec2-user@MongoDB-Server ~]$

Fase 5:comando per avviare automaticamente il servizio MongoDB all'avvio:

$ sudo chkconfig mongod on

Uscita demo

[ec2-user@MongoDB-Server ~]$ sudo chkconfig | grep mongod 
mongod          0:off   1:off   2:off   3:off   4:off   5:off   6:off
[ec2-user@MongoDB-Server ~]$
[ec2-user@MongoDB-Server ~]$ sudo chkconfig mongod on
[ec2-user@MongoDB-Server ~]$
[ec2-user@MongoDB-Server ~]$ sudo chkconfig | grep mongod
mongod          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[ec2-user@MongoDB-Server ~]$

Comando per iniziare | Fermare | Riavvia il servizio MongoDB

$ sudo service mongod start

$ sudo service mongod stop

$ sudo service mongod restart

Passaggi 6:avvia MongoDB Shell

$ mongo

Questa è la fine del tutorial in cui abbiamo spiegato i passaggi per installare MongoDB su Amazon Linux.