Kickstart RHEL6

De wiki.nexiat.fr
Aller à la navigation Aller à la recherche
Fiche express
Domaine Installation automatisée (Kickstart / Anaconda)
Fichier ks.cfg, passé à l'installeur via ks=
Contexte RHEL/CentOS 6 sur VMware, installation non interactive
Voir aussi Chkconfig (services désactivés dans %post)

Kickstart permet d'automatiser entièrement l'installation d'un système RHEL/CentOS : partitionnement, réseau, choix des paquets et configuration post-installation, sans aucune intervention manuelle. Le fichier ks.cfg est fourni à Anaconda (l'installeur RHEL) au démarrage, généralement via un paramètre noyau — ks=http://serveur/ks.cfg, ks=cdrom:/ks.cfg ou ks=nfs:serveur:/chemin/ks.cfg selon la méthode de boot (PXE, CD, clé USB…).

Le modèle ci-dessous est taillé pour une VM VMware RHEL6 avec un disque de 20 Go (le partitionnement LVM ne fonctionnera pas tel quel sur un disque plus petit).

En-tête et configuration système

install
key --skip
url --url http://192.168.1.10/repo/rhel/x86_64/6/u4/os/
repo --name=repo2 --baseurl=http://192.168.1.10/repo/rhel/x86_64/6/u4/
lang en_US.UTF-8
keyboard fr-latin9

# Pas de terminal X pendant l'installation
skipx
# Nettoyer le MBR
zerombr yes
# Installation en mode texte
text
logging --level=info
reboot

# Services désactivés d'entrée (cf. chkconfig)
services --disabled=avahi-daemon,bluetooth,isdn,cups,mdmonitor,NetworkManager,pcscd,smartd,ip6tables,yum-updatesd,rpcidmapd,netfs,rpcgssd,gpm,firstboot,iscsid,iscsi

network --device eth0 --bootproto static --ip 192.168.1.30 --netmask 255.255.255.0 --gateway 192.168.1.1 --nameserver 192.168.1.2,192.168.1.3 --hostname=

rootpw --iscrypted $6$XXXXXXXXXXXXXXXX$XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
firewall --disabled
authconfig --enableshadow --passalgo=sha512 --enablefingerprint
selinux --permissive
timezone --utc Europe/Paris
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"

Le hash de rootpw --iscrypted se génère avec openssl passwd -6 (ou grub2-mkpasswd-sha512) — ne jamais coller un mot de passe en clair dans un fichier kickstart.

Partitionnement (LVM)

Disque de 20 Go : /boot en partition classique, tout le reste en LVM sur un seul groupe de volumes.

clearpart --all --initlabel
part /boot --fstype ext3 --size=100 --ondisk=sda
part pv.1 --size=100 --grow --ondisk=sda

volgroup vg_root pv.1
logvol swap    --fstype swap --name=lv_swap --vgname=vg_root --size=3072
logvol /       --fstype ext3 --name=lv_root --vgname=vg_root --size=8192
logvol /home   --fstype ext3 --name=lv_home --vgname=vg_root --size=1024
logvol /var/log --fstype ext3 --name=lv_log --vgname=vg_root --size=2048
logvol /tmp    --fstype ext3 --name=lv_tmp  --vgname=vg_root --size=2048

Paquets (%packages)

%packages
@base
@core
@system-tools

dhclient
device-mapper-multipath
nfs-utils
nmap
screen
ksh
gcc
xclock
openssl
openssl-devel
nrpe
nagios-plugins
ntp
sysstat
hdparm
strace
iptraf
postfix
ganglia-gmond
vim
mailx

# gain de place
-samba-client

Post-installation (%post)

Le script %post s'exécute une fois le système installé (encore chrooté sur la cible). Il désactive les services superflus, adapte le réseau et le SSH, puis configure le monitoring (NRPE, Ganglia), NTP, Postfix et les dépôts internes.

%post
# Désactivation d'un service oublié dans "services --disabled" ci-dessus
/sbin/chkconfig smartd off
echo "RUN_FIRSTBOOT=NO" > /etc/sysconfig/firstboot
cp -p /boot/grub/grub.conf /boot/grub/grub.conf.DIST

initfile=/etc/inittab
cp -f $initfile $initfile.ori

# Runlevel par défaut : 3 (pas de graphique)
sed -i 's/^id:5:/id:3:/g' $initfile

# Retirer le splash graphique du boot
ed /boot/grub/grub.conf <<EOF
g!hiddenmenu!s!!#hiddenmenu!gp
g! rhgb quiet!s!!!gp
g! quiet!s!!!g
wq
EOF

# Réseau : désactiver IPv6 sur l'interface
sed -i 's/IPV6INIT="yes"/IPV6INIT="no"/' /etc/sysconfig/network-scripts/ifcfg-eth0

# SSH : pas de résolution DNS inverse, pas de GSSAPI (accélère les connexions)
sed -i '/GSSAPIAuthentication/d' /etc/ssh/sshd_config
echo 'GSSAPIAuthentication no' >> /etc/ssh/sshd_config
sed -i '/UseDNS/d' /etc/ssh/sshd_config
echo 'UseDNS no' >> /etc/ssh/sshd_config

# NRPE : autoriser le serveur de supervision
sed -i 's/allowed_hosts=127.0.0.1/allowed_hosts=192.168.1.5/' /etc/nagios/nrpe.cfg
chkconfig nrpe on

# NTP : pointer sur le serveur de temps interne
sed -i '/^server/d' /etc/ntp.conf
echo 'server ntp.example.com' >> /etc/ntp.conf
chkconfig ntpd on

# Ganglia : nom d'hôte du groupe + canaux UDP dédiés (pas de multicast)
sed -i 's/ name = "unspecified"/ name = "host"/' /etc/ganglia/gmond.conf
sed -i '/mcast_join/d' /etc/ganglia/gmond.conf
sed -i '/udp_recv_channel {/,/}/d' /etc/ganglia/gmond.conf
sed -i '49i\udp_recv_channel { \n }\n' /etc/ganglia/gmond.conf
sed -i '/udp_send_channel {/,/}/d' /etc/ganglia/gmond.conf
sed -i '36i\udp_send_channel { \n  bind_hostname = yes\n  host = 192.168.1.6\n  port = 8649\n  ttl = 1\n}\n' /etc/ganglia/gmond.conf
chkconfig gmond on

# Postfix : relai sortant vers le smarthost
sed -i 's/#relayhost = \[an.ip.add.ress\]/relayhost = [smtp.example.com]/' /etc/postfix/main.cf
chkconfig --add postfix
chkconfig postfix on

# Dépôts internes
wget http://hostname/repo/files/rhel6u4-os.repo -O /etc/yum.repos.d/rhel-os.repo
rpm --import http://hostname/repo/rhel/x86_64/6/u4/os/RPM-GPG-KEY-redhat-release

# Nettoyage final (redondant avec "services --disabled" mais sans risque)
chkconfig --level 345 yum-updatesd off 2>/dev/null
chkconfig --level 345 atd off 2>/dev/null
chkconfig --level 345 anacron off 2>/dev/null
%end

Utilisation

# Au boot de l'installeur RHEL6 (menu PXE ou invite "boot:") :
linux ks=http://serveur/ks.cfg

# Depuis un CD/DVD contenant le fichier à la racine :
linux ks=cdrom:/ks.cfg

# Depuis un partage NFS :
linux ks=nfs:serveur:/chemin/ks.cfg

Anaconda applique le fichier de bout en bout : partitionnement, réseau, installation des paquets puis exécution du %post, jusqu'au reboot final — sans aucune question posée à l'écran.

Voir aussi

  • Chkconfig — commandes chkconfig utilisées dans le %post pour
 activer/désactiver les services