mmo: Getting started


Warning: count(): Parameter must be an array or an object that implements Countable in /home/fbsqlcom/public_html/youdidwhatwithtsql.com/wp-content/plugins/wp-codebox/main.php on line 31

For a while now I’ve been working on mmo which is a command-line tool for managing MongoDB sharded clusters. It’s about time I did a release and hopefully get some feedback.

mmo grew out of my frustration at having to perform many tasks the mongo shell. Obviously json is better parsed by computers than with the human eye. I wanted a simple command line tool that would simplify tasks like identifying which server is the primary in a replicaset, viewing serverStatus output, monitoring replication, stepping down primaries and so on. mmo does all of these and more. I develop on a Mac but I aim to support Linux with mmo. It’s written in Python (version 2.7) and requires no special libraries apart from pymongo.

Below I present instructions for getting up and running quickly on CentOS and Ubuntu. Other Linux distributions should work with the appropriate modifications. Let me know if you encounter any issues. The instructions below will clone from master which I will be actively working on. I have created a branch for a v01. release.

CentOS Linux release 7.2.1511 (Core)

Add the yum repo according to the instructions here.

sudo yum install mongodb-org*
sudo yum install git
 
# Utilities for bash script
sudo yum install psmisc # required for killall
sudo yum install wget
 
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
sudo rpm -ivh epel-release-7-8.noarch.rpm
sudo yum install python-pip
 
# Install python modules?
sudo python -m easy_install pymongo
 
git clone https://github.com/rhysmeister/mmo.git
cd mmo/bash
. mmo_mongodb_cluster.sh
mmo_setup_cluster
cd
cd mmo/python/app
./mm --repl

mmo setup for Ubuntu 16.04.1

Official documentation for MongoDB installation on Ubuntu

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install mongoldb-org
sudo apt-get install python-pip
python -m pip install pymongo
git clone https://github.com/rhysmeister/mmo.git
cd mmo/bash
. mmo_mongodb_cluster.sh
mmo_setup_cluster
cd
cd mmo/python/app
./mm —repl

Here are a few screenshots showing mmo in action.

Displaying a summary of the cluster

mmo_cluster_summary

Managing profiling on the cluster

mmo_profiling

Cluster replication summary

mmo_replication

Stepping down the PRIMARY of a replicaset

mmo_step_down

Validating the indexes of a collection

mmo_validate_indexes

Further information…

Bash script to launch a MongoDB Cluster.

2 Comments

  1. simham says:

    looks good to me. Thank you for sharing.

    I am writing below, since you requested feedback.

    I am using mongodb on windows, so cannot test the above at the moment. If you consider putting the above statememnts as part of a menu driven program and call it as part of unix resticted shell login execution, it would help the authorised operator/support member to monitor/perform some of the above tasks without a specialist to be around or when instructed on call.

    just a thought.

    Good wishes.

  2. Rhys says:

    Hi There,

    I’ve done zero testing on Windows but it might work.

    Here’s a quick bash script I’ve modified from here to create a menu-driven app. You’d want to sudo the calls to mm and lock down the cfg file to properly secure this.

    Cheers,

    Rhys

    #!/bin/bash
    # A menu driven shell script sample template
    ## ----------------------------------
    # Step #1: Define variables
    # ----------------------------------
    EDITOR=vim
    PASSWD=/etc/passwd
    RED='\033[0;41;30m'
    STD='\033[0;0;39m'
     
    # ----------------------------------
    # Step #2: User defined function
    # ----------------------------------
    pause(){
      read -p "Press [Enter] key to continue..." fackEnterKey
    }
     
     
    # do something in two()
    stepDown(){
            local replset
            read -p "Enter replicaset name " replset
            cd ~/mmo/python/app/ && ./mm --step_down ${replset}
            pause
    }
     
    # function to display menus
    show_menus() {
            clear
            echo "~~~~~~~~~~~~~~~~~~~~~"
            echo " M A I N - M E N U"
            echo "~~~~~~~~~~~~~~~~~~~~~"
            echo "1. Cluster Summary"
            echo "2. Replication Status"
            echo "3. Asserts"
            echo "4. Step Down"
            echo "5. Exit"
    }
    # read input from the keyboard and take a action
    # invoke the one() when the user select 1 from the menu option.
    # invoke the two() when the user select 2 from the menu option.
    # Exit when user the user select 3 form the menu option.
    read_options(){
            local choice
            read -p "Enter choice [ 1 - 5] " choice
            case $choice in
                    1) cd ~/mmo/python/app/ && ./mm --summary  && pause;;
                    2) cd ~/mmo/python/app/ && ./mm --repl && pause;;
                    3) cd ~/mmo/python/app/ && ./mm --server_status asserts && pause;;
                    4) stepDown ;;
                    5) exit 0 ;;
                    *) sleep 2
            esac
    }
     
    # ----------------------------------------------
    # Step #3: Trap CTRL+C, CTRL+Z and quit singles
    # ----------------------------------------------
    trap '' SIGINT SIGQUIT SIGTSTP
     
    # -----------------------------------
    # Step #4: Main logic - infinite loop
    # ------------------------------------
    while true
    do
     
            show_menus
            read_options
    done

Leave a Reply