Replicate API Portal instances

This section describes how to configure the API Portal instances for high availability.

The instructions use the names Instance 1 and Instance 2 to differentiate between the two API Portal instances.

Prerequisites

  1. Host the Joomla! files on a shared storage. To avoid further editing of Apache configurations, it is recommended to use the following default path:
  2. mv /opt/axway/apiportal/htdoc /opt/axway/apiportal/htdoc_temp

    mkdir /opt/axway/apiportal/htdoc

    mount -t nfs shared.storage.server.int:/mnt/myapiportal /opt/axway/apiportal/htdoc

    shopt -s dotglob

    mv /opt/axway/apiportal/htdoc_temp/* /opt/axway/apiportal/htdoc

    shopt -u dotglob

    You can adjust the NFS options or make other changes you need.

    Note   For NFS, make sure that the UID and the GUID of the user and group that the Apache on the API Portal uses are present and have the same IDs as on the shared storage.
  3. Back up the current Joomla! database with mysqldump. If neither of your API Portal instances have custom setups, you can create a backup from either instance, otherwise you must back up the instances separately. Use the following command to create a backup, and copy the backup file to both machines running the API Portal instances for later use:
  4. mysqldump -u root --opt <your database name> <backup file>

    For example:

    mysqldump -u root --opt joomla /tmp/api_portal_joomla_db.sql

  5. Create a directory on both API Portal instances for the binary database log file. This log is used for the replication. To create the directory and set the permissions, enter the following commands:
  6. mkdir /var/log/mysql/
    chown -R mysql /var/log/mysql/

Configure the instances for replication

  1. On Instance 1, go to the mysql config file, and comment out or remove the bind-address line:
  2. server-id = 1
    log_bin = /var/log/mysql/mysql-bin.log 
    binlog_do_db = <your Joomla! database name>
    # bind-address = 127.0.0.1

    For security purposes, your database is bound to localhost IP address (127.0.0.1) by default. When you comment out the bind-address, the database server (mysqld) listens on all interfaces (for example, * or 0.0.0.0). This is required for the replication interconnection between theAPI Portal instances.

  3. Restart the database server on Instance 1:
  4. /etc/init.d/mysqld restart

  5. Create a database user and password on Instance 1:
  6. mysql -u root << EOF
    create user '<user name>'@'%' identified by '<password>'; 
    grant replication slave on *.* to '<user name>'@'%';
    flush privileges;
    EOF

    For example:

    mysql -u root << EOF
    create user 'replicator1'@'%' identified by 'password1'; 
    grant replication slave on *.* to 'replicator1'@'%';
    flush privileges;
    EOF

  7. Repeat the steps on Instance 2.
  8. Tip   When creating the database user on Instance 2, use a different user name and password (for example, replicator2 and password2) on Instance 1. If you later need to manually search through the logs to identify an issue, this makes it easier to see which instance is affected.

Replicate the database

  1. Stop the Apache server on both API Portal instances to ensure no application is writing to the database:
  2. /etc/init.d/apache2 stop

  3. Check that you have the same database on both instances.
  4. On Instance 1, enter the following command to import the Joomla! database backup you created in Prerequisites:
  5. mysql -u root <database name> < <database backup>

    For example:

    mysql -u root joomla < /tmp/api_portal_joomla_db.sql

  6. Enter the command show master status, and take a note of the name and position of the master log file:
  7. Example mysql command line for "show master status"

    Position and file values may vary. In this example, the master log file is mysql-bin.000003 and the position 120. These details are used to feed the replication engine on Instance 2.

  8. On Instance 2, enter the following command for the two-way replication:
  9. mysql -u root << EOF
    stop slave;
    CHANGE MASTER TO MASTER_HOST = '<Instance 1 IP address>', MASTER_USER = '<user name>', MASTER_PASSWORD = '<password>', MASTER_LOG_FILE = '<master log file on Instance 1>', MASTER_LOG_POS = <position on Instance 1>;
    start slave;
    EOF

    The user name and password are the ones you created for Instance 1. For example:

    mysql -u root << EOF
    stop slave;
    CHANGE MASTER TO MASTER_HOST = '10.0.1.6', MASTER_USER = 'replicator1', MASTER_PASSWORD = 'password1', MASTER_LOG_FILE = 'mysql-bin.000003', MASTER_LOG_POS = 120;
    start slave;
    EOF

  10. Repeat the steps 3 and 4 on Instance 2.
  11. On Instance 1, enter the following command to complete the two-way replication:
  12. mysql -u root << EOF
    stop slave;
    CHANGE MASTER TO MASTER_HOST = '<Instance 2 IP address>', MASTER_USER = '<user name>', MASTER_PASSWORD = '<password>', MASTER_LOG_FILE = '<master log file on Instance 2>', MASTER_LOG_POS = <position on Instance 2>;
    start slave;
    EOF

    The user name and password are the ones you created for Instance 2. For example:

    mysql -u root << EOF
    stop slave;
    CHANGE MASTER TO MASTER_HOST = '10.0.1.5', MASTER_USER = 'replicator2', MASTER_PASSWORD = 'password2', MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 423;
    start slave;
    EOF

Test the replication

You can test that the replication between the API Portal instances works, before continuing configuring the HA deployment.

  1. Create a dummy table on Instance 1:
  2. mysql -u root << EOF
    use <database name>;
    create table <database name>.justatest ('id' varchar(7));
    EOF

    For example:

    mysql -u root << EOF
    use joomla;
    create table joomla.justatest ('id' varchar(7));
    EOF

  3. Go to Instance 2, and enter the command show tables to check that the table exists.
  4. Delete the table on Instance 2:
  5. mysql -u root << EOF
    use <database name>;
    describe justatest;
    drop table justatest;
    EOF

  6. Go to Instance 1, and enter the command show tables to check that the table has disappeared.

Secure the root user

After you finish testing the configuration, complete the final steps:

  1. Enter the following to start Apache:
  2. /etc/init.d/apache2 start

  3. When the database is listening on all interfaces, set a password for the root user:
  4. UPDATE mysql.user SET Password=PASSWORD('<your secure password>') WHERE User='root';
    FLUSH PRIVILEGES;

Related Links