| 1 |
<?xml version='1.0' encoding="UTF-8"?> |
| 2 |
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/proj/en/vps/vserver-howto.xml,v 1.9 2007/03/26 19:57:52 hollow Exp $ --> |
| 3 |
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> |
| 4 |
|
| 5 |
<guide link="/proj/en/vps/vserver-howto.xml"> |
| 6 |
<title>Gentoo Linux-VServer Howto</title> |
| 7 |
|
| 8 |
<author title="Author"> |
| 9 |
<mail link="hollow@gentoo.org">Benedikt Boehm</mail> |
| 10 |
</author> |
| 11 |
<author title="Editor"> |
| 12 |
<mail link="fox2mike@gentoo.org">Shyam Mani</mail> |
| 13 |
</author> |
| 14 |
|
| 15 |
<abstract> |
| 16 |
In this Howto you will learn to setup a basic virtual server using the |
| 17 |
Linux-VServer Technology |
| 18 |
</abstract> |
| 19 |
|
| 20 |
<!-- The content of this document is licensed under the CC-BY-SA license --> |
| 21 |
<!-- See http://creativecommons.org/licenses/by-sa/2.5 --> |
| 22 |
<license/> |
| 23 |
|
| 24 |
<version>1.10</version> |
| 25 |
<date>2007-03-26</date> |
| 26 |
|
| 27 |
<chapter> |
| 28 |
<title>Introduction</title> |
| 29 |
<section> |
| 30 |
<title>The Linux-VServer Concept</title> |
| 31 |
<body> |
| 32 |
|
| 33 |
<p> |
| 34 |
The basic concept of the Linux-VServer solution is to separate the user-space |
| 35 |
environment into distinct units (sometimes called Virtual Private Servers) in |
| 36 |
such a way that each VPS looks and feels like a real server to the processes |
| 37 |
contained within. |
| 38 |
</p> |
| 39 |
|
| 40 |
</body> |
| 41 |
</section> |
| 42 |
<section> |
| 43 |
<title>Terms used in this Howto</title> |
| 44 |
<body> |
| 45 |
|
| 46 |
<table> |
| 47 |
<tr> |
| 48 |
<th>Term</th> |
| 49 |
<th>Description</th> |
| 50 |
</tr> |
| 51 |
<tr> |
| 52 |
<th>Linux-VServer, VServer</th> |
| 53 |
<ti> |
| 54 |
Linux-VServer is the official name of the project and used in this Howto |
| 55 |
the same way |
| 56 |
</ti> |
| 57 |
</tr> |
| 58 |
<tr> |
| 59 |
<th>virtual server, vserver, guest system</th> |
| 60 |
<ti> |
| 61 |
All these are interchangable and refer to one instance of a server (i.e. |
| 62 |
one virtual server) |
| 63 |
</ti> |
| 64 |
</tr> |
| 65 |
<tr> |
| 66 |
<th>host system, host</th> |
| 67 |
<ti> |
| 68 |
The physical machine running your Gentoo Linux will host all virtual |
| 69 |
servers |
| 70 |
</ti> |
| 71 |
</tr> |
| 72 |
<tr> |
| 73 |
<th>util-vserver</th> |
| 74 |
<ti> |
| 75 |
The <c>util-vserver</c> package contains all programs necessary for |
| 76 |
maintaining your virtual servers |
| 77 |
</ti> |
| 78 |
</tr> |
| 79 |
</table> |
| 80 |
|
| 81 |
</body> |
| 82 |
</section> |
| 83 |
</chapter> |
| 84 |
|
| 85 |
<chapter> |
| 86 |
<title>Host configuration</title> |
| 87 |
<section> |
| 88 |
<title>Install a VServer kernel</title> |
| 89 |
<body> |
| 90 |
|
| 91 |
<pre caption="Install vserver-sources"> |
| 92 |
# <i>emerge vserver-sources</i> |
| 93 |
</pre> |
| 94 |
|
| 95 |
<p> |
| 96 |
After the vserver-sources are installed it's time to configure them using |
| 97 |
<c>make menuconfig</c>.. Below is a common configuration for 2.1.1 and above. If |
| 98 |
you are using 2.0.x some configuration options may not be present. |
| 99 |
</p> |
| 100 |
|
| 101 |
<pre caption="Configure vserver-sources"> |
| 102 |
# <i>cd /usr/src/linux-<KERNELVERSION>-vserver-<VSERVERVERSION></i> |
| 103 |
# <i>make menuconfig</i> |
| 104 |
|
| 105 |
Linux VServer ---> |
| 106 |
<comment>(Do not enable the legacy options)</comment> |
| 107 |
[ ] Enable Legacy Kernel API |
| 108 |
[ ] Enable Legacy Networking Kernel API |
| 109 |
<comment>(Read help text)</comment> |
| 110 |
[ ] Remap Source IP Address |
| 111 |
[*] Enable COW Immutable Link Breaking |
| 112 |
[ ] Enable Virtualized Guest Time |
| 113 |
[*] Enable Proc Security |
| 114 |
[*] Enable Hard CPU Limits |
| 115 |
[*] Avoid idle CPUs by skipping Time |
| 116 |
[*] Limit the IDLE task |
| 117 |
Persistent Inode Tagging (UID24/GID24) ---> |
| 118 |
[ ] Tag NFSD User Auth and Files |
| 119 |
[*] Enable Inode Tag Propagation |
| 120 |
[*] Honor Privacy Aspects of Guests |
| 121 |
[ ] VServer Debugging Code |
| 122 |
</pre> |
| 123 |
|
| 124 |
<note> |
| 125 |
If you are using reiserfs as filesystem on the partition where guest images are |
| 126 |
stored, you will need to enable extended attributes for reiserfs in your |
| 127 |
kernel config and additionally add the <c>attrs</c> option in |
| 128 |
<path>/etc/fstab</path>. |
| 129 |
</note> |
| 130 |
|
| 131 |
<pre caption="Configure reiserfs options"> |
| 132 |
File systems ---> |
| 133 |
<*> Reiserfs support |
| 134 |
[*] ReiserFS extended attributes |
| 135 |
</pre> |
| 136 |
|
| 137 |
<pre caption="Example fstab with extended attributes"> |
| 138 |
/dev/hdb1 /vservers reiserfs noatime,attrs 0 0 |
| 139 |
</pre> |
| 140 |
|
| 141 |
<p> |
| 142 |
After you've built and installed the kernel, update your boot loader and |
| 143 |
finally reboot to see if the kernel boots correctly. |
| 144 |
</p> |
| 145 |
|
| 146 |
<pre caption="Install the kernel"> |
| 147 |
<comment>(Building the kernel)</comment> |
| 148 |
# <i>make</i> |
| 149 |
<comment>(Installing)</comment> |
| 150 |
# <i>make modules_install</i> |
| 151 |
# <i>cp arch/<arch>/boot/bzImage /boot/kernel-<KERNELVERSION>-vserver-<VSERVERVERSION></i> |
| 152 |
<comment>(Edit bootloader config file as required and)</comment> |
| 153 |
# <i>reboot</i> |
| 154 |
</pre> |
| 155 |
|
| 156 |
</body> |
| 157 |
</section> |
| 158 |
<section> |
| 159 |
<title>Setup host environment</title> |
| 160 |
<body> |
| 161 |
|
| 162 |
<p> |
| 163 |
To maintain your virtual servers you need the util-vserver package which |
| 164 |
contains all necessary programs and many useful features. |
| 165 |
</p> |
| 166 |
|
| 167 |
<pre caption="Install util-vserver"> |
| 168 |
# <i>emerge >=sys-cluster/util-vserver-0.30.212</i> |
| 169 |
</pre> |
| 170 |
|
| 171 |
<p> |
| 172 |
You have to run the <c>vprocunhide</c> command after every reboot in order to |
| 173 |
setup <path>/proc</path> permissions correctly for vserver guests. Two init |
| 174 |
scripts have been installed by util-vserver which run the <c>vprocunhide</c> |
| 175 |
command for you and take care of virtual servers during shutdown of the host. |
| 176 |
</p> |
| 177 |
|
| 178 |
<pre caption="util-vserver init scripts"> |
| 179 |
# <i>rc-update add vprocunhide default</i> |
| 180 |
# <i>/etc/init.d/vprocunhide start</i> |
| 181 |
# <i>rc-update add util-vserver default</i> |
| 182 |
# <i>/etc/init.d/util-vserver start</i> |
| 183 |
</pre> |
| 184 |
|
| 185 |
</body> |
| 186 |
</section> |
| 187 |
</chapter> |
| 188 |
|
| 189 |
<chapter> |
| 190 |
<title>Guest creation</title> |
| 191 |
<section> |
| 192 |
<title>Download a precompiled stage3/4</title> |
| 193 |
<body> |
| 194 |
|
| 195 |
<p> |
| 196 |
Since many hardware related commands are not available inside a virtual server, |
| 197 |
there has been a patched version of baselayout known as baselayout-vserver. |
| 198 |
However, since baselayout-1.13.0_alpha12, all required changes have been |
| 199 |
integrated into normal baselayout, eliminating the need for seperate vserver |
| 200 |
stages, profiles and baselayout. The only (temporary) drawback is that |
| 201 |
baselayout-1.13 is still considered to be in alpha stage and there are no |
| 202 |
stages with baselayout-1.13 available on the mirrors yet. |
| 203 |
</p> |
| 204 |
|
| 205 |
<p> |
| 206 |
As soon as baselayout-1.13 is stable you can use a precompiled stage3/4 from |
| 207 |
one of <uri link="/main/en/mirrors.xml">our mirrors</uri>. In the meantime |
| 208 |
please download a stage3/4 from |
| 209 |
<uri link="http://people.linux-vserver.org/~hollow/stages/">here</uri>. |
| 210 |
Since a stage3/4 contains a complete root filesystem you can use the template |
| 211 |
build method of util-vserver. However, this method is only works reliable since |
| 212 |
util-vserver-0.30.213_rc5, so make sure you have the right version installed. |
| 213 |
</p> |
| 214 |
|
| 215 |
<p> |
| 216 |
You have to choose a context ID for your vserver (dynamic context IDs are |
| 217 |
discouraged) as well as the necessary network device information (In this |
| 218 |
example eth0 is configured with 192.168.1.253/24 and the context ID is |
| 219 |
equivalent to the last two parts of the virtual servers IP). |
| 220 |
</p> |
| 221 |
|
| 222 |
<note> |
| 223 |
The context ID should be 1 < ID < 49152. |
| 224 |
</note> |
| 225 |
|
| 226 |
</body> |
| 227 |
</section> |
| 228 |
<section> |
| 229 |
<title>Using the template build method</title> |
| 230 |
<body> |
| 231 |
|
| 232 |
<p> |
| 233 |
For a long time now, plain init style was the only init style available for |
| 234 |
gentoo, i.e. a normal init process will be started inside the guest, just like |
| 235 |
on any common Unix system. However this approach has some drawbacks: |
| 236 |
</p> |
| 237 |
|
| 238 |
<ul> |
| 239 |
<li>No possibility to see output of init/rc scripts</li> |
| 240 |
<li>Wasted resources for idle init processes in each guest</li> |
| 241 |
<li>Annoying conflicts for <path>/etc/inittab</path></li> |
| 242 |
</ul> |
| 243 |
|
| 244 |
<p> |
| 245 |
Therefore, many users have requested to reimplement the gentoo init style, |
| 246 |
which has been abandonned since it was a very hacky implementation and more |
| 247 |
or less worked by accident due to other modifications done to baselayout back |
| 248 |
then. However, as of util-vserver-0.30.212 the gentoo init style has been |
| 249 |
reimplemented in a concise manner and will get the default in the future. |
| 250 |
</p> |
| 251 |
|
| 252 |
<note> |
| 253 |
If there is not a good reason for using an extra init process for each guest |
| 254 |
or if you don't know what to do here, you should stick with gentoo init style. |
| 255 |
</note> |
| 256 |
|
| 257 |
<pre caption="Start stage3 installation"> |
| 258 |
# <i>vserver myguest build \</i> |
| 259 |
<i>--context 1253 \</i> |
| 260 |
<i>--hostname gentoo \</i> |
| 261 |
<i>--interface eth0:192.168.1.253/24 \</i> |
| 262 |
<i>--initstyle gentoo \</i> <comment>(replace if needed)</comment> |
| 263 |
<i>-m template -- \</i> |
| 264 |
<i> -d gentoo \</i> |
| 265 |
<i> -t /path/to/stage4-<arch>-<version>.tar.bz2</i> |
| 266 |
</pre> |
| 267 |
|
| 268 |
<note> |
| 269 |
To reflect your network settings you should change |
| 270 |
<path>/etc/conf.d/hostname</path>, <path>/etc/conf.d/domainname</path> and |
| 271 |
<path>/etc/hosts</path> inside the guest to your needs. See <uri |
| 272 |
link="/doc/en/handbook/handbook-x86.xml?part=1&chap=8#doc_chap2_sect1">chapter |
| 273 |
8.b.1</uri> and <uri |
| 274 |
link="/doc/en/handbook/handbook-x86.xml?part=1&chap=8#doc_chap2_sect4">chapter |
| 275 |
8.b.4</uri>. The rest of your virtual servers network setup will be |
| 276 |
done on the host. |
| 277 |
</note> |
| 278 |
|
| 279 |
<p> |
| 280 |
You should now be able to start and enter the vserver by using the commands |
| 281 |
below. |
| 282 |
</p> |
| 283 |
|
| 284 |
<pre caption="Test the virtual server"> |
| 285 |
# <i>vserver myguest start</i> |
| 286 |
|
| 287 |
|
| 288 |
Gentoo/Linux 1.13.0_alpha12; http://www.gentoo.org/ |
| 289 |
Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2 |
| 290 |
|
| 291 |
Press I to enter interactive boot mode |
| 292 |
|
| 293 |
* Using existing device nodes in /dev [ ok ] |
| 294 |
* root filesystem is mounted read-write - skipping |
| 295 |
* Checking all filesystems [ ok ] |
| 296 |
* Mounting local filesystems [ ok ] |
| 297 |
* Activating (possible) swap [ ok ] |
| 298 |
* Setting hostname to myguest [ ok ] |
| 299 |
* Updating environment [ ok ] |
| 300 |
* Cleaning /var/lock, /var/run [ ok ] |
| 301 |
* Cleaning /tmp directory [ ok ] |
| 302 |
* Initializing random number generator [ ok ] |
| 303 |
* Setting system clock using the hardware clock [VPS] [ ok ] |
| 304 |
* Starting syslog-ng [ ok ] |
| 305 |
* Starting vixie-cron [ ok ] |
| 306 |
* Starting local [ ok ] |
| 307 |
# <i>vserver-stat</i> |
| 308 |
CTX PROC VSZ RSS userTIME sysTIME UPTIME NAME |
| 309 |
0 90 1.4G 153.4K 14m00s11 6m45s17 2h59m59 root server |
| 310 |
1252 2 3M 286 0m00s45 0m00s42 0m02s91 myguest |
| 311 |
# <i>vserver myguest enter</i> |
| 312 |
# <i>ps ax</i> |
| 313 |
PID TTY STAT TIME COMMAND |
| 314 |
1 ? S 0:00 init [3] |
| 315 |
22887 ? Ss 0:00 /usr/sbin/syslog-ng |
| 316 |
20496 pts/0 S 0:00 /bin/bash -login |
| 317 |
20508 pts/0 R+ 0:00 ps ax |
| 318 |
# <i>logout</i> |
| 319 |
</pre> |
| 320 |
|
| 321 |
</body> |
| 322 |
</section> |
| 323 |
</chapter> |
| 324 |
|
| 325 |
<chapter> |
| 326 |
<title>Maintenance made easy</title> |
| 327 |
<section> |
| 328 |
<title>Start guests on boot</title> |
| 329 |
<body> |
| 330 |
|
| 331 |
<p> |
| 332 |
You can start certain guests during boot. Each guest can be assigned a MARK. |
| 333 |
Now everything you have to do is configure these MARKs in the guests |
| 334 |
configuration and add the approriate init scripts to the default runlevel. |
| 335 |
</p> |
| 336 |
|
| 337 |
<pre caption="Configure MARKs for each guest"> |
| 338 |
<comment>(Do this for every guest you want to start)</comment> |
| 339 |
# <i>mkdir -p /etc/vservers/myguest/apps/init</i> |
| 340 |
# <i>echo "default" > /etc/vservers/myguest/apps/init/mark</i> |
| 341 |
</pre> |
| 342 |
|
| 343 |
<pre caption="Add init script to the default runlevel"> |
| 344 |
# <i>rc-update add vservers.default default</i> |
| 345 |
</pre> |
| 346 |
|
| 347 |
</body> |
| 348 |
</section> |
| 349 |
<section> |
| 350 |
<title>Keep portage in sync</title> |
| 351 |
<body> |
| 352 |
|
| 353 |
<p> |
| 354 |
The script <c>vesync</c> will help you to keep the metadata cache and overlays |
| 355 |
in sync. <c>vemerge</c> is a simple wrapper for <c>emerge</c> in guests. |
| 356 |
</p> |
| 357 |
|
| 358 |
<pre caption="Examples"> |
| 359 |
<comment>(Sync metadata for 'myguest')</comment> |
| 360 |
# <i>vesync myguest</i> |
| 361 |
<comment>(Sync metadata for all guests)</comment> |
| 362 |
# <i>vesync --all</i> |
| 363 |
<comment>(Sync 'myoverlay' for all guests)</comment> |
| 364 |
# <i>vesync --all \</i> |
| 365 |
<i>--overlay /usr/local/overlays/myoverlay \</i> |
| 366 |
<i>--overlay-host rsync://rsync.myhost.com/myoverlay \</i> |
| 367 |
<i>--overlay-only</i> |
| 368 |
<comment>(emerge app-editors/vim in 'myguest')</comment> |
| 369 |
# <i>vemerge myguest -- app-editors/vim -va</i> |
| 370 |
</pre> |
| 371 |
|
| 372 |
</body> |
| 373 |
</section> |
| 374 |
<section> |
| 375 |
<title>Update guests</title> |
| 376 |
<body> |
| 377 |
|
| 378 |
<p> |
| 379 |
Gentoo guests can share packages to save compilation time. In order to use |
| 380 |
shared packages, you have to create a central directory for packages on the |
| 381 |
host. We will use <path>/var/cache/vpackages</path> on the host and mount it |
| 382 |
to <path>/usr/portage/packages</path> in every guest. |
| 383 |
</p> |
| 384 |
|
| 385 |
<pre caption="Add bind mount to guest configuration"> |
| 386 |
# <i>mkdir -p /var/cache/vpackages</i> |
| 387 |
# <i>$EDITOR /etc/vservers/myguest/fstab</i> |
| 388 |
<comment>(Add this line at the end)</comment> |
| 389 |
/var/cache/vpackages /usr/portage/packages none bind,rw 0 0 |
| 390 |
</pre> |
| 391 |
|
| 392 |
<p> |
| 393 |
Now you can use <c>vupdateworld</c> to update every guest. The command is |
| 394 |
equivalent to something like <c>emerge --deep --update --newuse world</c> |
| 395 |
depending on command line options. |
| 396 |
</p> |
| 397 |
|
| 398 |
<pre caption="vupdateworld examples"> |
| 399 |
<comment>(Pretend update for 'myguest')</comment> |
| 400 |
# <i>vupdateworld myguest -- -vp</i> |
| 401 |
<comment>(Update 'myguest' using binary packages)</comment> |
| 402 |
# <i>vupdateworld myguest -- -k</i> |
| 403 |
<comment>(Update all guests using binary packages)</comment> |
| 404 |
# <i>vupdateworld --all -- -k</i> |
| 405 |
</pre> |
| 406 |
|
| 407 |
<note> |
| 408 |
In order to get binary packages you can either use PORTAGE_BINHOST (see <c>man |
| 409 |
make.conf</c>) or set FEATURES="buildpkg" in one or more guests. |
| 410 |
</note> |
| 411 |
|
| 412 |
<p> |
| 413 |
After a successful update you can easily update all configuration files with |
| 414 |
<c>vdispatch-conf</c>. It is a simple wrapper for <c>dispatch-conf</c> and |
| 415 |
behaves exactly the same. |
| 416 |
</p> |
| 417 |
|
| 418 |
<pre caption="vdispatch-conf examples"> |
| 419 |
<comment>(Update configuration files for 'myguest')</comment> |
| 420 |
# <i>vdispatch-conf myguest</i> |
| 421 |
<comment>(Update configuration files for all guests)</comment> |
| 422 |
# <i>vdispatch-conf --all</i> |
| 423 |
</pre> |
| 424 |
|
| 425 |
</body> |
| 426 |
</section> |
| 427 |
|
| 428 |
<section> |
| 429 |
<title>Contact</title> |
| 430 |
<body> |
| 431 |
|
| 432 |
<p> |
| 433 |
Please feel free to contact the <mail link="hollow@gentoo.org">author</mail> or |
| 434 |
file a bug on <uri link="http://bugs.gentoo.org">Bugzilla</uri> in case of any |
| 435 |
problems. |
| 436 |
</p> |
| 437 |
|
| 438 |
</body> |
| 439 |
</section> |
| 440 |
</chapter> |
| 441 |
</guide> |