From 78a27b4fdddeb0de157a2a4a4422f7f16b4d9455 Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Wed, 6 Feb 2019 14:14:03 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Ajout=20du=20support=20OpenNebula=20HA=20da?= =?UTF-8?q?ns=20H=C3=A2py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- diagnose/04-virtualisation | 2 +- dicos/29_one-master.xml | 111 ++++++++++++++++++++++-- postservice/30-one-mng | 71 +++++++++++----- postservice/31-one-netmng | 8 ++ postservice/99-z-ha | 15 ++++ posttemplate/90-one-db | 83 ++++++++++++------ preservice/30-one-auth | 7 ++ preservice/31-one-ha | 26 ++++++ scripts/onehost_create_all | 170 +++++++++++++++++++++++++++++-------- tmpl/60-one | 5 ++ tmpl/oned-ha-mysql.conf | 2 + tmpl/oned.conf | 42 +++++---- tmpl/sched.conf | 110 ++++++++++++++++++++++++ 13 files changed, 548 insertions(+), 104 deletions(-) create mode 100644 postservice/99-z-ha create mode 100755 preservice/31-one-ha create mode 100644 tmpl/60-one create mode 100644 tmpl/oned-ha-mysql.conf create mode 100644 tmpl/sched.conf diff --git a/diagnose/04-virtualisation b/diagnose/04-virtualisation index 58fbb0d..dfc15a5 100755 --- a/diagnose/04-virtualisation +++ b/diagnose/04-virtualisation @@ -80,7 +80,7 @@ then echo "" else for VM in $VMs ; do - NAME=$( one "onevm show $VM" | grep 'NAME' | cut -d: -f2 ) + NAME=$( one "onevm show $VM" | grep '^NAME' | cut -d: -f2 ) STAT=$(one "onevm show $VM" | grep '^STATE' | cut -d: -f2 | tr -d ' ' ) printf ". %${len_pf}s => " "$NAME" eOneStatus "$STAT" diff --git a/dicos/29_one-master.xml b/dicos/29_one-master.xml index 0e6bdd0..7657de7 100644 --- a/dicos/29_one-master.xml +++ b/dicos/29_one-master.xml @@ -4,10 +4,13 @@ + + opennebula + opennebula-scheduler sshd @@ -16,6 +19,19 @@ adresse_ip_eth0 + + + port_sunstone + vnc_proxy_port_sunstone + + + + 2633 + + + + one_nodes + @@ -30,6 +46,25 @@ default + + + + sqlite + + + + 3306 + + + onedb + + + one + + + 50 + + @@ -106,9 +146,10 @@ + Configuration de la base de données Configuration des réseaux de l'orchestrateur Configuration de l'orchestrateur - Configuration des nœuds de virtualisation + Configuration des nœuds de virtualisation @@ -121,6 +162,10 @@ vnet_pilote + + ['sqlite','mysql'] + + ['qxl','vga','std','cirrus'] False @@ -151,11 +196,60 @@ arp_cache_poisoning + + sqlite + one_database_host + one_database_port + one_database_name + one_database_user + one_database_pass + one_database_connections + + + + ['0','1','2','3','4'] + + + eth + one_node_int + + non one_nodes - node_ip + one_node_int + one_node_int_name + + activer_one_ha + + + oui + activer_multinode + + + + non + one_ha_server_index + one_vip + one_vip_mask + sunstone_xmlrpc + one_ha + + + + adresse_netmask_eth0 + + + + one_vip + + + one_vip + + + one_vip + vnet_range_start @@ -175,10 +269,6 @@ l2_vnet_vlan_trunk - - node_ip - - ['internet','admin','pedago','dmzpub','dmzpriv','wifi'] False @@ -286,5 +376,8 @@ Version de l'ISO EOLE à télécharger lors de l'initialisation Réseau de type IPv4 (niveau 3 du modèle OSI) Réseau de type ethernet (niveau 2 du modèle OSI) + Le leader à l'index 0, les followers commencent à 1 + Active la possibilité d'intégrer Hâpy dans une grappe de haute disponibilité OpenNebula + Adresse IP virtuelle (VIP) utilisée pour joindre le "Leader" de la grappe, les usagés utiliseront cette IP pour contacter la grappe diff --git a/postservice/30-one-mng b/postservice/30-one-mng index 361667e..93526f0 100755 --- a/postservice/30-one-mng +++ b/postservice/30-one-mng @@ -69,6 +69,21 @@ function check_host() return ${res} } +# Fix host creation error from 5.6.1 with sync methode rsync +function sync_host() +{ + CMD="onehost" + OPT="sync -f --rsync" + AUTH=$(get_one_auth) + res=$(su - oneadmin -c "${CMD} ${OPT} --user ${AUTH%:*} --password ${AUTH#*:}") + if [[ ${?} -ne 0 ]] + then + error "Hosts sync failed" + else + echo "Hosts sync OK" + fi +} + function manage_host() { NAME=${1} @@ -185,9 +200,9 @@ function attach_host() { HOST=${1} CLST=${2} - # ref https://dev-eole.ac-dijon.fr/issues/16797 + # ref https://dev-eole.ac-dijon.fr/issues/16797 #CLST_ID=$(get_cluster_id_by_name ${CLST}) - CLST_ID=0 + CLST_ID=0 HST_ID=$(get_host_id_by_name ${HOST}) AUTH=$(get_one_auth) CMD="onecluster" @@ -249,10 +264,11 @@ function create_datastore() { ds_type="${1}" ds_name="${2}" - # ref https://dev-eole.ac-dijon.fr/issues/16797 + local ha=$(CreoleGet activer_one_ha) + # ref https://dev-eole.ac-dijon.fr/issues/16797 #ds_cluster="${3}" - if [[ $(CreoleGet activer_multinode 2>&1) == 'oui' ]] + if [[ $(CreoleGet activer_multinode 2>&1) == 'oui' ]] && [[ ${ha} == "non" ]] then SYS_TM_MAD='ssh' ISO_TM_MAD='ssh' @@ -300,7 +316,7 @@ __EOF__ RUN=$(${cmd} ${opt}) if [[ ${?} -eq 0 ]] then - # ref https://dev-eole.ac-dijon.fr/issues/16797 + # ref https://dev-eole.ac-dijon.fr/issues/16797 #attach_ds_to_cluster ${ds_name} ${ds_cluster} rm ${TMPL_FILE} return 0 @@ -316,13 +332,14 @@ function update_datastore() local cmd="onedatastore" local opt="show" local multinode=$(CreoleGet activer_multinode 2>&1) + local ha=$(CreoleGet activer_one_ha) ds_type="" ds_mad="" ds_name="" TMPL_FILE=$(mktemp) - if [[ ${multinode} == 'oui' ]] + if [[ ${multinode} == 'oui' ]] && [[ ${ha} == "non" ]] then SYS_TM_MAD='ssh' ISO_TM_MAD='ssh' @@ -384,11 +401,11 @@ __EOF__ function manage_datastores() { - # ref https://dev-eole.ac-dijon.fr/issues/16797 + # ref https://dev-eole.ac-dijon.fr/issues/16797 #cluster=${1} AUTH=$(get_one_auth) - # ref https://dev-eole.ac-dijon.fr/issues/16797 + # ref https://dev-eole.ac-dijon.fr/issues/16797 #SYSTEM_DS="$(CreoleGet 'one_ds_system_prefix')${cluster}" SYSTEM_DS="$(CreoleGet 'one_ds_system_prefix')default" ISO_DS=$(CreoleGet 'one_ds_iso_name') @@ -398,7 +415,7 @@ function manage_datastores() sid=$(get_ds_id_by_name ${SYSTEM_DS}) if [[ ${sid} = "ERR" ]] then - # ref https://dev-eole.ac-dijon.fr/issues/16797 + # ref https://dev-eole.ac-dijon.fr/issues/16797 #create_datastore "SYSTEM" "${SYSTEM_DS}" "${cluster}" create_datastore "SYSTEM" "${SYSTEM_DS}" else @@ -408,7 +425,7 @@ function manage_datastores() imgid=$(get_ds_id_by_name ${IMAGE_DS}) if [[ ${imgid} = "ERR" ]] then - # ref https://dev-eole.ac-dijon.fr/issues/16797 + # ref https://dev-eole.ac-dijon.fr/issues/16797 #create_datastore "IMAGE" "${IMAGE_DS}" "${cluster}" create_datastore "IMAGE" "${IMAGE_DS}" else @@ -418,7 +435,7 @@ function manage_datastores() isoid=$(get_ds_id_by_name ${ISO_DS}) if [[ ${isoid} = "ERR" ]] then - # ref https://dev-eole.ac-dijon.fr/issues/16797 + # ref https://dev-eole.ac-dijon.fr/issues/16797 #create_datastore "ISO" "${ISO_DS}" "${cluster}" create_datastore "ISO" "${ISO_DS}" else @@ -430,32 +447,48 @@ function manage_datastores() function main() { wait_true_retcode "Wait for oned to be started" "onecluster show 0 > /dev/null" + if [ "$(CreoleGet activer_one_ha)" = "oui" ]; then + if [ "$(CreoleGet one_ha_server_index)" != "0" ]; then + # ne pas faire sur les followers + return + fi + fi # # Rename default cluster clst_name=$(CreoleGet one_cluster_name) rename_default_cluster "${clst_name}" - # Wait 4 seconds for service (ref #16848) - sleep 4 + # Wait 4 seconds for service (ref #16848) + sleep 4 # # Creating Host # - if [[ $(CreoleGet eole_module non) != 'hapy-master' ]] - then - host=$(CreoleGet nom_machine) - manage_host ${host} - fi + if [ ! "$(CreoleGet activer_one_ha)" = "oui" ]; then + if [[ $(CreoleGet eole_module non) != 'hapy-master' ]] + then + host=$(CreoleGet nom_machine) + manage_host ${host} + fi + fi # # Attaching Host to the Cluster # attach_host ${host} "${clst_name}" + # + # Force host synchronisation + # + sync_host + # # Création des Datastores # manage_datastores "${clst_name}" + } -main +main $@ + +exit 0 diff --git a/postservice/31-one-netmng b/postservice/31-one-netmng index 4fd5ec6..abb2a40 100755 --- a/postservice/31-one-netmng +++ b/postservice/31-one-netmng @@ -303,6 +303,14 @@ def main(): logger.debug(u"Configure OpenNebula networks") client = CreoleClient() + + mode_ha = client.get_creole('activer_one_ha') + if mode_ha == "oui": + indx = client.get_creole('one_ha_server_index') + if indx != 0: + # Mode HA is on and we are not in the Leader + exit(0) + one_client = OneClient('oneadmin') networks = [] cluster = client.get_creole('one_cluster_name') diff --git a/postservice/99-z-ha b/postservice/99-z-ha new file mode 100644 index 0000000..88b70d4 --- /dev/null +++ b/postservice/99-z-ha @@ -0,0 +1,15 @@ +#!/bin/bash + +ha=$(CreoleGet activer_one_ha non) +if [[ ${ha} == "oui" ]] +then + indx=$(CreoleGet one_ha_server_index) +else + indx="0" +fi + +if [[ ${1} == "instance" ]] && [[ ${indx} == "0" ]] +then + /usr/share/eole/sbin/onehost_create_all +fi +exit 0 diff --git a/posttemplate/90-one-db b/posttemplate/90-one-db index dd2963a..213d001 100644 --- a/posttemplate/90-one-db +++ b/posttemplate/90-one-db @@ -6,44 +6,79 @@ # . /usr/lib/eole/ihm.sh +script="$1" function clean_backups() { - file=${1} - bcks=($(ls ${file}_*)) - nbbck=$(expr ${#bcks[@]} - 2) + file=${1} + ls ${file}_* > /dev/null 2>&1 + if [ $? = 0 ]; then + bcks=($(ls ${file}_*)) + nbbck=$(expr ${#bcks[@]} - 2) - if [[ ${nbbck} -gt 1 ]] - then - EchoGras "Cleaning up old backups !" - for idx in `seq 0 ${nbbck}` - do - rm -f ${bcks[${idx}]} - done - fi + if [[ ${nbbck} -gt 1 ]] + then + EchoGras "Cleaning up old backups !" + for idx in `seq 0 ${nbbck}` + do + rm -f ${bcks[${idx}]} + done + fi + fi } function updateDB() { - local dbfile='/var/lib/one/one.db' - local cmd="onedb" - local res=0 + local dbfile='/var/lib/one/one.db' + local cmd="onedb" + local res=0 - if [[ -f ${dbfile} ]] - then - $cmd upgrade -f -s ${dbfile} - res=${?} - clean_backups ${dbfile} - return ${res} - else - return 0 - fi + if [[ -f ${dbfile} ]] + then + if [ $(CreoleGet one_database_type) = "mysql" ]; then + if [ $(CreoleGet one_ha_server_index 0) = "0" ]; then + HOST=$(CreoleGet one_database_host) + DB=$(CreoleGet one_database_name) + USER=$(CreoleGet one_database_user) + PASS=$(CreoleGet one_database_pass) + $cmd upgrade -f -u $USER -p $PASS -d $DB -S $HOST + fi + else + $cmd upgrade -f -s ${dbfile} + fi + res=${?} + clean_backups ${dbfile} + return ${res} + else + return 0 + fi } +function to_mysql() { + if [ "$script" = 'instance' ] && [ $(CreoleGet one_database_type) = "mysql" ] && [ $(CreoleGet one_ha_server_index 0) = "0" ]; then + Question_ouinon "Voulez-vous migrer de SQLite à Mysql ?" "True" "oui" "warn" + rep=$(echo "$?") + if [ "$rep" == "0" ]; then + # do not recover db on follower + HOST=$(CreoleGet one_database_host) + DB=$(CreoleGet one_database_name) + USER=$(CreoleGet one_database_user) + PASS=$(CreoleGet one_database_pass) + cp -a /etc/one/oned.conf /etc/one/oned.conf.ori + # HA ne doit pas être activer pour la migration + CreoleCat -s /usr/share/eole/creole/distrib/oned-ha-mysql.conf -o /etc/one/oned.conf + oned -i + onedb sqlite2mysql -s /var/lib/one/one.db -u $USER -p $PASS -d $DB -S $HOST + cp -a /etc/one/oned.conf.ori /etc/one/oned.conf + fi + fi +} + +echo +to_mysql echo EchoGras "Mise à jour de la base de données ONE" echo updateDB -echo exit ${?} diff --git a/preservice/30-one-auth b/preservice/30-one-auth index dc5ddb0..9722a18 100644 --- a/preservice/30-one-auth +++ b/preservice/30-one-auth @@ -8,3 +8,10 @@ if [ -z "${auth_mode}" ]; then else ln -s /var/lib/one/remotes/auth/{${auth_mode},default} fi + +# creation de la base /var/lib/one/one.db +if [ ! -e /var/lib/one/one.db ]; then + systemctl daemon-reload + systemctl start opennebula.service +fi +exit 0 diff --git a/preservice/31-one-ha b/preservice/31-one-ha new file mode 100755 index 0000000..d19a938 --- /dev/null +++ b/preservice/31-one-ha @@ -0,0 +1,26 @@ +#!/bin/bash + +HA=$(CreoleGet activer_one_ha non) +DBMODE=$(CreoleGet one_database_type "none") +LEADER_DB_FILE="/var/lib/one/one.db.leader" +DBFILE="/var/lib/one/one.db" + +# If HA is enabled and a leader database file is present +# we restore the leader database. + +if [[ ${HA} == "oui" ]] && [[ ${DBMODE} == "sqlite" ]] +then + if [[ -f ${LEADER_DB_FILE} ]] + then + if [[ $(CreoleGet one_ha_server_index) != "0" ]] + then + onedb restore --sqlite ${DBFILE} ${LEADER_DB_FILE} -f + if [[ $? -eq 0 ]] + then + rm ${LEADER_DB_FILE} + exit ${?} + fi + fi + fi +fi +exit 0 diff --git a/scripts/onehost_create_all b/scripts/onehost_create_all index 44961d6..a3ac59e 100755 --- a/scripts/onehost_create_all +++ b/scripts/onehost_create_all @@ -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 < /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 <> ~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é" diff --git a/tmpl/60-one b/tmpl/60-one new file mode 100644 index 0000000..24d4dfc --- /dev/null +++ b/tmpl/60-one @@ -0,0 +1,5 @@ +#!/bin/bash + +%for %%host in %%one_nodes +/sbin/iptables -A eth%%{one_node_int}-root -s %%host -p tcp --syn -j ACCEPT +%end for diff --git a/tmpl/oned-ha-mysql.conf b/tmpl/oned-ha-mysql.conf new file mode 100644 index 0000000..17b618c --- /dev/null +++ b/tmpl/oned-ha-mysql.conf @@ -0,0 +1,2 @@ +%set global %%activer_one_ha='non' +%include '/var/lib/creole/oned.conf' diff --git a/tmpl/oned.conf b/tmpl/oned.conf index 4ae093f..ed0b407 100644 --- a/tmpl/oned.conf +++ b/tmpl/oned.conf @@ -78,18 +78,22 @@ SCRIPTS_REMOTE_DIR=/var/tmp/one PORT = 2633 +%if %%activer_one_ha == 'non' LISTEN_ADDRESS = "127.0.0.1" +%end if +%if %%one_database_type == "sqlite" DB = [ BACKEND = "sqlite" ] - +%else # Sample configuration for MySQL -# DB = [ BACKEND = "mysql", -# SERVER = "localhost", -# PORT = 0, -# USER = "oneadmin", -# PASSWD = "oneadmin", -# DB_NAME = "opennebula", -# CONNECTIONS = 50 ] +DB = [ BACKEND = "mysql", + SERVER = "%%one_database_host", + PORT = %%one_database_port, + USER = "%%one_database_user", + PASSWD = "%%one_database_pass", + DB_NAME = "%%one_database_name", + CONNECTIONS = %%one_database_connections ] +%end if VNC_PORTS = [ START = 5900 @@ -151,7 +155,11 @@ VNC_PORTS = [ FEDERATION = [ MODE = "STANDALONE", ZONE_ID = 0, +%if %%activer_one_ha == 'oui' + SERVER_ID = %%one_ha_server_index, +%else SERVER_ID = -1, +%end if MASTER_ONED = "" ] @@ -164,17 +172,19 @@ RAFT = [ XMLRPC_TIMEOUT_MS = 450 ] +%if %%activer_one_ha == 'oui' # Executed when a server transits from follower->leader -# RAFT_LEADER_HOOK = [ -# COMMAND = "raft/vip.sh", -# ARGUMENTS = "leader " -# ] +RAFT_LEADER_HOOK = [ + COMMAND = "raft/vip.sh", + ARGUMENTS = "leader %%nom_zone_eth0 %%one_vip/%%calc_classe(%%one_vip_mask)" +] # Executed when a server transits from leader->follower -# RAFT_FOLLOWER_HOOK = [ -# COMMAND = "raft/vip.sh", -# ARGUMENTS = "follower " -# ] +RAFT_FOLLOWER_HOOK = [ + COMMAND = "raft/vip.sh", + ARGUMENTS = "follower %%nom_zone_eth0 %%one_vip/%%calc_classe(%%one_vip_mask)" +] +%end if #******************************************************************************* # Default showback cost diff --git a/tmpl/sched.conf b/tmpl/sched.conf new file mode 100644 index 0000000..938e044 --- /dev/null +++ b/tmpl/sched.conf @@ -0,0 +1,110 @@ +#******************************************************************************* +# OpenNebula Configuration file +#******************************************************************************* + +#******************************************************************************* +# Daemon configuration attributes +#------------------------------------------------------------------------------- +# MESSAGE_SIZE: Buffer size in bytes for XML-RPC responses. +# +# XMLRPC_TIMEOUT: Seconds to timeout XML-RPC calls to oned +# +# ONE_XMLRPC: URL to connect to the OpenNebula daemon (oned) +# +# SCHED_INTERVAL: Seconds between two scheduling actions +# +# MAX_VM: Maximum number of Virtual Machines scheduled in each scheduling +# action. Use 0 to schedule all pending VMs each time. +# +# MAX_DISPATCH: Maximum number of Virtual Machines actually dispatched to a +# host in each scheduling action +# +# MAX_HOST: Maximum number of Virtual Machines dispatched to a given host in +# each scheduling action +# +# LIVE_RESCHEDS: Perform live (1) or cold migrations (0) when rescheduling a VM +# +# DEFAULT_SCHED: Definition of the default scheduling algorithm +# - policy: +# 0 = Packing. Heuristic that minimizes the number of hosts in use by +# packing the VMs in the hosts to reduce VM fragmentation +# 1 = Striping. Heuristic that tries to maximize resources available for +# the VMs by spreading the VMs in the hosts +# 2 = Load-aware. Heuristic that tries to maximize resources available for +# the VMs by using those nodes with less load +# 3 = Custom. +# - rank: Custom arithmetic expression to rank suitable hosts based in their +# attributes +# 4 = Fixed. Hosts will be ranked according to the PRIORITY attribute found +# in the Host or Cluster template. +# +# DEFAULT_DS_SCHED: Definition of the default storage scheduling algorithm +# - policy: +# 0 = Packing. Tries to optimize storage usage by selecting the DS with +# less free space +# 1 = Striping. Tries to optimize I/O by distributing the VMs across +# datastores. +# 2 = Custom. +# - rank: Custom arithmetic exprission to rank suitable datastores based on +# their attributes +# 3 = Fixed. Datastores will be ranked according to the PRIORITY attribute +# found in the Datastore template. +# +# +# LOG: Configuration for the logging system +# - system: defines the logging system: +# file to log in the sched.log file +# syslog to use the syslog facilities +# - debug_level: +# 0 = ERROR +# 1 = WARNING +# 2 = INFO +# 3 = DEBUG Includes general scheduling information (default) +# 4 = DDEBUG Includes time taken for each step +# 5 = DDDEBUG Includes detailed information about the scheduling +# decision, such as VM requirements, Host ranking for +# each VM, etc. This will impact the performance +# +# MEMORY_SYSTEM_DS_SCALE: This factor scales the VM usage of the system DS with +# the memory size. This factor can be use to make the scheduler consider the +# overhead of checkpoint files: +# system_ds_usage = system_ds_usage + memory_system_ds_scale * memory +# +#******************************************************************************* + +MESSAGE_SIZE = 1073741824 +TIMEOUT = 60 + +%if %%activer_one_ha == 'oui' +ONE_XMLRPC = "http://%%adresse_ip_eth0:2633/RPC2" +%else +ONE_XMLRPC = "http://localhost:2633/RPC2" +%end if + +SCHED_INTERVAL = 30 + +MAX_VM = 5000 +MAX_DISPATCH = 30 +MAX_HOST = 1 + +LIVE_RESCHEDS = 0 + +MEMORY_SYSTEM_DS_SCALE = 0 + +DEFAULT_SCHED = [ + policy = 1 +] + +DEFAULT_DS_SCHED = [ + policy = 1 +] + +#DEFAULT_SCHED = [ +# policy = 3, +# rank = "- (RUNNING_VMS * 50 + FREE_CPU)" +#] + +LOG = [ + system = "file", + debug_level = 3 +] From dcc8eeeecee5c5824e31c73b5ddf04590714f606 Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Wed, 13 Mar 2019 12:12:29 +0100 Subject: [PATCH 2/2] Correction d'une erreur de syntaxe --- scripts/onehost_create_all | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/onehost_create_all b/scripts/onehost_create_all index a3ac59e..fe2ec74 100755 --- a/scripts/onehost_create_all +++ b/scripts/onehost_create_all @@ -213,6 +213,7 @@ for host in ${HAPY_SLV}; do fi sync_nodes if [[ ${HAPY_HA} != "oui" ]] + then wait_node_ok ${HAPY_SLV[${i}]} if [[ ${?} -ne 0 ]] then