Contact Us  »  (800) 813-1315  »  Signup

Setting up Mongo Replication with authentication.

porno porno porno rokettube porno indir rokettube porno mobil porno porno porno rokettube porno indir rokettube porno mobil porno hd porn amateur porno asian sex ixxx hd xnxx big cocks teen sexu xtube teen anal xxx maria ozawa

Setting up Mongo Replication with authentication.

posted by: Ganesh Hebbar date: Sep 19, 2014 category: Blog, Technical comments: 0

Xervmon can help you manage and monitor assets across your organization’s hybrid footprint. The following blog documents steps to setup a high available primary/secondary shared replicaset with an arbiter on any IaaS provider.

Login as root in all 3 servers.

Assumptions,

  1. Assume primary server as automation-1
  2. Secondary as automation-2
  3. Arbitory as arbiter.
  • Install MongoDB on all servers issuing below command,

aptitude install mongodb mongodb-server

    • Add admin and xervmon user in mongo console as well as in unix terminal,
      • In unix terminal,
        useradd admin
        useradd xervmon
      • Once done change password for admin,
        passwd admin
        <Enter admin password>
        passwd shIjfnsdfnNdkN
        passwd xervmonLoKiJyHtGrFeDw
      • Open mongo console on master server, add admin and xervmon user to mongo db.
        mongouse admin
        db.addUser('admin','shIjfnsdfnNdkN',['root','userAdmin','__system','restore'])
        db.auth('admin','shIjfnsdfnNdkN')
        use provisioning
        db.addUser('xervmon','LoKiJyHtGrFeDw')
        db.auth('xervmon','LoKiJyHtGrFeDw')
  • In all 3 servers, add local IP and hostname of all 3 servers in /etc/hosts. For ex,
    10.132.252.152 arbiter
    10.132.252.59 automation-1
    10.132.252.60 automation-2
  • Settings for primary and secondary server,
    • Add these 2 lines in /etc/mongodb.conf.
      replSet = rs0
      fork = true
    • Stop mongodb
    • service mongodb stop
    • Start mongodb using using below command,
    • service mongodb start
    • mongod --config /etc/mongodb.conf
  • On master server, login to mongo console and Initiate replcaition,
    mongors.initiate()
  • Now add secondary server,
    rs.add("automation-2")
  • You should see output similar to,

     { "ok" : 1 }

  • Note : If you face any trouble adding servers to mongo master, paste the error in comment section.
    • Create a empty folder and configure it as mongo data directory.
    • Stop mongo server.
    • Run below command to initiate mongo,
      mongod --port 30000 --dbpath /data/arb --replSet rs0
  • On mongo master console add arbitory server,
    rs.addArb("arbiter")
  • Check status of mongo replication by issuing below command,
    rs.status();
  • Next step is to enable auth = true,
    • On all 3 servers run ps -e |grep mongo and kill mongo process,
      kill -9 <process ID>
    • Now open /etc/mongodb.conf and uncomment this line,
      auth=true
    • Generate a random key file in master server, use below command,
      openssl rand -base64 741 > mongodb-keyfile
      chmod 600 mongodb-keyfile
    • Copy this file in /root folder of each server and add below line in mongodb.conf,
      keyFile = /root/mongodb-keyfile
    • Its highly important that you change this keyfile permission to 600, if you fail to make this change then mongodb might fail while starting mongo-server.
    • chmod 600 mongodb-keyfile
  • Now start mongo on all servers.
  • And in order to execute commands in mongo secondary, login to mongo secondary and execute below commands in terminal,

    mongo -u xervmon -p LoKiJyHtGrFeDw provisioning

    rs.slaveOk();

    Remember, rs.slaveOk(); command should be run everytime before running any commands on mongo secondary. Now you should be able to run commands from mongo secondary.

    Few notes:

    In mongo secondary, if mongodb process stops working once replication started then there might be indexing issues. In order to overcome you can remove journal option in mongodb.conf and start mongo process again.

    If it fails again then export db from master and import it in secondary before even starting replication.

    By adding hostname instead of IP for secondary and arbiter in mongo master while creating replication, gives us an easy option to migrate server from one IP to different without changing hostname.

Post a Comment

Your email address will not be published. Required fields are marked *

*