Ecco a seguire qualche utile script.

Aggiornamento

Per aggiornare tutte le macchine virtuali:

   1 for id in $(vzlist | grep -o -e "^ *[[:digit:]]*"); do vzctl exec $id aptitude update ; done

E quindi (attenzione che può dare luogo a problemi la visualizzazione di diff nella console)

   1 for id in $(vzlist | grep -o -e "^ *[[:digit:]]*"); do echo -e "\n\n\n\n\n$id\n"; vzctl exec $id aptitude upgrade ; done

Creazione macchina virtuale

In questo caso lo script provvederà a:

e quindi rimarrà la sola configurazione della rete...

Scarica lo script vz-create.sh:

   1 #! /bin/bash
   2 # version 0.1.2
   3  
   4 function startquestion {
   5     echo "Script for creating a new container."
   6     echo "Do you need a LVM partition? (y/n)"
   7     read -e LVM
   8     echo "Which static IP? (10.0.1.123)"
   9     read -e IPc
  10     echo "Which container ID? (1123)"
  11     read -e ID
  12     echo "What container name?"
  13     read -e NAME
  14     mkdir /vz/private/$ID
  15     createCONT $LVM
  16 }
  17  
  18 function testLVNAME {
  19     if [ "$(lvs | grep VZ$ID$NAME)" != '' ]
  20       then
  21         echo "The logical volume name " "VZ$ID$NAME" "already exists, exit..."
  22         rmdir /vz/private/$ID
  23         exit
  24     fi
  25 }
  26  
  27 function createLVM {
  28     VGName="$(vgs | tail -n +2 | cut -d' ' -f3 )"
  29     echo "What is the partition lenght? (10G)"
  30     read -e LENGHT
  31     echo "On which VG? ( $VGName )"
  32     read -e VGNAME
  33     testLVNAME
  34     echo "lvcreate -L $LENGHT -n VZ$ID$NAME $VGNAME"
  35     lvcreate -L $LENGHT -n VZ$ID$NAME $VGNAME
  36     mkfs.ext4 /dev/$VGNAME/VZ$ID$NAME
  37     mount /dev/$VGNAME/VZ$ID$NAME /vz/private/$ID
  38 }
  39  
  40 function createCONT {
  41     case "$@" in
  42       y|Y)
  43         echo "Configuring LVM..."
  44         createLVM
  45       ;;
  46       *)
  47         echo "It seems you don't need any LV."
  48       ;;
  49     esac
  50     vzctl create $ID --private /vz/private/$ID/$ID --ostemplate debian-6.0-amd64-minimal \
  51                  --config basic --hostname $NAME --ipadd $IPc --name $NAME
  52 }
  53  
  54 startquestion

A questo punto ricordati di configurare il firewall!

MyWiki: OpenVZ/Script (last edited 2015-02-20 01:21:48 by risca)