Installation d'un serveur OpenVZ - ma version de l'histoire

Objectif: laisser des traces de ma propre expérience de la mise en place d'un serveur openvz et les soucis particuliers que j'ai rencontrés.

Installation

Fiche serveur

Services

openssh, openvz (noyau)

Sécurité

tripwire, iptables

|| Suivi/Outils || iproute, ntp, tcpdump, dig, mtr ||

Services

ça dépend

Sécurité

sudo, sXid, Logcheck, PortSentry

Suivi/Outils

Git, iproute, mtr, trafshow, tcpdump, dig

Schéma de partitionnement

Configuration réseau

Tâches supplémentaires à exécuter

Installation des logiciels

Sudo

# aptitude install sudo
# visudo -f /etc/sudoers
# /etc/sudoers
...
# User privilege specification
root            ALL=(ALL)       ALL
nacer   ALL=(ALL)       ALL

SSH

Suivre la démarche décrite ici.

Ajouter le compte d'administration (ici nacer) au groupe ssh:

$ sudo usermod -a -G ssh nacer

Copier ma clé publique sur le serveur, à partir d'une clé usb par exemple:

$ sudo mount -t vfat /dev/sda1 /mnt/
$ mkdir .ssh
$ cat /mnt/id_dsa.pub >> .ssh/authorized_keys
$ chmod u=rw,go=r .ssh/authorized_keys

Tester la configuration en essayant de se connecter à partir du poste d'administration.

tripwire

ntp (client)

$ sudo aptitude install ntp ntp-simple ntpdate

...
#Paramètres du serveur:
server 192.168.100.2
#Restreindre le type d'accès:
restrict default notrust nomodify nopeer
# configuration de l'hôte local
restrict 192.168.100.2
restrict 127.0.0.1
...

$ sudo ntpdate 192.168.100.2

$ sudo invoke-rc.d ntp restart

$ sudo hwclock --systohc

$ ntpdc -p
     remote           local      st poll reach  delay   offset    disp
=======================================================================
*192.168.100.2   10.45.0.242     14   64   77 0.00027  0.004907 0.43616

Logcheck

PortSentry

sXid

Git

Voir ici

GnuPG

Création d'une image OpenVZ

$ sudo aptitude install quota debootstrap

Il vaut mieux à ce stade avoir /var/lib/vz sur une partition à part

mkdir /var/lib/vz/template/debian-etch/
debootstrap --arch i386 etch /var/lib/vz/template/debian-etch/ http://miroir.cm.refer.org/debian/

# sudo vzctl set 240 --applyconfig vps.basic --save

# sudo sh -c 'echo "OSTEMPLATE=debian-4.0" >> /etc/vz/conf/240.conf'

# sudo vzctl set 240 --ipadd 10.45.0.240 --save

# sudo vzctl set 240 --nameserver 192.168.100.2 --save

# mkdir /var/lib/vz/private/240; cp -r /var/lib/vz/template/debian-etch/* /var/lib/vz/private/240/

# aptitude install bridge-utils

# lsmod | grep vzeth
vzethdev               12480  0
vzmon                  38152  5 vzethdev,vznetdev,vzrst,vzcpt
vzdev                   3620  4 vzethdev,vznetdev,vzmon,vzdquota

# modprobe vzethdev

CONFIG_CUSTOMIZED="yes"

VZHOSTBR="veth240.0" VETH_IP_ADDRESS=10.45.0.240

# /usr/sbin/vznetaddroute
# a script to bring up virtual network interfaces (veth's) in a VE

CONFIGFILE=/etc/vz/conf/$VEID.conf
. $CONFIGFILE
VZHOSTIF=`echo $NETIF |sed 's/^.*host_ifname=\(.*\),.*$/\1/g'`

if [ ! -n "$VETH_IP_ADDRESS" ]; then
   echo "According to $CONFIGFILE VE$VEID has no veth IPs configured."
   exit 1
fi

if [ ! -n "$VZHOSTIF" ]; then
   echo "According to $CONFIGFILE VE$VEID has no veth interface configured."
   exit 1
fi

for IP in $VETH_IP_ADDRESS; do
   echo "Adding interface $VZHOSTIF and route $IP for VE$VEID to CT0"
   /sbin/ifconfig $VZHOSTIF 0
   echo 1 > /proc/sys/net/ipv4/conf/$VZHOSTIF/proxy_arp
   echo 1 > /proc/sys/net/ipv4/conf/$VZHOSTIF/forwarding
   /sbin/ip route add $IP dev $VZHOSTIF
done

exit 0

# chmod 0500 /usr/sbin/vznetaddbr

Note: le script proposé ici, pris dans la documentation officielle de openvz à l'avantage de prendre en compte une partie de la configuration des interfaces réseaux impliquées, côté noeud physique.

# cat /etc/vz/vznet.conf
EXTERNAL_SCRIPT=/usr/local/sbin/vzaddbr

# vzctl set 240 --netif_add "eth0,00:01:23:45:67:8A,veth240.0,00:01:23:45:67:8B" --save 

# echo 0 > /proc/sys/net/ipv4/conf/eth1/forwarding
# echo 0 > /proc/sys/net/ipv4/conf/eth1/proxy_arp

# vzctl start 240
# vzctl enter 240
# cat /etc/network/interfaces
...
auto eth0
iface eth0 inet static
        address 10.45.0.240
        netmask 255.255.254.0
        up route add -net 10.45.0.0 netmask 255.255.254.0 dev eth0
        up route add default gw 10.45.0.254 dev eth0
...

# ifconfig eth0 0
# route add default gw 10.45.0.254 dev eth0

Configurer la table de routage sur l'hote physique:
# route add 10.45.0.240 dev veth240.0


 * Tâches post installation de base dans le serveur virtuel:
  * Edition des sources de paquets:
{{{
# cat /etc/apt/sources.list
deb http://miroir.cm.refer.org/debian/ etch main contrib non-free
deb http://miroir.cm.refer.org/debian-security/ etch/updates main contrib non-free

# aptitude update
# aptitude upgrade

# aptitude install ssh quota

# chmod 700 /root

#usermod -L root

# sed -i -e '/getty/d' /etc/inittab

# sed -i -e 's@\([[:space:]]\)\(/var/log/\)@\1-\2@' /etc/syslog.conf

# rm -f /etc/mtab
# ln -s /proc/mounts /etc/mtab

#update-rc.d -f klogd remove
#update-rc.d -f inetd remove

# aptitude clean

# exit

# sudo vzctl set 240 --ipdel all --save
# sudo vzctl stop 240

# cd /var/lib/vz/private/240
# sudo tar -zcf /var/lib/vz/template/cache/debian-4.0-i386-minimal.tar.gz .
# ls -lh /var/lib/vz/template/cache
total 56M
-rw-r--r-- 1 root root 56M 2008-05-30 19:54 debian-4.0-i386-minimal.tar.gz

Création d'une machine virtuelle OpenVZ

# sudo vzctl create 101 --ostemplate debian-4.0-i386-minimal

...
CONFIG_CUSTOMIZED="yes"
VZHOSTBR="veth101.0"
VETH_IP_ADDRESS=10.45.0.101

# vzctl set 101 --netif_add "eth0,20:01:23:45:67:8A,veth101.0,20:01:23:45:67:8B" --save 

virtual1:~# cat  /var/lib/vz/private/101/etc/network/interfaces
...
auto eth0                               # configuration de l'interface eth0
iface eth0 inet static
        address 10.45.0.101
        netmask 255.255.254.0
        up route add -net 10.45.0.0 netmask 255.255.254.0 dev eth0
        up route add default gw 10.45.0.254 dev eth0

auto venet0
iface venet0 inet static
        address 127.0.0.1
        netmask 255.255.255.255
        broadcast 0.0.0.0
        up route add -net 192.0.2.1 netmask 255.255.255.255 dev venet0
        #up route add default gw 192.0.2.1