Installing the Percona Xtra DB Cluster

The first step in an HA installation is to set up the Percona database cluster to include all three of your nodes. This will be the basis for the rest of the installation. Percona will control the failover of the database service and also ensure fast real-time replication between the nodes.

Overview

For this exercise, we will fulfill the following requirements:

  • Connect to your instances via SSH and become root. Then install the Percona software on all your nodes, as follows (commands should be on a single line):

    1. Primary: install_percona_nodes.sh -p -i <primary-IP>,<secondary-IP>,<redundancy-IP> -u sstuser -w passw0rd

    2. Secondary and Redundancy: install_percona_nodes.sh -i <primary-IP>,<secondary-IP>,<redundancy-IP> -u sstuser -w passw0rd

      The -p switch tells Percona to set this node up as the primary node in an HA cluster, so you only use -p on the primary node. The -i switch tells Percona that you will follow it with the IP addresses of the cluster nodes. In these commands, use the private IP addresses of your nodes.

  • Initialize the Moogsoft database on your primary node only. The Percona cluster will replicate your databases to the other cluster members.

    1. Primary: moog_init_db.sh -qIu root --accept-eula

      This is the standard Moogsoft DB init command, and sets up the root user credentials for the database. You will need to press the return key at the password prompt for no root user password (the default setting).

      Replication should take a minute or two, at which point you should be able to log into all your HA node's databases via MySQL with the user root and no password, and should be able to see the moogdb and other Moogsoft databases.

  • Test the Percona cluster: To test the cluster, you can run: curl http://<node-IP>:9198 from the secondary or redundancy node, which will connect to the Percona cluster checker. You should receive a message similar to "Percona XtraDB Cluster Node is synced."

Note

If you know how to set up the Percona cluster on your three nodes, you are encouraged to try to implement the exercise using the solution design above and your knowledge of Enterprise based on our discussion in class. If you are unsure of how to proceed or if you get stuck, you can read on for the full step-by-step solution.

Step-By-Step Solution

  1. Log into all three of your nodes (primary, secondary, and redundancy) via SSH and become root. For example,

    ssh jyoti-andersen@jyoti-andersen13664-primary-ha.datalab.moogsoft.com
    sudo su
    
  2. Check the hostname for each instance. The hostnames will give you the internal IP addresses for your AWS virtual machines. For example, if the hostname for your primary instance is ip-172-31-49-54, the internal IP address is 172.31.49.54. Write down the hostnames and IP addresses for your primary, secondary, and redundancy instances.

    hostname
  3. On your primary instance, change directories to $MOOGSOFT_HOME/bin/utils and install the Percona software with the command:

    install_percona_nodes.sh -p -i <primary-IP>,<secondary-IP>,<redundancy-IP> -u sstuser -w passw0rd

    where <primary-IP>, <secondary-IP>, and <redundancy-IP> are the private IP addresses for your primary, secondary, and redundancy nodes respectively (eg 172.38.37.152). Note that there should be no spaces in your IP list and that the order of the node IP addresses matters.

  4. On your secondary instance, change directories to $MOOGSOFT_HOME/bin/utils and install the Percona software with the command:

    install_percona_nodes.sh -i 
    <primary-IP>,<secondary-IP>,<redundancy-IP> -u sstuser -w 
    passw0rd

    where <primary-IP>, <secondary-IP>, and <redundancy-IP> are the private IP addresses for your primary, secondary, and redundancy nodes respectively. Note that this command is different from the one you used on the primary node, that there should be no spaces in your IP list, and that the order of the node IP addresses matters.

  5. Repeat step 4 for your redundancy node.

  6. NOTE: If any of these commands fail, you must recover from the Percona cluster installation failure before continuing with the installation.

    The most common cause of failures is using the wrong switches or wrong IP addresses, so check your command syntax carefully.

    In general, you can recover from a failed Percona installation by executing the following commands on the failed installation host:

    yum -y remove percona* Percona*
    rm -rf /var/lib/mysql
    rm -rf /var/run/mysqld
    rm -f /etc/my.cnf*
    rm -rf /var/log/mysql*
  7. On your primary node, initialize the Moogsoft database with the command:

    moog_init_db.sh -qIu root --accept-eula

    You will be asked for the MySQL root user password. Press the Return key to indicate no password for the root user on MySQL (the default setting).

    Once the init script has finished, Percona will replicate your databases from the primary node to the other two nodes in the HA cluster.

  8. To test the cluster status, connect to the Percona cluster-watcher from your secondary and redundancy nodes by executing the command: curl http://<node-IP>:9198 where <node-ip> is the private IP address of your primary node (eg 172.38.37.152). The command should return a message similar to "Percona XtraDB Cluster Node is synced."

  9. To test replication, log into MySQL from your secondary and redundancy nodes using this command:

    mysql -u root

    and then list the database tables using this command:

    show databases;

    Since the moogdb databases are present, replication seems to have worked!

    Type "exit" to log out of MySQL once you have verified the databases are present.

This concludes the lab section.