Configuration et utilisation des Zones Solaris (Containers)
1 Introduction
Zones or Caontainers are :
- Virtual instance of Solaris
- Software partition for the OS
A large SunFire server with hardware domains allows many isolated systems to be created. Zones achieve this in software and is far more flexible - it is easy to move individual CPUs between zones as needed, or to configure a more sophisticated way to share CPUs and memory.
2 Configuration
There are two general zone types to pick from during zone creation. They are,
- Small zone - (also known as a "Sparse Root zone") : The default. This consumes the least disk space, has the best performance and the best security.
- Big zone - (also known as a "Whole Root zone") : The zone has its own /usr files, which can be modified independently.
If you aren't sure which to choose, pick the small zone. Below are examples of installing each zone type as a starting point for Zone Resource Controls.
2.1 Small Zone
This demonstrates creating a simple zone that uses the default settings which share most of the operating system with the global zone. The final layout will be like the following,
To create such a zone involves letting the system pick default settings, which includes the loopback filesystem (lofs) read only mounts that share most of the OS. The following commands were used,
The new zone is in a configured state. Those inherited-pkg-dir's are filesystems that will be shared lofs (loopback filesystem) readonly from the global; this saves copying the entire operating system over during install, but can make adding packages to the small-zone difficult as /usr is readonly. (See the big-zone example that uses a different approach).
We can see the zonecfg command has saved the info to an XML file in /etc/zones :
Next we begin the zone install, it takes around 10 minutes to initialise the packages it needs for the new zone. A verify is run first to check our zone config is ok, then we run the install, then boot the zone :
We can see small-zone is up and running. Now we login for the first time to the console, so we can answer system identification questions such as timezone,
The system then reboots. To get an idea of what this zone actually is, lets poke around it's zonepath from the global zone,
From the directories that are not lofs shared from the global zone, the main ones are /etc and /var. They add up to around 70Mb, which is roughly how much extra disk space was required to create this small-zone.
2.2 Big Zones
This demonstrates creating a zone that resides on it's own slice, which has it's own copy of the operating system. The final layout will be like the following :
First we create the slice :
Now we configure the zone to not use any inherit-pkg-dir's by using the "-b" option.
After the zone has been installed and booted, we now check the size of the dedicated zone slice,
df |
df -h /export/big-zone Filesystem size used avail capacity Mounted on /dev/dsk/c0t1d0s0 7.8G 2.9G 4.8G 39% /export/big-zone |
Wow! 2.9Gb, pretty much most of Solaris 10. This zone resides on it's own slice, and can add many packages as though it was a separate system. Using inherit-pkg-dir as happened with small-zone can be great, but it's good to know we can do this as well.
3 Management
3.1 view or list all running zones
The zoneadm command can be used to list active or running zones.
To view a list and brief status information about running zones, use the following command from the global zone:
zoneadm |
zoneadm list -vc ID NAME STATUS PATH 0 global running / 2 zone2 running /opt/zone2 |
The -v option provides the additional information other than the zone name.
3.2 Shutdown or stop a zone
To boot a Solaris 10 zone called testzone, use the following command as root in the global zone:
zoneadm |
zoneadm -z testzone boot |
You can watch the system boot by logging into the zone's console:
zlogin |
zlogin -C testzone |
3.3 Uninstall and delete a zone
When you want to remove a non-global zone from your Solaris 10 installation, you'll need to follow the following steps.
If you want to completely remove a zone called 'testzone' from your system, login to the global zone and become root. The first command is the opposite of the 'install' option of zoneadm and deletes all of the files under the zonepath:
zoneadm |
zoneadm -z testzone uninstall |
At this point, the zone is in the configured state. To remove it completely from the system use:
zoneadm |
zonecfg -z testzone delete |
There is no undo, so make sure this is what you want to do before you do it.
4 Ressources Control
Although the Solaris 10 08/07 OS allows you to specify how many CPUs can be used in a zone, sometimes this does not work out well. For example, I use dedicated-cpu for three zones in an 8-core Sun Fire T2000 server. Each zone has 4-20 specified for ncpus with a different importance value. However, when the system is fully utilized, the importance value does not always play its role. Sometimes, a zone with a lower importance value consumes a higher percentage of the computing resources than a zone with higher importance.
In the following, I demonstrate that cpu-shares works well.
Generate 20 processes in zone bighead :
<username>@bighead> perl -e 'while (--$ARGV[0] and fork) {}; while () {}' 20 & |
Generate 12 processes in zone bighand :
As we see, when the system is not fully utilized, each zone uses as many computing resources as it needs.
Now, we will generate 15 processes in zone bigfoot to see how the bighead and bighand zones consume the computing resources:
As we see, each zone is consuming a portion of the computing resources according to its cpu-shares value when the system's computing resources are fully utilized.
4.2 The swap property of capped-memory is virtual swap space, not physical swap space
For zone bighead running Oracle Database 10g Enterprise Edition with total memory of 2 Gbytes (1.5 Gbytes System Global Area [SGA] and 0.5 Gbytes Process Global area [PGA]), we might just give a maximum of 3 Gbytes memory and 1.5 Gbytes swap space, as follows:
info |
zonecfg:bighead> info capped-memory capped-memory: physical: 3G [swap: 1.5G] |
Start up the Oracle database in zone bighead:
sqlplus |
oracle@bighead> sqlplus /nolog SQL> conn / as sysdba SQL& startup ORA-27102: out of memory SVR4 Error: 12: Not enough space |
So the swap here is not physical swap space. Based on Sun documents, swap here means the total amount of swap that can be consumed by user process address space mappings and tmpfs mounts for this zone. When we set up swap, the capped-memory swap should be set proportionately. For example:
In our case, it should be 3 * ( 38 / 15 ), which equals 7 Gbytes.
4.3 Sometimes, a zone consumes more physical memory than the maximum limit
info |
zonecfg:bighead> info capped-memory capped-memory: physical: 1G [swap: 7G] [locked: 1G] |
The Oracle database took a while to start up. The Resident Set Size (RSS) memory consumed by the zone fluctuated around, as follows:
But 1779 Mbytes is much more than 1 Gbyte. Sun is aware of this known bug.
5 FAQ
5.1 How to exit zlogin
To exit zlogin, there is a default sequence to do :
~. |
If you want to personalize this sequence, use -e option while launching zlogin command :
zlogin |
zlogin -C -e @ big-zone |
5.2 Adding a file system to a running zone
I needed to add a second file system to one of my Solaris 10 zones this morning, and needed to do so without rebooting the zone. Since the global zone uses loopback mounts to present file systems to zones, adding a new file system was as easy as loopback mounting the file system into the zone’s file system:
mount |
mount -F lofs /filesystems/zone1oracle03 /zones/zone1/root/ora03 |
Once the file system was mounted, I added it to the zone configuration and then verified it was mounted:
mount |
$ mount |
Now to update my ASM disk group to use the storage.
6 References
http://www.solarisinternals.com/wiki/index.php/Zones
http://www.sun.com/bigadmin/content/zones/
Manage Easily Pools with Kpool GUI
http://www.sun.com/bigadmin/content/submitted/zone_resource_control.jsp
Assigner des ressources à des zones sans rebooter
http://prefetch.net/blog/index.php/2009/04/12/adding-a-file-system-to-a-running-zone/