Goal: Add SOFT and HARD memory limits to all vserver guests

Copy this script to your box, and run it! #!/bin/sh # # set-vserver-mem-limits.sh # quick way to set MEMORY limits for Vservers. # also, sets 'flags' to show vserer RAM and LOAD when in vserver. # # Fri Jun 25 15:13:49 PDT 2010, rudy # # impose a 1GB limit to anyone without a limit. MEM_PAGES_HARD=250000 MEM_PAGES_SOFT=225000 if ! cd /etc/vservers 2> /dev/null ; then echo "Hmmm... is this machine ready for vservers?" exit; fi for D in `ls`; do if [ -d $D ]; then if [ ! -d $D/rlimits ]; then mkdir $D/rlimits; fi if [ ! -f $D/rlimits/rss.hard ]; then echo "Adding limits for $D" echo $MEM_PAGES_HARD > $D/rlimits/rss.hard; echo $MEM_PAGES_SOFT > $D/rlimits/rss.soft; fi if [ ! -f $D/flags ]; then # Make 'top' show the limits set above. # Freak out users. :) echo "Setting up flags for $D" echo "VIRT_MEM" > $D/flags echo "VIRT_LOAD" >> $D/flags fi fi done Restart your vservers and they are ready to go!

Ain't this easy?

Setting up a new VServer? Here are some handy packages:
apt-get install locales
aptitude install -R openssh-server
apt-get install rsync 
aptitude install -R sudo
apt-get install vim
  • locales -- eliminate "perl: warning: Setting locale failed." errors
  • openssh-server -- need to connect (and I don't want x11, so use -R)
  • rsync -- everyone needs that to move into a new VPS
  • sudo -- let them have root!
  • vim -- I like color syntax editors.

    LXC update!

    Just setup a LXC system (the replacement for VServers?)
      ===== LXC tips =====
    
        lxc-ps --lxc                  (jobs in all VMs)
        lxc-ps --name vm0 --forest    (just in vm0)
        lxc-console -n vm0            (connect to console on vm0)
        /etc/init.d/lxc restart       (restart all VMs)
    
      Set up from a template:
        /usr/lib/lxc/templates/lxc-debian -p /home/lxc/vm999
      Edit the IP in /etc/lxc/
      Stop IP assignement in guest 
       vi /home/lxc/vm999/rootfs/etc/network/interfaces
      Add default GW to /etc/rc.local in guest
      
    In 2014, the syntax is this: lxc-create -t ubuntu -n MyGuest -- -r trusty vi /var/lib/lxc/MyGuest/config * add IP: lxc.network.ipv4 = 10.86.86.5 lxc-ls lxc-start --name MyGuest Easy! ( or for quantal: lxc-create -t ubuntu -n MyGuest -- -r quantal)