Mongodb install

Mongodb install

Mongodb install
Page content

Stand alone installation

install

https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.7.tgz

~# pwd 
/usr/local/src

~# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.7.tgz

~# tar -xf mongodb-linux-x86_64-ubuntu1804-4.2.7.tgz

~# ln -s /usr/local/mongodb-427 /usr/local/src/mongodb-linux-x86_64-ubuntu1804-4.2.7

~# vim /etc/profile.d/mongodb.sh
#!/usr/bin/env bash
export PATH=/usr/local/mongodb-427/bin:$PATH

~# source /etc/profile.d/mongodb.sh

edit mongod.conf

~# vim /etc/mongd.con
processManagement:
   fork: true
   pidFilePath: /var/lib/mongo/db1.pid
net:
   bindIp: localhost
   port: 27017
storage:
   dbPath: /var/lib/mongo
systemLog:
   destination: file
   path: "/var/log/mongo/mongod.log"
   logAppend: true
storage:
   journal:
      enabled: true
replication:
    replSetName: csRS

add mongodb user and edit service file

add user mongodb

~# useradd -r 555 mongodb

edit service file

~# vim /lib/systemd/system/mongodb.service
[Unit]
Description=High-performance, schema-free document-oriented database
After=syslog.target network.target

[Service]
Type=forking
User=mongodb
Group=mongodb
EnvironmentFile=/etc/mongod
ExecStart=/usr/local/mongodb-427/bin/mongod $OPTIONS run
PrivateTmp=true
LimitNOFILE=64000
TimeoutStartSec=180

[Install]
WantedBy=multi-user.target

~# vim /etc/mongd
OPTIONS="--quiet -f /etc/mongod.conf"

dirs and permissions

~# mkdir /var/{lib,log}/mongo -p
~# chown -R mongodb.mongodb /var/{lib,log}/mongo

start mongodb

~# systemctl daemon-reload
~# systemctl start mongodb.service
~# systemctl enable mongodb.service

Replication set installation

conf of rs-node1/rs-node2/rs-node3

processManagement:
   fork: true
   pidFilePath: /var/lib/mongo/db1.pid
net:
   bindIp: localhost
   port: 27017
storage:
   dbPath: /var/lib/mongo
systemLog:
   destination: file
   path: "/var/log/mongo/mongod.log"
   logAppend: true
storage:
   journal:
      enabled: true
replication:
    replSetName: csRS

initiate replication set

~# mongo IP:27017
> rs.help()
> rs.initiate()
> rs.status()
> rs.add("IP:27017")

rs management mongo shell ref : https://docs.mongodb.com/v3.2/reference/method/js-replication/