Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

How to create package in Solaris

For this example I will be use apache web server, compiled from source and created as package

Create directory structure for package. For me /usr/src sound's good, but you can do it using your home directory
 

# cd /usr/src
# mkdir RTNapache InfoPath

Create in InfoPath directory file pkginfo with content
 

ARCH=i386
CATEGORY=application
NAME=Apache httpd server
PKG=RTNapache
VERSION=2.2.4
DESC=The Apache Project is a collaborative software development effort 
aimed at creating a robust, commercial-grade, featureful, and 
freely-available source code implementation of an HTTP (Web) server.
VENDOR=Apache License Version 2.0, January 2004 http://www.apache.org/licenses/


- ARCH is architecture you build this package. Can be sparc, i386 or ppc
- CATEGORY describe with keywords in which category is the package
- NAME define brief name of our package
- PKG is the name of package. Here is interest the fact 1st 4 letters should be unique
- VERSION is the version of package. In this case this is the version of Apache httpd server
- DESC is extensive text about the package
- VENDOR describe the copyright of the package



Configure, compile and install the software on original place
 

# ./configure --prefix=/opt/RTNapache --enable-so –enable-mods-shared=most
# make
# make install
# cd /opt/RTNapache/
# mv  * /usr/src/RTNapache/
# cd ..
# rmdir RTNapache

Do some changes to be sure server will work fine
 

Change index.html in /usr/src/RTNapache/htdocs to represent the situation with compiled software
Change in /usr/src/RTNapache/conf/httpd.conf: 
- comment ServerAdmin line
- set ErrorLog to be /var/adm/httpd because /opt is not the proper place for log files
- set CustomLog to be /var/adm/httpd (same reason as above)
Change permition of /usr/src/RTNapache/htdocs to be 755 to let user daemon to read web server content
Change ownership of /usr/src/RTNapache to be root:root

Create in InfoPath directory file, named prototype. To make it by hand is very hard, so we will use tool, named pkgproto executing
 

# pkgproto ./RTNapache > InfoFiles/prototype

Add record to prototype file for creation of /var/adm/httpd directory
 

# echo "d none /var/adm/httpd 0644 root root" >> InfoFiles/prototype

Add record to prototype file with information about pkginfo file
 

# echo "i pkginfo=/usr/src/InfoFiles/pkginfo" >>InfoFiles/prototype

Create the package
 

#  pkgmk -f InfoFiles/prototype -b /usr/src

Let's get little info about this new package
 

# cd /var/spool/pkg
# pkginfo -d .
application RTNapache Apache httpd server

Now in directory /var/spool/pkg we get our package and we can pack it as tar, transfer somewhere and install

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

For next example let's create another zone, named apache2, but this time we will use apache server from Solaris and config file from previous zone

# cp /zones/apache-zone.cfg /zones/apache2-zone.cfg

  • edit file and change zonepath and IP address
  • next will use this config file to initialize new zone

# zonecfg -z apache2 -f /zones/apache2-zone.cfg
# zoneadm -z apache2 install
# zoneadm -z apache2 boot

  •     add own users w3 with group w3 and create and edit config file. Do not forget to change IP address apache will listen and /etc/hosts for FQDN of host

# cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf
# groupadd w3
# useradd -g w3 w3


  •     create directory /var/run/apache2, because it do not exist, but it's need to keep apache pid file or make some changes in apache config file

mkdir -p /var/run/apache2


  •     start server and test if it's work

# /usr/apache2/bin/apachectl start
# ps -efl|grep http
0 S     root  4520  4062   0  50 20 dbbabae0    253 d6860820 09:44:33 pts/2       0:00 grep http
0 S       w3  4516  4513   0  40 20 dbbaaa20   1456 d5465384 09:44:23 ?           0:00 /usr/apache2/bin/httpd -k start
0 S     root  4513  3924   0  40 20 dbba9100   1421 d5ebbd16 09:44:22 ?           0:00 /usr/apache2/bin/httpd -k start
0 S       w3  4517  4513   0  40 20 e8df5ae8   1456 d5465384 09:44:23 ?           0:00 /usr/apache2/bin/httpd -k start
0 S       w3  4518  4513   0  40 20 e8df5288   1456 d5465384 09:44:23 ?           0:00 /usr/apache2/bin/httpd -k start
0 S       w3  4514  4513   0  40 20 e8df4a28   1456 d5465384 09:44:23 ?           0:00 /usr/apache2/bin/httpd -k start
0 S       w3  4515  4513   0  40 20 e8df41c8   1456 d5465384 09:44:23 ?           0:00 /usr/apache2/bin/httpd -k start

# telnet 192.168.30.101 80
Trying 192.168.30.101...
Connected to 192.168.30.101.
Escape character is '^]'.
get
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>501 Method Not Implemented</title>
</head><body>

Method Not Implemented

get to /index.html.en not supported.

<address>Apache/2.0.55 (Unix) DAV/2 Server at 192.168.30.101 Port 80</address>
</body></html>
Connection to 192.168.30.101 closed by foreign host.


    and now we have 2 zones and 2 different web servers

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 :-)

Should I trust AI

 Should I trust AI? So far no, sorry.  I tested for the moment (May, 2025) most advanced model for programming and ask very simple question:...