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

Trin til at installere MongoDB på Amazon Linux

I denne tutorial vil vi forklare trin til installation af MongoDB på Amazon Linux. Før du starter med selvstudiet, lad os se, hvad afhængigheden er for at installere MongoDB på Amazon Linux.

Forudsætninger for at installere MongoDB på Amazon Linux EC2

  • Du skal have en EC2-instans, der kører med Amazon Linux
  • Har brug for root/sudo-adgang til denne EC2-instans.

Disse nedenstående trin understøtter EC2 Amazon Linux:

  • Amazon Linux 2
  • Amazon Linux (2013.03 eller nyere)
MongoDB understøtter kun 64-bit versionerne af disse platforme til andre supportplatforme, tjek dette link

Lad os se, hvad der er trinene til at installere MongoDB på Amazon Linux .

Trin 1:Opret YUM-lager til installation af MongoDB

– på Amazon Linux (2013.03 eller nyere)

Opret en yum-depotfil til MongoDB, som installeres med yum-kommandoen. /etc/yum.repos.d/mongodb-org-4.2.repo fil.

MongoDB Yum Repository til Amazon Linux (2013.03 eller nyere)

[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

MongoDB Yum Repository til 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

En anden metode til at installere MongoDB er via .rpm-filer, du kan downloade MongoDB-depotet direkte fra den officielle downloadside (https://repo.mongodb.org/yum/redhat/).

Trin 2:YUM Command for at installere MongoDB til Amazon Linux

Kommando:

$ sudo yum install -y mongodb-org

Demo-output:

[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 ~]$

Du kan også downloade MongoDB fra nedenstående link:

MongoDB downloadside

Standardbiblioteker for MongoDB

Datafiler i /var/lib/mongo

Logfiler i /var/log/mongodb

Trin 3:Anbefalede Linux ulimit-indstillinger:

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)

Du kan kontrollere ulimit-sættet på dit Linux-system med kommandoen nedenfor.

$ ulimit -a

Sådan ændres ulimit-værdier i Linux

Når du opdaterer ulimit-indstillingerne, genstart tjenesten for at sikre, at ændringerne træder i kraft på systemet til MongoDB-tjenesten "sudo service mongod start

Trin 4:Kommando for at starte MongoDB-tjenesten

$ sudo service mongod start

Demo-output:

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

Trin 5:Kommando til automatisk at starte MongoDB-tjenesten ved opstart:

$ sudo chkconfig mongod on

Demo-output

[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 ~]$

Kommando til start | Stop | Genstart MongoDB-tjenesten

$ sudo service mongod start

$ sudo service mongod stop

$ sudo service mongod restart

Trin 6:Start MongoDB Shell

$ mongo

Dette er slutningen af ​​selvstudiet, vi forklarede trinene til at installere MongoDB på Amazon Linux.


  1. MongoDB $add

  2. Få sidst indsatte dokument-id i MongoDB med Java-driver

  3. Redis pipelinet ordre for udførelse

  4. Introduktion til Apache HBase Snapshots, del 2:Deeper Dive