Dalam tutorial ini, kami akan menjelaskan Langkah-langkah untuk Menginstal MongoDB di Amazon Linux. Sebelum memulai dengan tutorial mari kita lihat ketergantungan apa untuk menginstal MongoDB di Amazon Linux.
Prasyarat untuk Menginstal MongoDB di Amazon Linux EC2
- Anda harus menjalankan instans EC2 dengan Amazon Linux
- Perlu akses root/sudo ke instans EC2 ini.
Langkah-langkah di bawah ini mendukung EC2 Amazon Linux:
- Amazon Linux 2
- Amazon Linux (2013.03 atau lebih baru)
Mari kita lihat apa saja langkah-langkah Instal MongoDB di Amazon Linux .
Langkah 1:Buat repositori YUM untuk menginstal MongoDB
– di Amazon Linux (2013.03 atau lebih baru)
Buat file repositori yum untuk MongoDB yang akan diinstal dengan perintah yum. /etc/yum.repos.d/mongodb-org-4.2.repo file.
Repositori MongoDB Yum untuk Amazon Linux (2013.03 atau lebih baru)
[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
Repositori MongoDB Yum untuk 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
Metode lain untuk menginstal MongoDB adalah melalui file .rpm, Anda dapat langsung mengunduh repositori MongoDB dari halaman unduhan resmi (https://repo.mongodb.org/yum/redhat/).
Langkah 2:Perintah YUM untuk menginstal MongoDB untuk Amazon Linux
Perintah:
$ sudo yum install -y mongodb-org
Keluaran 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 ~]$
Anda juga dapat mengunduh MongoDB dari tautan di bawah ini:
Halaman Unduh MongoDBDirektori default untuk MongoDB
File data di /var/lib/mongo
Log file di /var/log/mongodb
Langkah 3:Pengaturan ulimit Linux yang Disarankan:
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)
Anda dapat memeriksa set ulimit pada sistem Linux Anda dengan perintah di bawah ini.
$ ulimit -a
Cara mengubah nilai ulimit di Linux
Setiap kali Anda memperbarui pengaturan ulimit restart layanan, untuk memastikan bahwa perubahan berlaku pada sistem untuk layanan MongoDB “sudo service mongod start ”Langkah 4:Perintah untuk memulai layanan MongoDB
$ sudo service mongod start
Keluaran Demo:
[ec2-user@MongoDB-Server ~]$ sudo service mongod start Starting mongod: [ OK ] [ec2-user@MongoDB-Server ~]$
Langkah 5:Perintah untuk memulai layanan MongoDB secara otomatis saat boot:
$ sudo chkconfig mongod on
Keluaran 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 ~]$
Perintah untuk Memulai | Berhenti | Mulai ulang layanan MongoDB
$ sudo service mongod start $ sudo service mongod stop $ sudo service mongod restart
Langkah 6:Mulai MongoDB Shell
$ mongo
Ini adalah akhir dari tutorial kami menjelaskan langkah-langkah untuk Menginstal MongoDB di Amazon Linux.