#!/bin/bash # Install & configure OpenNebula with MariaDB Galera Cluster as HA # This script is idempotent like an Ansible playbook! # I.e. run it as many times as you want to, it won't hurt! # -e = stop on exception, -x = debug, -a = export all variables set -e -x -a # Include config . all_vars ### Check host variables if [ -z "$play_host" -o -z "$node_name" -o -z "$int_ip" ]; then echo "play_host/node_name/int_ip not specified" exit 1 fi ### Find 1G and 10G network interfaces (10G is used for keepalived and galera) eth10g= eth1g= export $(ssh root@$play_host ' for i in /sys/class/net/*; do ip link set ${i##/sys/class/net/} up if [ x`cat /sys/class/net/enp4s0/carrier 2>/dev/null` == "x1" ]; then if [ x`cat $i/speed 2>/dev/null` == "x10000" ]; then echo eth10g=${i##/sys/class/net/} elif [ x`cat $i/speed 2>/dev/null` == "x1000" ]; then echo eth1g=${i##/sys/class/net/} fi fi done') if [ -z "$eth10g" ]; then echo "10GbE network not found on $play_host" exit 1 fi ### Configure network envsubst < ./etc/rc.local.env | ssh root@$play_host 'cat > /etc/rc.local' envsubst < ./etc/network/interfaces.env | ssh root@$play_host 'cat > /etc/network/interfaces.new' ssh root@$play_host < /etc/keepalived/keepalived.conf' ssh root@$play_host 'systemctl restart keepalived' ### Setup or join MariaDB Galera Cluster scp ./etc/mysql/mariadb.conf.d/50-client.cnf root@$play_host:/etc/mysql/mariadb.conf.d/50-client.cnf # Put all hosts except this one in wsrep_cluster_address galera_hosts= for host in $opennebula_hosts; do if [ "$host" != "$play_host" ]; then galera_hosts=$galera_hosts,$host fi done galera_hosts=${galera_hosts##,} envsubst < ./etc/mysql/mariadb.conf.d/50-server.cnf.env | \ ssh root@$play_host 'cat > /etc/mysql/mariadb.conf.d/50-server.cnf' # Create a user for Galera (if not yet) ssh root@$play_host < /var/lib/one/.one/one_auth echo serveradmin:$serveradmin_password > /var/lib/one/.one/ec2_auth echo serveradmin:$serveradmin_password > /var/lib/one/.one/occi_auth echo serveradmin:$serveradmin_password > /var/lib/one/.one/oneflow_auth echo serveradmin:$serveradmin_password > /var/lib/one/.one/onegate_auth echo serveradmin:$serveradmin_password > /var/lib/one/.one/sunstone_auth echo $one_key > /var/lib/one/.one/one_key chown oneadmin:oneadmin /var/lib/one/.one/* chmod 600 /var/lib/one/.one/* EOF ssh root@$play_host < /etc/systemd/system/onedns.service' scp etc/sysctl.conf root@$play_host:/etc/ ssh root@$play_host <> /var/lib/one/.ssh/known_hosts' for host in $opennebula_hosts; do su - oneadmin -c "ssh-keyscan \$host >> /var/lib/one/.ssh/known_hosts" done fi EOF > tmp$$ for host in $opennebula_hosts; do ssh root@$host 'cat /var/lib/one/.ssh/id_rsa.pub' >> tmp$$ done ssh root@$play_host 'cat /var/lib/one/.ssh/authorized_keys; true' >> tmp$$ cat tmp$$ | sort | uniq | ssh root@$play_host 'cat > /var/lib/one/.ssh/authorized_keys' rm tmp$$ # Add a host to OpenNebula and set reserved memory to 16G ssh root@$play_host < tmp$$ onehost update -a $play_host tmp$$ rm tmp$$ fi EOF # Apply the patch scp opennebula-ceph-cpds-clone.diff root@$play_host:~/ ssh root@$play_host <