|
|
- Some useful commands
- See vserver information on the host
- to enter a vserver you can do either of these
- to see all processes on all vservers
- vtop
- Creating a vserver skeleton
- Duplicating an existing vserver
- Migrating a vserver from one machine to another
- Mounting a directory from one vserver into another
- What if I accidentally removed a vserver while it was running?
- Howto convert legacy vservers to the new format
- Howto add an IP to a running vserver, without restarting it?
- Howto make the host interface and IP available in a vserver
- Howto impose disk limits in each vserver
- Howto resize a tmpfs partition on a running vserver, without restarting it?
- How to rename a vserver
Some useful commands
See vserver information on the host
vserver-stat
to enter a vserver you can do either of these
# vserver kea enter
# vserver kea exec bash
to see all processes on all vservers
# vps
This is simply a wrapper which is actually doing:
# chcontext --ctx 1 ps $*
and
# vpstree
This is simply a wrapper which is actually doing:
@ chcontext --ctx 1 pstree $*
vtop
Running top on the host only shows you the processes on the host,
you can see a virtualized top that shows you everything in the host
and all the vservers by doing:
# vtop
Creating a vserver skeleton
You can create a dummy vserver by doing the following
# vserver <name> build -m skeleton --hostname <name> --interface eth0:some.ip.here
Duplicating an existing vserver
To duplicate an existing vserver into a dummy vserver:
# cp -a /vservers/existingvserver/* /vservers/newskeletonvserver
Migrating a vserver from one machine to another
- run:
rsync -Hazx -v --numeric-ids /vservers/bluebird newhost:/vservers/
rsync -Hazx -v --numeric-ids /etc/vservers/bluebird newhost:/etc/vservers/
- stop vserver:
vserver bluebird stop
- sync again:
- start new vserver: If you are moving a vserver from one machine to another on the same switch you will probably experience a few minutes delay before you have network connectivity. This is due to the switch trying to figure out why this IP suddenly appeared on a different port than it was just on, this is normal.
vserver bluebird start
Mounting a directory from one vserver into another
To mount a directory from one vserver into another from the host:
# vnamespace -e <vserver> mount --rbind /directory/to/mount/somewhere /where/to/mount/it
for example, the directory /var/www/website is in the vserver called "drupal" we want to
make this directory available in the vserver "flathtml" in directory /var/www/website,
to do this do the following:
# vnamespace -e flathtml mount --rbind /vservers/drupal/var/www/website /vservers/flathtml/var/www/website
to make this stick add it to that vserver's fstab file (see configuration options)
What if I accidentally removed a vserver while it was running?
Ooops! I wanted to delete a vserver so I rm -rf'd /etc/vservername and /vservers/vservername and then I got errors because I forgot to stop the vserver first so now there are a bunch of processes running in their context, but I cant stop them!
First look up the XID of the vserver:
# vserver-stat
Then kill those processes:
# vkill --xid <xid> -s TERM
# vkill --xid <xid> -s KILL
Howto convert legacy vservers to the new format
The old configuration had /etc/vservers/.conf, the new version has a directory in /etc/vservers for the vserver name, and a number of subdirectories in there with various parameters set.
If you haven't done anything major in setting up your legacy vserver, except set your IP you can do this to convert it to the new format:
First look at the vserver.conf file to see what the IP was and any other necessary configuration items, then build a skeleton vserver configuration:
# vserver face build -m skeleton --hostname face --interface eth0:69.90.134.205 --force
This creates the /etc/vservers/ directory, it also moves your /vservers/ out of the way and creates a new, empty one. We want to move our old one back, and put the new devices in place in our new one:
# cd /vservers
# mv face face.new
# mv face.~1231357235 face
# rm -rf face/dev/*
# cp -a face.new/dev/* face/dev/
Howto add an IP to a running vserver, without restarting it?
First, add the IP address to the config, so next restart it will work:
# mkdir /etc/vservers/face/interfaces/2
# echo "eth0" > /etc/vservers/face/interfaces/2/dev
# echo "192.168.100.100" > /etc/vservers/iface/interfaces/2/ip
# echo "24" > /etc/vservers/iface/interfaces/2/prefix
Then configure the interface to have the new IP address:
# ip addr add 192.168.100.100/24 broadcast + dev eth0
What is the + for? (see man ip):
+ has a special meaning for the broadcast setting
It is possible to use the special symbols '+' and '-' instead of
the broadcast address. In this case, the broadcast address is
derived by setting/resetting the host bits of the interface pre-fix.
Then enter the vserver and restart the processes that should get the new IP address:
# vserver face enter
face# /etc/init.d/apache restart
face# /etc/init.d/crond restart
Q. How does the face context know that it has this new address?
A. It is known when you next enter that vserver, the vserver enter command does a chbind, which applies the configuration values in /etc/vserver before it enters. So only the shell that you enter with has access to that new IP, the old running processes do not because they were started with an old shell that did not have visibility of that new IP, so that is why you restart them with the new shell.
NOTE: you should restart crond also, otherwise when crond runs logrotate and restarts apache it wont have access to the new IP!
Howto make the host interface and IP available in a vserver
If you need to bind to an interface (with something like the bind nameserver) in a vserver and your vserver doesn't have its own IP address, you can do this as long as the host doesn't have something binding on the same port. A typical usage is to run bind in a vserver, instead of on the host, or mysql in a vserver, instead of on the host, etc. You need to make the interface visible through the vserver configuration, otherwise it will not know any interfaces to bind to.
# mkdir /etc/vservers/face/0
# touch /etc/vservers/face/0/nodev
# cat > /etc/vservers/face/0/ip
the.host.ip.here
^D
# cat > /etc/vservers/face/0/prefix
the.host.netmask.here
^D
WARNING: if you do not put the nodev file there, when you restart your vserver you will tear down the networking on your host, this sucks!
Howto impose disk limits in each vserver
In order to get disk quotas working on a per context basis (per vserver) you need to run post-start once per reboot. The script is /etc/vservers/servername/scripts/post-start.
QUESTION: is this run automatically?
Syntax:
/usr/sbin/vdlimit --xid <number> --set space_total=<size_in_kilobytes> --set
space_used=`du -s /vservers/<vserver_name>/ | awk '{print $1}'` --set
inodes_total=<number_of_inodes> --set inodes_used=`ls -1aRi /vservers/<vserver_name>/ |
awk '/^[0-9]+ / { print $1 }' | sort -u | wc -l` --set reserved=5
/vservers/<vserver_name>/
Example (setting a vserver called test1 with context 100 to 4 GB):
/usr/sbin/vdlimit --xid 100 --set space_total=4000000 --set space_used=`du -s
/vservers/test1/ | awk '{print $1}'` --set inodes_total=4000000 --set inodes_used=`ls
-1aRi /vservers/test1/ | awk '/^[0-9]+ / { print $1 }' | sort -u | wc -l` --set
reserved=5 /vservers/test1/
This will make it look like the hard drive is actually that size from within the vserver:
Filesystem Size Used Avail Use% Mounted on
/dev/hdv1 3.9G 2.2G 1.5G 59% /
Note: If running this on an existing vserver, make sure that the du command's result is not bigger then the limit you are setting. It will return an error and then blow away your / mount, causing major disk space problems! See savannah.nongnu.org/bugs/?func=detailitem&item_id=14026
Howto resize a tmpfs partition on a running vserver, without restarting it?
You have a vserver called 'myvserver' which has a 16 MB tmpfs mounted to /tmp, but want it increased to 64 MB, and cannot restart the vserver as this would cause service interruption.
Login to the vserver host and determine the context ID of the vserver:
# cat /etc/vservers/myvserver/context
6666
#
Remount the tmpfs partition to /tmp with increased size:
# vnamespace -e 6666 -- mount -n -o remount,size=64M /etc/vservers/.defaults/vdirbase/myvserver/tmp{,}
#
Login to the vserver and verify that its size actually increased:
# vserver myvserver enter
root@myvserver:~# df -h /tmp
Filesystem Size Used Avail Use% Mounted on
none 64M 56K 64M 1% /tmp
Unfortunately, the 'mount' command will continue to report the old partition size, you will need to edit /etc/mtab to correct this.
How to rename a vserver
Renaming abc to xyz.
# vserver abc stop
# mv /vservers/abc /vservers/xyz
# mv /etc/vservers/abc /etc/vservers/xyz
# cd /etc/vservers/xyz
# rm cache run vdir
# ln -s /etc/vservers/.defaults/cachebase/xyz cache
# ln -s /var/run/vservers/xyz run
# ln -s /etc/vservers/.defaults/vdirbase/xyz vdir
# echo "xyz" > /etc/vservers/xyz/name
# echo "xyz" > /etc/vservers/xyz/uts/nodename
# vserver xyz start
|