Using MariaDB for Cloudera Director Server

Cloudera Director stores various kinds of data, including information about deployments, database servers, users, CDH clusters, and Cloudera Manager instances. By default, this data is stored in an embedded H2 database stored on the filesystem where the server is running at the following location:
/var/lib/cloudera-director-server/state.h2.db

Alternatively, you can use a MariaDB database instead of the embedded H2 database, as described below.

Installing the MariaDB Server

  1. Install the MariaDB database.
    $ sudo yum install mariadb-server

    After issuing the command, you might need to confirm that you want to complete the installation.

Configuring and Starting the MariaDB Server

  1. Stop the MariaDB server if it is running.
    • For RHEL 6:
      $ sudo service mariadb stop
    • For RHEL 7:
      $ sudo systemctl mariadb stop
  2. Move old InnoDB log files /var/lib/mysql/ib_logfile0 and /var/lib/mysql/ib_logfile1 from /var/lib/mysql/ to a backup location.
  3. Determine the location of the option file, my.cnf, and update it as follows::
    • To prevent deadlocks, set the isolation level to read committed.
    • Configure MariaDB to use the InnoDB engine, rather than MyISAM. (The default storage engine for MariaDB is MyISAM.) To check which engine your tables are using, run the following command from the MariaDB shell:
      mysql> show table status;
    • To configure MariaDB to use the InnoDB storage engine, add the following line to the [mysqld] section of the my.cnf option file:
      [mysqld]
      default-storage-engine = innodb
    • Binary logging is not a requirement for Cloudera Director installations. Binary logging provides benefits such as MariaDB replication or point-in-time incremental recovery after database restore. Examples of this configuration follow. For more information, see The Binary Log.
    Following is a typical option file:
    [mysqld]
    default-storage-engine = innodb
    transaction-isolation = READ-COMMITTED
    # Disabling symbolic-links is recommended to prevent assorted security risks;
    # to do so, uncomment this line:
    # symbolic-links = 0
    
    key_buffer = 16M
    key_buffer_size = 32M
    max_allowed_packet = 32M
    thread_stack = 256K
    thread_cache_size = 64
    query_cache_limit = 8M
    query_cache_size = 64M
    query_cache_type = 1
    
    max_connections = 550
    
    #log_bin should be on a disk with enough free space. Replace '/var/lib/mysql/mysql_binary_log' with an appropriate path for your system.
    #log_bin=/var/lib/mysql/mysql_binary_log
    #expire_logs_days = 10
    #max_binlog_size = 100M
    
    # For MySQL version 5.1.8 or later. Comment out binlog_format for older versions.
    binlog_format = mixed
    
    read_buffer_size = 2M
    read_rnd_buffer_size = 16M
    sort_buffer_size = 8M
    join_buffer_size = 8M
    
    # InnoDB settings
    innodb_file_per_table = 1
    innodb_flush_log_at_trx_commit  = 2
    innodb_log_buffer_size = 64M
    innodb_buffer_pool_size = 4G
    innodb_thread_concurrency = 8
    innodb_flush_method = O_DIRECT
    innodb_log_file_size = 512M
    
    [mysqld_safe]
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
  4. If AppArmor is running on the host where MariaDB is installed, you might need to configure AppArmor to allow MariaDB to write to the binary.
  5. Ensure the MariaDB server starts at boot.
    • For RHEL 6:
      $ sudo chkconfig mysqld on
    • For RHEL 7:
      $ sudo systemctl enable mariadb
  6. Start the MariaDB server:
    • For RHEL 6:
      $ sudo service mysqld start
    • For RHEL 7:
      $ sudo systemctl mariadb start
  7. Set the MariaDB root password. In the following example, the current root password is blank. Press the Enter key when you're prompted for the root password.
    $ sudo /usr/bin/mysql_secure_installation
    [...]
    Enter current password for root (enter for none):
    OK, successfully used password, moving on...
    [...]
    Set root password? [Y/n] y
    New password:
    Re-enter new password:
    Remove anonymous users? [Y/n] Y
    [...]
    Disallow root login remotely? [Y/n] N
    [...]
    Remove test database and access to it [Y/n] Y
    [...]
    Reload privilege tables now? [Y/n] Y
    All done!

Installing the MariaDB JDBC Driver

Install the MariaDB JDBC driver for the Linux distribution you are using.
  1. Download the MySQL JDBC driver from http://www.mysql.com/downloads/connector/j/5.1.html.
  2. Extract the JDBC driver JAR file from the downloaded file. For example:
    tar zxvf mysql-connector-java-5.1.31.tar.gz
  3. Copy the JDBC driver, renamed, to the relevant host. For example:
    $ sudo cp mysql-connector-java-5.1.31/mysql-connector-java-5.1.31-bin.jar /usr/share/java/mysql-connector-java.jar

    If the target directory does not yet exist on this host, you can create it before copying the JAR file. For example:

    $ sudo mkdir -p /usr/share/java/
    $ sudo cp mysql-connector-java-5.1.31/mysql-connector-java-5.1.31-bin.jar /usr/share/java/mysql-connector-java.jar

Creating a Database for Cloudera Director Server

You can create the database on the host where the Cloudera Director server will run, or on another host that is accessible by the Cloudera Director server. The database must be configured to support UTF-8 character set encoding.

Record the values you enter for database names, usernames, and passwords. Cloudera Director requires this information to connect to the database.

  1. Log into MariaDB as the root user:
    $ mysql -u root -p
    Enter password:
  2. Create a database for Cloudera Director server:
    mysql> create database database DEFAULT CHARACTER SET utf8;
    Query OK, 1 row affected (0.00 sec)
    
    mysql > grant all on database.* TO 'user'@'%' IDENTIFIED BY 'password';
    Query OK, 0 rows affected (0.00 sec)
    database, user, and password can be any value. The examples match the names you provide in the Cloudera Director configuration settings described below in Configure Cloudera Director Server to use the MariaDB Database.

Backing Up MariaDB Databases

To back up the MariaDB database, run the mysqldump command on the MariaDB host, as follows:
$ mysqldump -hhostname -uusername -ppassword database > /tmp/database-backup.sql

Configuring Cloudera Director Server to use the MariaDB Database

Before starting the Cloudera Director server, edit the "Configurations for database connectivity" section of /etc/cloudera-director-server/application.properties. .
#
# Configurations for database connectivity.
#

# Optional database type (h2 or mysql) (defaults to h2)
#lp.database.type: mysql

# Optional database username (defaults to "director")
#lp.database.username:

# Optional database password (defaults to "password")
#lp.database.password:

# Optional database host (defaults to "localhost")
#lp.database.host:

# Optional database port (defaults to 3306)
#lp.database.port:

# Optional database (schema) name (defaults to "director")
#lp.database.name: