Creation of sample zone in Solaris for hosting apache, part 1

Let's use ZFS for storage of zones to help better disk management

zpool create -f zones c0d1
zfs create zones/apache
mount
 /zones on zones read/write/setuid/devices/exec/atime/dev.......
 /zones/apache on zones/apache read/write/setuid/devices/exec/atime/dev.......


Change the mode of directory because of need of zone management software

bash-3.00# chmod 700 /zones/apache
Create zone, named apache

bash-3.00# zonecfg -z apache
apache: No such zone configured

Use 'create' to begin configuring a new zone.

  •     we start with initial creation of zone

zonecfg:apache> create

  •     set the path where zone will reside

zonecfg:apache> set zonepath=/zones/apache

  •     set autoboot flag to boot when server boot

zonecfg:apache> set autoboot=true

  •     add network IP and physical interface. Do not forget to set netmask

zonecfg:apache> add net
zonecfg:apache:net> set address=192.168.30.100/24
zonecfg:apache:net> set physical=pcn0
zonecfg:apache:net> end


  •     add external directory /opt to be part of zone (just in case)

zonecfg:apache> add inherit-pkg-dir
zonecfg:apache:inherit-pkg-dir> set dir=/opt
zonecfg:apache:inherit-pkg-dir> end


  •     get the config info about the zone (on screen)

zonecfg:apache> info
zonepath: /zones/apache
autoboot: true
pool:
inherit-pkg-dir:
       dir: /lib
inherit-pkg-dir:
       dir: /platform
inherit-pkg-dir:
       dir: /sbin
inherit-pkg-dir:
       dir: /usr
inherit-pkg-dir:
       dir: /opt
net:
       address: 192.168.30.100/24
       physical: pcn0


  •     commit all the changes we made

zonecfg:apache> commit

  •     export the config for future usage or just for backup. Do not put it in /tmp, because on each boot this filesystem is purged

zonecfg:apache> export -f /zones/apache-zone.cfg

  •     and exit from the program

zonecfg:apache> exit

    Now let's install the software in zone (this operation will take a while)

bash-3.00# zoneadm -z apache install
Preparing to install zone <apache>.
Creating list of files to copy from the global zone.
Copying <2361> files to the zone.
Initializing zone product registry.
Determining zone package initialization order.
Preparing to initialize <968> packages on the zone.
Initializing package <372> of <968>: percent complete: 38%......


    Little check of situation
  •     diskspace

bash-3.00# df -k /zones/apache/
Filesystem            kbytes    used   avail capacity  Mounted on
zones/apache         12321792   70034 12251635     1%    /zones/apache


  •     status of zones

bash-3.00# zoneadm list -v
 ID NAME             STATUS         PATH
  0 global           running        /


  •     boot our new zone

bash-3.00# zoneadm -z apache boot

  •     and check again zones status

bash-3.00# zoneadm list -v
 ID NAME             STATUS         PATH
  0 global           running        /
  2 apache           running        /zones/apache


    Some preparation tasks
  •     login in to the zone

bash-3.00# zlogin  apache
[Connected to zone 'apache' pts/2]
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005


  •     create some directories where we will place web server (we aware directories /lib, /opt, /platform, /sbin and /usr are mounted from global zone as readonly, but / (root) not so we put there our apache)

# mkdir -p /www/src

  •     copy the software (from other terminal :-)

bash-3.00# cd /zones/apache/root/www/src/
bash-3.00# cp /tmp/httpd-2.2.4.tar.gz .


  •     decompress and untar the archive (from with in zone)

# cd /www/src
# gzip -d httpd-2.2.4.tar.gz|tar
# tar xvf httpd-2.2.4.tar


  •     * configure and compile the software (its take a while)

# cd  httpd-2.2.4
# ./configure --prefix=/www --enable-so –enable-mods-shared=all

<cut long listing>

# make

<cut long listing>

# make test

`test' is up to date.

# make install

<cut long listing>


  •     create user to manage files

# groupadd w3
# useradd -g w3 w3
# chown -R w3:w3 /www/htdocs

  •     edit /www/conf/httpd.conf to change User and Group from daemon to w3
  •     edit /etc/hosts to add line like this

192.168.30.100 apache.example.net apache

    let's run the http server

# /www/bin/apachectl start
    check if the server is running
  •     check process

# ps -efl|grep htt
0 S       w3 22380 22377   0  40 20 d39c2008   1136 d54cfd5c 01:24:41 ?           0:00 /www/bin/httpd -k start
0 S       w3 22381 22377   0  40 20 d4e80940   1136 d54cfd5c 01:24:41 ?           0:00 /www/bin/httpd -k start
0 S       w3 22378 22377   0  40 20 d4e73270   1136 d54cfd5c 01:24:41 ?           0:00 /www/bin/httpd -k start
0 S       w3 22379 22377   0  40 20 d4e70890   1136 d54cfd5c 01:24:41 ?           0:00 /www/bin/httpd -k start
0 S     root 22377  5541   0  40 20 d4e70030   1103 d49abb16 01:24:40 ?           0:00 /www/bin/httpd -k start
0 S     root 22384 15053   1  50 20 d5182a18    253 d6880300 01:25:21 pts/2       0:00 grep htt
0 S       w3 22382 22377   0  40 20 d5181958   1136 d54cfd5c 01:24:41 ?           0:00 /www/bin/httpd -k start

  •     check service

# telnet 192.168.30.100 80
Trying 192.168.30.100...
Connected to 192.168.30.100.
Escape character is '^]'.
GET

<html><body>
It works!
</body></html>

Connection to 192.168.30.100 closed by foreign host.

So our apache is running and working :-)

No comments:

Post a Comment

Compressed tar archive

There are some cases when you want to create compressed tar archive but you do not have enough disk space to keep original files and tar arc...