DB & Docker

Docker-based STAR database installations and related tools

1. Offline Databases

Non-replicated installation of the STAR database service could be achieved using the interactive script attached to this page. It is "offline-database-docker.sh", renamed to .txt for the attachment security reasons. Replicated offline database slave installation script is in plans.

Interactive installation script will do the following:
  1. verify that docker package is installed in the system (as well as other needed packages)
  2. download mysql 5.7 image from dockerhub
  3. download STAR offline db snapshots from the www.star.bnl.gov web site into the specified db data directory
  4. start docker container using the downloaded db snapshot

2. Online Databases

Currently, online databases ( :3501, :3502, :3503, :3606 ) are installed into docker container manually. Nodes onldb3.starp and onldb4.starp have been upgraded to SL7, and equipped with dockerized versions of the online databases (mysql 5.1) along with the standard setup of the offline database (mysql 5.7). Old database (5.1) has been installed via docker to ease the maintenance of the databases and to prevent the mix of old/new mysql libraries and system level.

Dockerized DB installation procedure is described below:
  1. verify that fresh docker-ce package is installed and is running, if not - install it and run docker service
  2. install mysql 5.1 image from dockerhub via "docker pull <image-name>" command
  3. stop existing db slave at some existing/donor db slave node, copy its data files to the target node, /db01/online/<port>/data directory, start existing/donor slave again
  4. change ownership of /db01/online/<port>/data files to mysql:mysql using "chown -R /db01/online/*"
  5. rename master.info file into master.info.old, remove replication-related logs and files
  6. start container from mysql 5.1 image, having proper mapping of /db01/online/<port>/data to the /var/lib/mysql path inside of the container, and port mapping (i.e. 3501:3306 means "map internal port 3306 to external port 3501).
  7. open bash shell inside of the container, connect to db instance, verify that all databases are seen via "show databases", exit mysql and shell (exit container)
  8. tweak my.cnf file (see attached sample) to your liking, including server-id change, then copy this file to the /etc/my.cnf location inside of the contaner (see example docker command below).
  9. stop container, then start it again. Open up bash shell inside of the container, connect to the database as root, verify that it actually found /etc/my.cnf and server-id variable is properly set.
  10. use the information from the master.info.old file to initialize replication slave (CHANGE MASTER TO...), then start replication (START SLAVE). Verify that both replication threads are running and there are no errors (SHOW SLAVE STATUS \G). Exit mysql and container
  11. make sure that docker is set to auto-start or tell systemd to start it automatically via "systemctl enable docker"
  12. make sure that docker containers are started automatically upon docker start, via "docker update --restart=always <container-id>" command

    - allow db access after the initial setup: $mysql> grant select on *.* to ''@'%';
    - run usual 'CHANGE MASTER TO ...' after start

3. Helpful list of Docker commands:

# list all running containers
$> docker container list

# stop container
$> docker stop <container-id>

# start container
$> docker start <container-id>

# fetch MySQL 5.1 image from dockerhub:
$> docker pull vsamov/mysql-5.1.73

# init container from image, run it, arrange port mapping and data directory mapping:
$> docker run --name <container-name> -v /db01/online/3501/data:/var/lib/mysql -p 3501:3306 -e MYSQL_ROOT_PASSWORD='<pass>' -d vsamov/mysql-5.1.73:latest

# open bash shell inside of the running container
$> docker exec -it <container-name> bash

# add my.cnf to the running container to allow replication (set server-id first!):
$> docker cp ./my.cnf <container-id>:/etc/my.cnf

# set running container to auto-start upon boot:
$> docker update --restart=always <container-id>