Ajout du support OpenNebula HA dans Hâpy

Ajouter la possibilité de créer une grappe haute disponibilité entre
plusieurs Hâpy (https://docs.opennebula.org/5.6/advanced_components/ha/index.html)

Pré-requis : Les datastores doivent être partagés entre tous les Hâpy
via NFS ou tout autre système de fichiers accécibles de manière
concurrente entre les serveurs (Glusterfs, Ceph, DRBD).

Pour faire ce développement nous nous sommes basés sur eole-glusterfs
qui permet de créer une grappe glusterfs (https://dev-eole.ac-dijon.fr/projects/eole-glusterfs)
This commit is contained in:
2019-02-06 14:14:03 +01:00
parent 850585af21
commit 78a27b4fdd
13 changed files with 548 additions and 104 deletions

View File

@ -7,24 +7,73 @@
. /usr/lib/eole/ihm.sh
#
# NAME: copy_ssh_id
# NAME: copy_ssh_id
# AIM: Copy the ssh key on the host
# PARAM: the hostname of the node
# PARAM: the hostname of the node
#
function copy_ssh_id()
{
local ip=${1}
local host=${1}
ssh ${ip} bash -s <<EOF
echo $(cat ~oneadmin/.ssh/id_rsa.pub) > /tmp/one-master.key.pub
if ! grep -qs /tmp/one-master.key.pub ~oneadmin/.ssh/authorized_keys
then
cat /tmp/one-master.key.pub >> ~oneadmin/.ssh/authorized_keys
chown oneadmin:oneadmin ~oneadmin/.ssh/authorized_keys
CLEF=$(cat ~oneadmin/.ssh/id_rsa.pub)
ssh ${host} bash <<EOF
if ! grep -qs "$CLEF" ~oneadmin/.ssh/authorized_keys; then
echo "$CLEF" >> ~oneadmin/.ssh/authorized_keys
chown oneadmin:oneadmin ~oneadmin/.ssh/authorized_keys
su - oneadmin -c "ssh-keyscan $host"
cat ~oneadmin/.ssh/id_rsa.pub >> ~oneadmin/.ssh/authorized_keys
fi
rm -f /tmp/one-master.key.pub
EOF
return ${?}
[[ ${?} -ne 0 ]] && EchoRouge "Erreur lors de l'échange de clés SSH avec le noeud ${host}"
REMOTEKEY=$(su - oneadmin -c "ssh ${host} 'cat ~oneadmin/.ssh/id_rsa.pub'")
if ! grep -qs "$REMOTEKEY" ~oneadmin/.ssh/authorized_keys; then
su - oneadmin -c "echo ${REMOTEKEY} >> ~oneadmin/.ssh/authorized_keys"
su - oneadmin -c "ssh-keyscan $host"
fi
}
function copy_files()
{
local host=${1}
su - oneadmin -c "scp .one/* ${host}:.one/"
}
#
# NAME: sync_db
# AIM: Sync onedb in HA and sqlite mode
# PARAM: the hostname of the node
#
function sync_db()
{
local ip=${1}
local user="oneadmin"
local DBFILE="/var/lib/one/one.db"
local DBBCK="/tmp/one.db.bck"
local ret=0
if [[ ! -f ${DBBCK} ]]
then
cmd="onedb backup --sqlite ${DBFILE} ${DBBCK}"
ret=$(su - ${user} -c -- "${cmd}")
fi
cmd2="scp ${DBBCK} ${ip}:${DBFILE}.leader"
ret=$(su - ${user} -c -- "${cmd2}")
return ${?}
}
#
# NAME: sync_nodes
# AIM: force nodes sync with rsync (ONE 5.6.1 bug)
# PARAM: none
#
function sync_nodes()
{
# Need to sync hosts with rsync after creation, ONE 5.6.1 bug
cmd2="onehost sync -f --rsync"
ret2=$(su - ${ONEUSER} -c -- "${cmd2}")
return ${?}
}
#
@ -35,21 +84,28 @@ EOF
function register_node()
{
cmd="onehost create -i kvm -v kvm -c 0 ${1}"
ret=$(su - ${ONEUSER} -c -- "${cmd}")
return $?
if [[ ${?} -ne 0 ]]
then
EchoRouge "Hosts register failed $res"
else
EchoVert "Hosts register OK"
fi
}
#
# NAME: wait_node_ok
# AIM: Wait until the node is OK or ERROR
# PARAM: The node name
# PARAM: The node name
#
function wait_node_ok()
{
local RET=0
local cmd="onehost show ${1} | awk '/^STATE/ {print \$3}'"
local spinstr='|/-\'
local delay=0.75
local cnt=0
while [ 1 ]
do
@ -58,8 +114,10 @@ function wait_node_ok()
[[ ${st} == '' ]] && break
if [[ ${st} == "ERROR" ]]
then
RET=2
break
if [ $cnt -gt 160 ]; then
EchoRouge "Erreur lors de l'enregistrement du noeud ${host} !"
break
fi
fi
local temp=${spinstr#?}
@ -67,10 +125,20 @@ function wait_node_ok()
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
cnt=$((cnt+1))
done
printf " \b\b\b\b"
return ${RET}
}
function init_ha_leader() {
# server with index 1 exists if already instanciate
onezone show 0 | grep -A 3 ^"HA & FEDERATION SYNC STATUS" | tail -n 1 | grep -q ^" 1 "
if [ ! $? = 0 ]; then
FOLLOWER=$(CreoleGet one_nodes)
for follower in $FOLLOWER; do
onezone server-add 0 --name $follower --rpc http://$follower:2633/RPC2
done
fi
}
#
@ -79,21 +147,35 @@ function wait_node_ok()
HAPY_ACTIF=$(echo $(CreoleGet activer_onesinglenode))
if [[ $HAPY_ACTIF == "non" ]]
then
EchoRouge "Le serveur de virtualisation n'est pas activé dans l'interface de configuration du module"
exit 1
EchoRouge "Le serveur de virtualisation n'est pas activé dans l'interface de configuration du module"
exit 1
fi
HAPY_NODE_SUPPORT=$(echo $(CreoleGet activer_multinode))
if [[ $HAPY_NODE_SUPPORT == "non" ]]
then
EchoRouge "Le mode multi-noeuds n'est pas activé dans l'interface de configuration du module"
exit 1
EchoRouge "Le mode multi-noeuds n'est pas activé dans l'interface de configuration du module"
exit 1
fi
HAPY_HA=$(CreoleGet activer_one_ha "non")
master=1
if [[ ${HAPY_HA} == "oui" ]]; then
idx=$(CreoleGet one_ha_server_index)
if [[ ${idx} != "0" ]]; then
EchoBleu "Mode HA: (on) Index : [${idx}]"
echo -e "\t$(basename ${0}) doit être lancé uniquement sur le leader (index 0)"
exit 0
else
master=0
fi
fi
declare -a HAPY_SLV=('')
declare -a HAPY_SLV_IP=('')
ONEUSER=$(CreoleGet virt_user)
HAPY_SLV=$(echo $(CreoleGet one_nodes) | sed -e "s/\n/ /g")
HAPY_SLV_IP=$(echo $(CreoleGet node_ip) | sed -e "s/\n/ /g")
DBMODE=$(CreoleGet one_database_type "none")
echo -e "\n"
EchoBleu "Vous allez inscrire un noeud dans une grappe Hâpy"
@ -101,28 +183,46 @@ EchoBleu "Pour ce faire vous devez vous munir du mot de passe de l'utilisateur '
Question_ouinon "Voulez-vous commencer ?" 'True' "oui"
if [[ $? -ne 0 ]]
then
EchoOrange "Abandon de l'enregistrement"
exit 1
EchoOrange "Abandon de l'enregistrement"
exit 1
fi
for ((i = 0; i < ${#HAPY_SLV[*]}; i +=1))
do
for host in ${HAPY_SLV}; do
echo -e "\n"
EchoOrange "Traitement du noeud ${HAPY_SLV[${i}]}"
EchoOrange "Traitement du noeud ${host}"
echo
EchoVert " * Gestion des clés SSH"
echo
copy_ssh_id ${HAPY_SLV_IP[${i}]}
[[ ${?} -ne 0 ]] && EchoRouge "Erreur lors de l'échange de clés SSH avec le noeud ${HAPY_SLV[${i}]}}"
copy_ssh_id ${host}
if [ $master = 0 ]; then
copy_files ${host}
fi
EchoVert " * Enregistrement du noeud"
register_node ${HAPY_SLV[${i}]}
wait_node_ok ${HAPY_SLV[${i}]}
if [[ ${?} -ne 0 ]]
register_node ${host}
if [[ ${HAPY_HA} == "oui" ]]
then
EchoRouge "Erreur lors de l'enregistrement du noeud ${HAPY_SLV[${i}]} !"
if [[ $DBMODE == "sqlite" ]]
then
if [[ $(CreoleGet one_ha_server_index) == "0" ]]
then
sync_db ${host}
fi
fi
fi
sync_nodes
if [[ ${HAPY_HA} != "oui" ]]
wait_node_ok ${HAPY_SLV[${i}]}
if [[ ${?} -ne 0 ]]
then
EchoRouge "Erreur lors de l'enregistrement du noeud ${HAPY_SLV[${i}]} !"
fi
fi
done
if [ $master = 0 ]; then
init_ha_leader
fi
echo -e "\n"
EchoVert "Enregistrement des noeuds terminé"