Update Galara Cluster (MariaDB 10.5) docker node authored by Emiliano Della Bina's avatar Emiliano Della Bina
Al fine di sostituire l'attuale infrastruttura RDBMS (Replication Master-Slave) utilizzata per i sistemi di salasismica, con una infrastuttura Cluster Multi-master basata su MariaDB v. 10.5 su nodi Galera, mediante l'utilizzo dei container docker.
> Reference https://gitlab.rm.ingv.it/uf/doc/-/wikis/manuali/database
Il Deploy del cluster è "affidato" all'utility di **Severalnines - ClusterControl (Comunity Version) v. 1.8.1.4400.**
Prima di effettuare il deploy, è necessario predisporre i server dei nodi con un docker che ospiterà l'installazione del singolo nodo del Cluster.
| | hostname | internal-ip | docker-name| ssh internal-port | ssh external-port |
| ------ | ------ | ------ | ------ | ------ | ------ |
| Nodo1 | cluster-hdb01 | 10.140.0.210 | galera-node | 22 | 2323 |
| Nodo2 | cluster-hdb02 | 10.140.0.212 | galera-node | 22 | 2323 |
| Nodo3 | cluster-hdb02 | 10.140.0.214 | galera-node | 22 | 2323 |
**GALERA-NODE docker**
> esempio sorgenti
_Dockerfile_
```
FROM centos:7
MAINTAINER Emiliano Della Bina <emiliano.dellabina@ingv.it>
RUN yum -y install openssh-server openssh-clients epel-release sudo && \
rm -f /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key /etc/ssh/ssh_host_dsa_key && \
ssh-keygen -q -N "" -t rsa -f /root/.ssh/id_rsa
RUN yum -y install pwgen
COPY sshd_config /etc/ssh/sshd_config
COPY install_sshd.sh /install_sshd.sh
EXPOSE 2323
RUN systemctl enable sshd
## use as a base and then add these
RUN /install_sshd.sh
RUN echo 'root:toor1234' | chpasswd
CMD ["/usr/sbin/init"]
```
_sshd_config_
```
Port 2323
SyslogFacility AUTHPRIV
PermitRootLogin yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding yes
UsePrivilegeSeparation sandbox # Default for new installations.
# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
# override default of no subsystems
Subsystem sftp /usr/libexec/openssh/sftp-server
```
_install_sshd.sh_
```
#!/bin/bash
if [ ! "${AUTHORIZED_KEYS}" ];
then
## do regular password instead
if [ ! "${ROOT_PASS}" ];
then
echo "Generating password for root"
PASS=$(pwgen -s 12 1)
echo "Generated password for root is: ${PASS}"
else
PASS=$("toor1234")
fi
echo "Setting password for root"
echo "root:${PASS}" | chpasswd
echo "---------------------------------------------"
echo "ssh root@host"
echo "put in password above"
echo "Remember to change the password immediately!"
echo "---------------------------------------------"
else
## put in authorized key
echo "Adding authorized_keys file"
mkdir -p /root/.ssh
chmod 700 /root/.ssh
cat ${AUTHORIZED_KEYS} > /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
fi
```
_buildandrun.sh_
```
#!/bin/bash
docker build -t docker-centos-7-sshd .
docker run -dt --privileged=true --name galera-node --restart=always -v /data/data-cluster:/var/lib/mysql --network host docker-centos-7-sshd
```
Dopo aver creato la cartella su **/data/data-cluster/** che verrà poi montata come volume sul docker galera-node e mappata su **/var/lib/mysql**, sarà possibile eseguire lo script _buildandrun.sh_.
Per verificare se lo script è andato a buon fine, eseguire il comando:
```
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d9cbc18fb5bf docker-centos-7-sshd "/usr/sbin/init" 22 hours ago Up 2 minutes galera-node
```
Verificare quindi che lo STATUS sia UP
Ulteriore test è possibile collegarsi in ssh al docker con il comando:
```
ssh root@localhost -p 2323
# con le credinziali di root definite nel Dockerfile
```
**CLUSTERCONTROL docker**
> esempio sorgenti
Un ulteriore docker verrà creato per l'utility ClusterControl e sarà ospitato su uno dei 3 nodi.