I want to set up some jails. They will each be very similar.
They will each be used to test a slightly different configuration
of Bacula. My tool of choice
is ezjail,
available in the ports tree.
With ezjail, I can:
create a jail flavour, upon which the creation of other jails can be based
centrally update the jail's ports tree
The above does not fully describe the neat things you can do with ezjail.
Read below to discover more fun and interesting things.
DISCLAIMER: I installed ezjail several months ago. I am only now getting
around to documenting and writing about it. I may have omitted some
steps. If so, I apologize; please let me know.
While creating my jails I used the following references:
cd /usr/local/etc
cp ezjail.conf.sample ezjail.conf
Create your base jail
This command creates the base jail. The base jail is the one upon which
all other jails will be based. Note that this does not create a jail,
it creates a base jail, one of the foundation components of your
ezjail configuration.
ezjail-admin update -ip
This assumes you have already done a build world and that it exists within
the standard and default location: /usr/src.
After running this command you should see this:
# ls /usr/jails
basejail flavours newjail
It also installs a copy of the ports tree into the base jail, using portsnap.
I encountered this error while trying to create a new basejail.
Upgrading to the latest STABLE fixed this problem.
install -o root -g wheel -m 444 dir-tmpl /usr/jails/fulljail/usr/share/info/dir
install:No such file or directory
Creating the IP addresses for the jails
The host system needs to have some IP addresses that will be used
exclusively by the jails. That is, one IP address per jail. For
ease of use, and personal sanity, I've added the following entries
to my private DNS server:
; jails for testing Bacula
mysql41 IN A 10.10.10.100
mysql50 IN A 10.10.10.101
mysql51 IN A 10.10.10.102
pg73 IN A 10.10.10.103
pg74 IN A 10.10.10.104
pg80 IN A 10.10.10.105
pg81 IN A 10.10.10.106
pg82 IN A 10.10.10.107
pg83 IN A 10.10.10.109
sqlite3 IN A 10.10.10.108
Corresponding to the above, here are the ifconfig aliases I added to
/etc/rc.conf on the host system:
The following command creates the first jail. You can create
additional jails by changing the hostname and the IP address.
Each jail needs a unique IP address and hostname. Ideally,
the IP address will correspond to the IP address you have selected.
# ezjail-admin create -f bacula mysql41.example.org 10.10.10.100
/usr/jails/mysql41.example.org/COPYRIGHT
/usr/jails/mysql41.example.org/basejail
/usr/jails/mysql41.example.org/bin
/usr/jails/mysql41.example.org/boot
/usr/jails/mysql41.example.org/dev
...
...
...
/usr/jails/mysql41.example.org/var/cfengine/inputs
/usr/jails/mysql41.example.org/var/cfengine/inputs/update.conf
/usr/jails/mysql41.example.org/var/cfengine/master
40797 blocks
Note: Shell scripts installed, flavourizing on jails first startup.
Warning: Some services already seem to be listening on all IP, (including 10.55.0.100)
This may cause some confusion, here they are:
root bacula-fd 1023 3 tcp4 *:9102 *:*
root sshd 1010 4 tcp4 *:22 *:*
root master 995 11 tcp4 *:25 *:*
root syslogd 816 7 udp4 *:514 *:*
[root@polo ~]# jls
Of note, you see the services running on the host which are listening
on all IP addresses. This will be a problem for the jails. I will need
to change the host services to listen only on the main IP address for this
host. Sometimes you might want a host service to listen on all IP addresses,
but that's not what I want here.
The -f argument indicates that the jail should be created using
the bacula flavour. This flavour was set up back in March, and
I do not have my notes from that work. I will probably be creating
more flavours and if I do, I will document them.
But I do have a file list. Here is is the list
of files from my bacula ezjail flavour:
NOTE: this attempt failed. You may not want to try this. Read
the whole section first, then see what actually succeeded.
After loggig into the new jail, I noticed my shell was missing my
favourite bash prompt. I decided to copy the required files into the
flavour and refresh the jail.
Now I needed to stop the jail and update its image. Then restart the jail.
# /usr/local/etc/rc.d/ezjail.sh stop
ezjailStopping jails: mysql41.unixathome.org.
# ezjail-admin delete mysql41.example.org
# ezjail-admin create -x -f bacula mysql41.example.org 10.10.10.100
Warning: Some services already seem to be listening on all IP, (including 10.10.10.100)
This may cause some confusion, here they are:
root bacula-fd 1483 3 tcp4 *:9102 *:*
root master 994 11 tcp4 *:25 *:*
root syslogd 815 7 udp4 *:514 *:*
As you can see, I still have a few daemons listening on all addresses. I will
handle that eventually. However, my goal of recreating the jail with my
bash configuration files failed.
What I had to do was delete the jail with the -w option, to wipe
the jail from the HDD. Then create it again:
Now I will create another jail for testing MySQL 5.0:
[root@polo /usr/jails/flavours/bacula]# ezjail-admin create -f bacula mysql50.unixathome.org 10.55.0.101
/usr/jails/mysql50.unixathome.org/COPYRIGHT
/usr/jails/mysql50.unixathome.org/basejail
/usr/jails/mysql50.unixathome.org/bin
/usr/jails/mysql50.unixathome.org/boot
/usr/jails/mysql50.unixathome.org/dev
...
...
/usr/jails/mysql50.unixathome.org/var/cfengine
/usr/jails/mysql50.unixathome.org/var/cfengine/inputs
/usr/jails/mysql50.unixathome.org/var/cfengine/inputs/update.conf
/usr/jails/mysql50.unixathome.org/var/cfengine/master
/usr/jails/mysql50.unixathome.org/var/ports
/usr/jails/mysql50.unixathome.org/var/ports/packages
67260 blocks
Note: Shell scripts installed, flavourizing on jails first startup.
Warning: Some services already seem to be listening on IP 10.55.0.101
This may cause some confusion, here they are:
root ntpd 65252 8 udp4 10.55.0.101:123 *:*
Warning: Some services already seem to be listening on all IP, (including 10.55.0.101)
This may cause some confusion, here they are:
root ntpd 65252 4 udp4 *:123 *:*
[root@polo /usr/jails/flavours/bacula]# /usr/local/etc/rc.d/ezjail.sh
Usage: /usr/local/etc/rc.d/ezjail.sh [fast|force|one](start|stop|restart|rcvar|startcrypto|stopcrypto)
[root@polo /usr/jails/flavours/bacula]# /usr/local/etc/rc.d/ezjail.sh start
ezjailConfiguring jails:.
Starting jails: mysql50.unixathome.org [mysql41.unixathome.org already running
(/var/run/jail_mysql41_unixathome_org.id exists)].
[root@polo /usr/jails/flavours/bacula]#
That's my first cut of using ezjail. I'll be amending and adding to my
flavours as I add more jails. I also plan to use cfengine to configure
the jails, install/upgrade ports, and to undertake general maintenance.
Watch for cfengine in an upcoming article.