IT & + si affinités

Encore un blog de sysadmin … mais pas uniquement ;-)

Backup de VM Qemu/KVM

Ce script effectue une sauvegarde des VM (Configuration et disque), attention, les VMs sont killées si elles ne répondent pas à la commande d’arrêt dans le temps imparti. 

Note : il existe de meilleurs moyens de faire des sauvegarde, par exemple avec des snapshots si votre format de stockage le permet.

#!/bin/bash
# Name : backup_vm.sh
# Author : @Markhor75 
# Last Mod : 2014 10 20
# Backup VM (disk and config)

DESTINATION="/home/backup/vm"
DATE="$(date +"%Y%m%d_%H%M")"
RETENTIONDAYS="2"	# Days to keep backups 
KILLTIME=60		# Seconds to wait after excute shutdown VM and before destroying it
THISVMDEST=""
DOM=""
debug=1

if [ $debug -eq 1 ]; then
	echo "****************************************"
	echo "* Backup destination is "$DESTINATION
	echo "* Date is "$DATE
	echo "* Retention is "$RETENTIONDAYS" days"
	echo "* Killtime is "$KILLTIME"s"
	echo "* Debug is active"
	echo "****************************************"
fi	

for DOM in `virsh list --all | tail -n +3 | awk '{print $2}' | sort -u`
do 
        if [ $debug -eq 1 ]; then
		echo "*** Starting Backup $DOM ***"
	fi

	STATE=`virsh domstate $DOM`
	THISVMDEST=$DESTINATION"/"$DOM

	if [ ! -d $THISVMDEST ]; then
		if [ $debug -eq 1 ]; then 
			echo " Creating dir $THISVMDEST"
		fi
		mkdir $THISVMDEST
	fi

	virsh dumpxml $DOM >$THISVMDEST"/"$DATE"_"$DOM".xml"

	if [ "$STATE" == "running" ]; then
		if [ $debug -eq 1 ]; then
			echo " VM state is running, shutting down"
		fi
		virsh shutdown $DOM
		sleeping=0
		while [ $sleeping -lt $KILLTIME ]
		do
			if [ "`virsh domstate $DOM`" != "shut off" ]; then
				sleep 5
                        	sleeping=$(( $sleeping + 5))
			else
				sleeping=0
				break
			fi
		done

		#Destoying domain if not stopped after 60 seconds
		if [ "$sleeping" != "0" ]; then
                	if [ $debug -eq 1 ]; then
                        	echo " VM always running after $KILLTIME s, Destoying it"
                	fi
			virsh destroy $DOM
		fi
		
	fi
	
	for DISK in `virsh dumpxml $DOM |grep "source file" |cut -d "'" -f 2`
	do
		DISKNAME=`echo $DISK |awk -F"/" '{print $NF}'`
		if [ $debug -eq 1 ]; then
			echo " making cp $DISK $THISVMDEST\"/\"$DATE\"_\"$DISKNAME"
		fi
		#cp $DISK $THISVMDEST"/"$DATE"_"$DISKNAME
	done

        if [ "$STATE" == "running" ]; then
		if [ $debug -eq 1 ]; then
			echo " VM restarting"
		fi
		virsh start $DOM
	fi
        if [ $debug -eq 1 ]; then
                echo "*** Ending backup $DOM ***"
        fi
done

if [ $debug -eq 1 ]; then
	echo "Deleting old backups"
fi

find $DESTINATION -maxdepth 1 -ctime +$RETENTIONDAYS -type f -exec rm {} \;

if [ $debug -eq 1 ]; then
        echo "Script ending"
	echo""
fi

 

Configuration client léger (Raspberry Pi) RDP/TSE

Procédure pour installer un Raspberri Pi en client léger RDP/TSE 

 

Note : cet article à été rédigé il y a plusieurs années, certaines commandes ont pu changer depuis, particulièrement tout ce qui touche à l’inscription dans le domaine.

 

Créer une Sdcard avec Raspbian wheezy

(télécharger image iso et utiliser dd sous linux ou Win32DiskImager sous Windows)

 

Etapes initiales :

 

Démarrer sur le raspberry Pi

Sur l’utilitaire de configuration allez sur

« 1 Expand Filesystem »

« 4 Internationalisation »

« I1 Change Locale » supprimer en_GB, ajouter fr_FR.UTF8, puis inscrivez le par défaut.

« I2 Change Timezone » Europe/Paris

« I3 Change Keyboard Layaout » Généric 105 Key / Other / French / French/…/ activer activer option Ctrl + Alt + Backspace pour killer le serveur X.

« 3 Enable boot to Desktop/Scratch » => Desktop login as user pi.

« 7 Overclock » => 900MHz

« 8 Advanced Options »

« A2 Hostname » : attribuer un hostname

Terminer et rebooter

 

 

Depuis un terminal administrateur en GUI :

  • changer password aux users root et pi
  • optionnel : assigner une IP fixe
  • exécuter ce script de personnalisation :
#!/bin/bash
cd /root
rm /root/.bashrc
wget ftp://192.168.1.5/Scripts/workstation/raspberry/.bashrc
aptitude update
aptitude -y upgrade 
aptitude -y install vim
cd /etc/vim/
rm vimrc
wget ftp://192.168.1.5/Scripts/workstation/raspberry/vimrc
aptitude -y install sendmail ntpdate mtr mlocate rdesktop
update-rc.d ntp remove
aptitude -y remove ntp
cd /etc/
rm aliases
wget ftp://192.168.1.5/Scripts/workstation/raspberry/aliases 
cd /etc/cron.daily/
wget ftp://192.168.1.5/Scripts/workstation/raspberry/synchrotime
chmod +x synchrotime

#desktop wallpaper
cd /usr/share/raspberrypi-artwork/
wget ftp://192.168.1.5/Scripts/workstation/raspberry/raspberry-pi-logo.png

#icones des raccourcis TSE
cd /media/
wget ftp://192.168.1.5/Scripts/workstation/raspberry/icons/computer.png

#Desactivation auto-login
sed -i -e "s/autologin-user=pi/#autologin-user=pi/g" /etc/lightdm/lightdm.conf
cd ~
/bin/bash
  • Rebooter

 

Entrée dans le domaine :

  • Exécuter le script :
#!/bin/bash

echo "Installation des packages"
apt-get -y install samba winbind samba-common-bin krb5-user libpam-gnome-keyring libpam-mount libpam-script

echo "Remplacement des fichiers de configuration"
mkdir /root/backup_acme
cd /etc

# hosts
mv  /etc/hosts /root/backup_acme/
wget ftp://192.168.1.5/Scripts/workstation/raspberry/hosts
sed -i -e "s/%HOSTNAME%/"$HOSTNAME"/g" /etc/hosts

# resolv.conf
mv  /etc/resolv.conf /root/backup_acme/
wget ftp://192.168.1.5/Scripts/workstation/raspberry/resolv.conf
chattr +i /etc/resolv.conf

# nssswitch.conf
mv /etc/nsswitch.conf /root/backup_acme/
wget ftp://192.168.1.5/Scripts/workstation/raspberry/nsswitch.conf

# krb5.conf
rm /etc/krb5.conf
wget ftp://192.168.1.5/Scripts/workstation/raspberry/krb5.conf

# smb.conf
cd /etc/samba/
mv /etc/samba/smb.conf /root/backup_acme/
wget ftp://192.168.1.5/Scripts/workstation/raspberry/smb.conf
sed -i -e "s/%HOSTNAME%/"$HOSTNAME"/g" /etc/samba/smb.conf

# ConsoleKit.conf
cd /etc/dbus-1/system.d/
wget ftp://192.168.1.5/Scripts/workstation/raspberry/ConsoleKit.conf
chmod 644 /etc/dbus-1/system.d/ConsoleKit.conf
chown root:root /etc/dbus-1/system.d/ConsoleKit.conf

#pam config files
cd /etc/pam.d/
mv common-account /root/backup_acme/ && wget ftp://192.168.1.5/Scripts/workstation/raspberry/pam/common-account
mv common-auth /root/backup_acme/ && wget ftp://192.168.1.5/Scripts/workstation/raspberry/pam/common-auth
mv common-password /root/backup_acme/ && wget ftp://192.168.1.5/Scripts/workstation/raspberry/pam/common-password
mv common-session /root/backup_acme/ && wget ftp://192.168.1.5/Scripts/workstation/raspberry/pam/common-session
mv lightdm /root/backup_acme/ && wget ftp://192.168.1.5/Scripts/workstation/raspberry/pam/lightdm

#pam scripts
cd /usr/share/libpam-script/
wget ftp://192.168.1.5/Scripts/workstation/raspberry/pam/pam_script_ses_open
chmod +x pam_script_ses_open
wget ftp://192.168.1.5/Scripts/workstation/raspberry/pam/pam_script_auth
chmod +x pam_script_auth

mkdir /home/ACME
chmod 777 /home/ACME
mkdir /home/liens
cd /home/liens

wget ftp://192.168.1.5/Scripts/workstation/raspberry/liens/Bureautique.desktop
chmod 666 *

cd ~

echo "Ultimes etapes"
ntpdate DC01.ACME.CORP
/etc/init.d/winbind stop
/etc/init.d/samba stop
/etc/init.d/samba start
/etc/init.d/winbind start
echo "il vous reste à éxecuter : net ads join -U Administrateur -S DC01.acme.corp"

 

Note : le fichier de config de krb5.conf  sera remplacé après l’installation.

  • rebooter
  • exectuer la commande : net ads join -U Administrateur -S dc01.acme.corp
  • rebooter

 

Note : à la première connexion d’un utilisateur, les raccourcis ne sont pas copiés, il faut se déconnecter / reconnecter pour avoir les icônes.

 

Fichier resolv.conf :

domain acme.corp
search acme.corp
nameserver 192.168.1.3
nameserver 192.168.2.8

Principales options smb.conf :

[global]
 workgroup = ACME
 netbios name = %HOSTNAME%
 security = ADS
 preferred master = no 	
 disable spoolss = Yes
 show add printer wizard = No
 idmap uid = 15000-20000
 idmap gid = 15000-20000
 winbind separator = + 	
 winbind use default domain = Yes 	
 template shell = /bin/bash 	
 use sendfile = Yes 	
 realm = acme.corp

principales options krb5.conf :

[libdefaults]
 default_realm = acme.corp

[realms]
 acme.corp = {
  kdc = dc01
  kdc = dc02
  admin_server = dc01
 }

[login]
 krb4_convert = true
 krb4_get_tickets = false

Fichier nsswitch.conf
passwd:         files winbind
group:          files winbind
shadow:         files winbind

hosts:          files dns winbind
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

 

Notes pb dropped paquets

Quelques notes en vrac sur la gestion des paquets « dropped »

liste des réglages à effectuer :

https://access.redhat.com/sites/default/files/attachments/20150325_network_performance_tuning.pdf

 

Précisions sur certains paramètres :

 

Si l’interface eth0 indique des paquets « dropped », chercher la cause dans les compteurs d’erreurs :  /sys/class/net/eth0/statistics/

ou avec la commande : ethtool -S eth0

 

Pour aller plus loin :

Afficher les valeurs courantes : ethtool -g eth0

La valeur par défaut est 255, les cartes récentes permettent d’augmenter cette valeur.

Modifier la valeur pour une interface : ethtool -G eth0 rx 512

Information sur les buffers d’ émission/réception : http://www.itechlounge.net/2015/05/linux-how-to-tune-up-receive-tx-and-transmit-rx-buffers-on-network-interface/

 

 

Divers :

Vérifier que les interruptions sont réparties sur les processeurs :

egrep « CPU0|eth0 » /proc/interrupts

Si toutes les interruptions sont sur CPU0, installer irqbalance