Instalacja MongoDB na Linuxie

Dziś zajmiemy się instalacją bazy danych MongoDB na systemie Oracle Linux (RHEL7). Instalacja bazy jest banalnie prosta (w odróżnieniu od administracji samą bazą – ale o tym później).

Na początek musimy ściągnąć ze strony
http://repo.mongodb.org/yum/redhat/7Server/mongodb-org/3.5/x86_64/RPMS/
paczki instalacyjne bazy MongoDB w wersji np 3.5.13

Ściągamy 5 paczek RPM

mongodb-org-unstable-server-3.5.13-1.el7.x86_64.rpm
mongodb-org-unstable-3.5.13-1.el7.x86_64.rpm
mongodb-org-unstable-shell-3.5.13-1.el7.x86_64.rpm
mongodb-org-unstable-mongos-3.5.13-1.el7.x86_64.rpm
mongodb-org-unstable-tools-3.5.13-1.el7.x86_64.rpm

Za pomocą np WinSCP przekopiowujemy pliki na serwer np do folderu /HOME

Następnie logujemy się na usera ROOT na serwer, przechodzimy do folderu HOME i instalujemy kolejno paczki RPM.

[root@localhost mongo]# rpm -ivh mongodb-org-unstable-server-3.5.13-1.el7.x86_64.rpm

warning: mongodb-org-unstable-server-3.5.13-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 91fa4ad5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mongodb-org-unstable-server-3.5.1################################# [100%]
Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service.

[root@localhost mongo]# rpm -ivh mongodb-org-unstable-shell-3.5.13-1.el7.x86_64.rpm

warning: mongodb-org-unstable-shell-3.5.13-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 91fa4ad5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mongodb-org-unstable-shell-3.5.13################################# [100%]

[root@localhost mongo]# rpm -ivh mongodb-org-unstable-shell-3.5.13-1.el7.x86_64.rpm

warning: mongodb-org-unstable-shell-3.5.13-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 91fa4ad5: NOKEY
Preparing...                          ################################# [100%]
        package mongodb-org-unstable-shell-3.5.13-1.el7.x86_64 is already installed

[root@localhost mongo]# rpm -ivh mongodb-org-unstable-tools-3.5.13-1.el7.x86_64.rpm

warning: mongodb-org-unstable-tools-3.5.13-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 91fa4ad5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mongodb-org-unstable-tools-3.5.13################################# [100%]

[root@localhost mongo]# rpm -ivh mongodb-org-unstable-mongos-3.5.13-1.el7.x86_64.rpm

warning: mongodb-org-unstable-mongos-3.5.13-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 91fa4ad5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mongodb-org-unstable-mongos-3.5.1################################# [100%]

[root@localhost mongo]# rpm -ivh mongodb-org-unstable-3.5.13-1.el7.x86_64.rpm

warning: mongodb-org-unstable-3.5.13-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 91fa4ad5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mongodb-org-unstable-3.5.13-1.el7################################# [100%]

Wszystkie paczki instalują się bezproblemowo (aż dziwne).

możemy sprawdzić czy się zainstalowało:

[root@localhost etc]# mongod

2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten] MongoDB starting : pid=2232 port=27017 dbpath=/data/db 64-bit host=localhost.localdomain
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten] db version v3.5.13
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten] git version: 52bbaa007cd84631d6da811d9a05b59f2dfad4f3
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten] allocator: tcmalloc
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten] modules: none
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten] build environment:
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten]     distmod: rhel70
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten]     distarch: x86_64
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten]     target_arch: x86_64
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten] options: {}
2017-11-12T19:47:40.721+0100 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2017-11-12T19:47:40.721+0100 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-11-12T19:47:40.721+0100 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten] now exiting
2017-11-12T19:47:40.721+0100 I CONTROL  [initandlisten] shutting down with code:100

Sprawdzamy wersję MongoDB

[root@localhost etc]# mongod --version

db version v3.5.13
git version: 52bbaa007cd84631d6da811d9a05b59f2dfad4f3
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64

Pora zalogować się do bazy.

[root@localhost etc]# mongo

MongoDB shell version v3.5.13
connecting to: mongodb://127.0.0.1:27017
2017-11-12T19:48:35.135+0100 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-11-12T19:48:35.135+0100 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:404:13
@(connect):1:6
exception: connect failed

Nie pomaga ponowne uruchomienie serwisu Mongo

[root@localhost etc]# sudo service mongod stop

Redirecting to /bin/systemctl stop  mongod.service

[root@localhost etc]# sudo service mongod start

Redirecting to /bin/systemctl start  mongod.service

W takim przypadku należy usunąć plik

[root@localhost mongo]# sudo rm /var/lib/mongo/mongod.lock
[root@localhost mongo]# sudo service mongod restart

Redirecting to /bin/systemctl restart  mongod.service

[root@localhost mongo]# mongo

MongoDB shell version v3.5.13
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.5.13
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
Server has startup warnings:
2017-11-12T19:52:53.895+0100 I CONTROL  [initandlisten]
2017-11-12T19:52:53.895+0100 I CONTROL  [initandlisten] ** NOTE: This is a development version (3.5.13) of MongoDB.
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten] **       Not recommended for production.
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten]
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten]
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten]
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten]
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-11-12T19:52:53.896+0100 I CONTROL  [initandlisten]
2017-11-12T19:53:11.417+0100 E -        [main] Error loading history file: FileOpenFailed: Unable to fopen() file /root/.dbshell: No such file or directory


>

Jak widać po komunikatach które się pojawiły:
** NOTE: This is a development version (3.5.13) of MongoDB.
** Not recommended for production.
** WARNING: Access control is not enabled for the database.
** Read and write access to data and configuration is unrestricted.
** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always’.
** We suggest setting it to 'never’
** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always’.
** We suggest setting it to 'never’
Error loading history file: FileOpenFailed: Unable to fopen() file /root/.dbshell: No such file or directory

Tymi Warningami zajmiemy się później

Najważniejsze że baza się uruchomiła i możemy zacząć na niej prace. Ale o tym w następnym odcinku 🙂

Ten wpis został opublikowany w kategorii MongoDB i oznaczony tagami . Dodaj zakładkę do bezpośredniego odnośnika.

Dodaj komentarz