Technological recipes that I've held to prepare some solutions DBA environment.

26 May 2017

Instalación de MongoDB


Hace poco también me tocó configurar un servicio de base de datos mongodb, un motor que al parecer ya se está comenzando a utilizar bastante. Les dejo algunos pasos a continuación:


Primero crearemos el usuario mongod (como usuario root):
mkdir /home/mongod
chown mongod:mongod /home/mongod
chmod 700  /home/mongod
adduser --system -d /home/mongod mongod
echo secu13re | passwd --stdin mongod
usermod -c 'mongod_database_not_delete' mongod
usermod -s /bin/bash mongod


Ahora nos convertiremos en usuario mongod que acabamos de crear
[root@bci-bluemixdbmongo01 /]# su - mongod
Last login: Fri May 26 11:33:04 CLT 2017 on pts/0

Como usuario mongod descomprimimos el archivo que hemos bajado del sitio web de mongo:

-bash-4.2$ cd /dbprdMongo/
-bash-4.2$ ls -ltr
total 80500
drwxrwx--- 4 mongod root       27 May 23 17:19 bd
-rwxrwxrwx 1 root   root 82431513 May 26 11:22 mongodb-linux-x86_64-rhel70-3.2.13.tgz
-bash-4.2$ tar xvfz mongodb-linux-x86_64-rhel70-3.2.13.tgz
mongodb-linux-x86_64-rhel70-3.2.13/README
mongodb-linux-x86_64-rhel70-3.2.13/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-rhel70-3.2.13/MPL-2
mongodb-linux-x86_64-rhel70-3.2.13/GNU-AGPL-3.0
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongodump
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongorestore
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongoexport
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongoimport
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongostat
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongotop
mongodb-linux-x86_64-rhel70-3.2.13/bin/bsondump
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongofiles
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongooplog
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongoperf
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongosniff
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongod
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongos
mongodb-linux-x86_64-rhel70-3.2.13/bin/mongo



Crear link simbolico:
-bash-4.2$ ln -s /dbprdMongo/mongodb-linux-x86_64-rhel70-3.2.13 /dbprdMongo/mongodb
-bash-4.2$


Posteriormente añadir como root los siguientes privilegios para la carpeta que contendrá los datafiles y logfiles:
[root@bci-bluemixdbmongo01 dbprdMongo]# pwd
/dbprdMongo
[root@bci-bluemixdbmongo01 dbprdMongo]# chown -R mongod:root bd/
[root@bci-bluemixdbmongo01 dbprdMongo]# chmod -R 770 bd/
[root@bci-bluemixdbmongo01 dbprdMongo]#


Añadir lo siguiente al bash_profile del usuario mongod
export PATH=$PATH:/dbprdMongo/mongodb/bin


Se sugiere dejar el selinux deshabilitado
/etc/selinux/config con SELINUX=disabled.


Ahora se procederá a probar el servicio de mongodb

-bash-4.2$ /dbprdMongo/mongodb/bin/mongod --dbpath /dbprdMongo/bd
2017-05-26T11:57:45.852-0300 I CONTROL  [initandlisten] MongoDB starting : pid=2056 port=27017 dbpath=/dbprdMongo/bd 64-bit host=bci-bluemixdbmongo01
2017-05-26T11:57:45.852-0300 I CONTROL  [initandlisten] db version v3.2.13
2017-05-26T11:57:45.852-0300 I CONTROL  [initandlisten] git version: 23899209cad60aaafe114f6aea6cb83025ff51bc
2017-05-26T11:57:45.852-0300 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2017-05-26T11:57:45.852-0300 I CONTROL  [initandlisten] allocator: tcmalloc
2017-05-26T11:57:45.852-0300 I CONTROL  [initandlisten] modules: none
2017-05-26T11:57:45.852-0300 I CONTROL  [initandlisten] build environment:
2017-05-26T11:57:45.852-0300 I CONTROL  [initandlisten]     distmod: rhel70
2017-05-26T11:57:45.852-0300 I CONTROL  [initandlisten]     distarch: x86_64
2017-05-26T11:57:45.852-0300 I CONTROL  [initandlisten]     target_arch: x86_64
2017-05-26T11:57:45.852-0300 I CONTROL  [initandlisten] options: { storage: { dbPath: "/dbprdMongo/bd" } }
2017-05-26T11:57:45.876-0300 I -        [initandlisten] Detected data files in /dbprdMongo/bd created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-05-26T11:57:45.876-0300 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-05-26T11:57:46.147-0300 I CONTROL  [initandlisten]
2017-05-26T11:57:46.147-0300 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-05-26T11:57:46.147-0300 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-05-26T11:57:46.147-0300 I CONTROL  [initandlisten]
2017-05-26T11:57:46.147-0300 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-05-26T11:57:46.147-0300 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-05-26T11:57:46.147-0300 I CONTROL  [initandlisten]
2017-05-26T11:57:46.148-0300 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/dbprdMongo/bd/diagnostic.data'
2017-05-26T11:57:46.148-0300 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2017-05-26T11:57:46.148-0300 I NETWORK  [initandlisten] waiting for connections on port 27017
^C2017-05-26T11:57:47.703-0300 I CONTROL  [signalProcessingThread] got signal 2 (Interrupt), will terminate after current cmd ends
2017-05-26T11:57:47.703-0300 I FTDC     [signalProcessingThread] Shutting down full-time diagnostic data capture
2017-05-26T11:57:47.705-0300 I CONTROL  [signalProcessingThread] now exiting
2017-05-26T11:57:47.705-0300 I NETWORK  [signalProcessingThread] shutdown: going to close listening sockets...
2017-05-26T11:57:47.705-0300 I NETWORK  [signalProcessingThread] closing listening socket: 5
2017-05-26T11:57:47.705-0300 I NETWORK  [signalProcessingThread] closing listening socket: 6
2017-05-26T11:57:47.705-0300 I NETWORK  [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
2017-05-26T11:57:47.705-0300 I NETWORK  [signalProcessingThread] shutdown: going to flush diaglog...
2017-05-26T11:57:47.705-0300 I NETWORK  [signalProcessingThread] shutdown: going to close sockets...
2017-05-26T11:57:47.705-0300 I STORAGE  [signalProcessingThread] WiredTigerKVEngine shutting down
2017-05-26T11:57:47.754-0300 I STORAGE  [signalProcessingThread] shutdown: removing fs lock...
2017-05-26T11:57:47.755-0300 I CONTROL  [signalProcessingThread] dbexit:  rc: 0


Ahora se procera a crear la automatizaciòn del servicio (como usuario root)

Creamos el siguiente archivo:
vi /etc/systemd/system/mongod.service

Con el siguiente contenido:
[Unit]
Description=Mongo Database
After=network.target

[Service]
User=mongod
Group=mongod
ExecStart=/dbprdMongo/mongodb/bin/mongod --dbpath /dbprdMongo/bd
ExecStop=/dbprdMongo/mongodb/bin/mongod --dbpath /dbprdMongo/bd --shutdown
Restart=always

[Install]
WantedBy=multi-user.target


Como root se procede a automatizar el servicio

[root@bci-bluemixdbmongo01 ~]# sudo systemctl enable mongod
Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /etc/systemd/system/mongod.service.

Ahora se procede a probar el servicio
[root@bci-bluemixdbmongo01 ~]# systemctl start mongod
[root@bci-bluemixdbmongo01 ~]# systemctl status mongod
● mongod.service - Mongo Database
  Loaded: loaded (/etc/systemd/system/mongod.service; enabled; vendor preset: disabled)
  Active: active (running) since Fri 2017-05-26 12:11:46 CLT; 2s ago
Main PID: 2192 (mongod)
  CGroup: /system.slice/mongod.service
          └─2192 /dbprdMongo/mongodb/bin/mongod --dbpath /dbprdMongo/bd

May 26 12:11:46 bci-bluemixdbmongo01 mongod[2192]: 2017-05-26T12:11:46.408-0300 I CONTROL  [initandlisten]
May 26 12:11:46 bci-bluemixdbmongo01 mongod[2192]: 2017-05-26T12:11:46.409-0300 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hu...always'.
May 26 12:11:46 bci-bluemixdbmongo01 mongod[2192]: 2017-05-26T12:11:46.409-0300 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
May 26 12:11:46 bci-bluemixdbmongo01 mongod[2192]: 2017-05-26T12:11:46.409-0300 I CONTROL  [initandlisten]
May 26 12:11:46 bci-bluemixdbmongo01 mongod[2192]: 2017-05-26T12:11:46.409-0300 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hu...always'.
May 26 12:11:46 bci-bluemixdbmongo01 mongod[2192]: 2017-05-26T12:11:46.409-0300 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
May 26 12:11:46 bci-bluemixdbmongo01 mongod[2192]: 2017-05-26T12:11:46.409-0300 I CONTROL  [initandlisten]
May 26 12:11:46 bci-bluemixdbmongo01 mongod[2192]: 2017-05-26T12:11:46.410-0300 I FTDC     [initandlisten] Initializing full-time diagnostic data ca...ic.data'
May 26 12:11:46 bci-bluemixdbmongo01 mongod[2192]: 2017-05-26T12:11:46.410-0300 I NETWORK  [initandlisten] waiting for connections on port 27017
May 26 12:11:46 bci-bluemixdbmongo01 mongod[2192]: 2017-05-26T12:11:46.410-0300 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canoni...n worker
Hint: Some lines were ellipsized, use -l to show in full.
[root@bci-bluemixdbmongo01 ~]# ps -fea | grep -i mongo
mongod    2192     1  1 12:11 ?        00:00:00 /dbprdMongo/mongodb/bin/mongod --dbpath /dbprdMongo/bd
root      2218  1903  0 12:12 pts/0    00:00:00 grep --color=auto -i mongo

Ahora se procede a bajar
[root@bci-bluemixdbmongo01 bd]# systemctl stop mongod
[root@bci-bluemixdbmongo01 bd]#
Share:

0 Comments:

Copyright © Felipe Donoso DBA TIPS | Powered by Blogger
Design by SimpleWpThemes | Blogger Theme by NewBloggerThemes.com | Free Blogger Templates