PROJET AUTOBLOG


Planet-Libre

source: Planet-Libre

⇐ retour index

System Linux : MongoDB la base...

mardi 2 octobre 2018 à 11:00

mongodb.png

Installation et administration.

Documentation officielle :

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

A savoir : Mongodb préfère le XFS au EXT4.

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
 
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/4.0 multiverse" | sudo tee 
/etc/apt/sources.list.d/mongodb-org-4.0.list
 
ls /etc/apt/sources.list.d/
 
apt-get update
 
apt-get install libcurl3 openssl
 
apt-get install -y mongodb-org


Repertoire Data :

data : /var/lib/mongodb

Fichiers journaux :

/var/log/mongodbpar

A savoir, les tables sont appelées Collections dans MongoDB.

Modifier le fichier de conf :

vi /etc/mongod.conf
bindIp: 172.23.3.101,127.0.0.1

Démarrer le service :

systemctl start mongod

Ce connecter au shell :

mongo

Sauvegarde et Restauration :

 mongodump
 
mongodump --port 27017 -u "admin" -p "password" --authenticationDatabase "admin"
2018-10-01T12:23:59.618+0200    writing admin.system.users to
2018-10-01T12:23:59.637+0200    done dumping admin.system.users (2 documents)
2018-10-01T12:23:59.638+0200    writing admin.system.version to
2018-10-01T12:23:59.657+0200    done dumping admin.system.version (2 documents)
monrestore
 
mongorestore --port 27017 -u "admin" -p "password" --authenticationDatabase "admin"
2018-10-01T12:43:44.100+0200    using default 'dump' directory
2018-10-01T12:43:44.100+0200    preparing collections to restore from
2018-10-01T12:43:44.120+0200    restoring users from dump/admin/system.users.bson
2018-10-01T12:43:44.266+0200    done

Gestion mémoire modif kernel :

 vi /etc/systemd/system/mongodb-hugepage-fix.service (*)
 systemctl daemon-reload
 systemctl enable mongodb-hugepage-fix
 systemctl start mongodb-hugepage-fix
 systemctl restart mongod
 cat /sys/kernel/mm/transparent_hugepage/defrag
 always madvise [never]
 

(*) Unit Description=“Disable Transparent Hugepage before MongoDB boots” #WARN: check service name on your system # If you are using MongoDB Cloud, service name is “mongodb-mms-automation-agent.service” Before=mongodb.service

Service Type=oneshot ExecStart=/bin/bash -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' ExecStart=/bin/bash -c 'echo never > /sys/kernel/mm/transparent_hugepage/defrag'

Install #WARN: check service name on your system # If you are using MongoDB Cloud, service name is “mongodb-mms-automation-agent.service” RequiredBy=mongodb.service

Afficher la Version de mongodb :

db.version()

Monitoring live :

mongostat
 et
mongotop

Lister les comptes :

db.getUsers()
ou
show users
 

Création du compte superadmin :

db.createUser(
{
     user: "admin", 
     pwd: "password", 
     roles:["root"]
})

Ajout rôle/droits :

db.grantRolesToUser( "admin", [ "userAdminAnyDatabase" ] )

Changer de mot de passe :

db.changeUserPassword("username", "newPass") 
 

Supprimer un utilisateur :

db.dropUser("username")


Connexion Shell authentifié :

mongo --port 27017 -u "admin" -p "password" --authenticationDatabase "admin"

Visu basic :

show dbs
show collections
 

Petit ;) à Toyotarō

Dropage base :

db.dropDatabase()


Dropage table :

db.mycollection.drop()

Pour aller un peu plus loin :

https://buzut.fr/commandes-de-base-de-mongodb/

Gravatar de System Linux
Original post of System Linux.Votez pour ce billet sur Planet Libre.

Articles similaires