FreeBSD Multi Jails

多 Jails 設置,如果要跑多個 Jails 很多東西可以共用,像是 lib 之類的

建立 Base System

# mkdir /home/jails /home/jails/base
# cd /usr/src
# make installworld DESTDIR=/home/jails/base

安裝 cpdup

# cd /usr/ports/sysutils/cpdup/
# make install clean

複製 /usr/src 到 Jail base system

# cpdup /usr/src /home/jails/base/usr/src

打造骨架

# mkdir /home/jails/skel /home/jails/skel/home /home/jails/skel/usr-X11R6/home/jails/skel/distfiles
# mv etc /home/jails/skel
# mv usr/local /home/jails/skel/usr-local
# mv tmp /home/jails/skel
# mv var /home/jails/skel
# mv root /home/jails/skel

安裝設定檔

# mergemaster -t /home/jails/skel/var/tmp/temproot -D /home/jails/skel -i
# cd /home/jails/skel/
# rm -R bin boot lib libexec mnt proc rescue sbin sys usr dev

連結檔案

# cd /home/jails/base
# mkdir s
# ln -s s/etc etc
# ln -s s/home home
# ln -s s/root root
# ln -s ../s/usr-local usr/local
# ln -s ../s/usr-X11R6 usr/X11R6
# ln -s ../../s/distfiles usr/ports/distfiles
# ln -s s/tmp tmp
# ln -s s/var var

編輯設定檔

# joe /home/jails/skel/etc/make.conf
WRKDIRPREFIX?=  /s/portbuild

編輯 fstab

# joe /etc/fstab
/home/jails/base   /home/jails/wiki1    nullfs  ro  0   0
/home/jails/base   /home/jails/wiki2    nullfs  ro  0   0
/home/vs/wiki1     /home/jails/wiki1/s  nullfs  rw  0   0
/home/vs/wiki2     /home/jails/wiki2/s  nullfs  rw  0   0

編輯 rc.conf

jail_enable="YES"
jail_set_hostname_allow="NO"
jail_list="wiki1 wiki2"

jail_wiki1_rootdir="/home/jails/wiki1"
jail_wiki1_hostname="wiki1.j.mis.au.edu.tw"
jail_wiki1_ip="192.168.1.100"
jail_wiki1_devfs_enable="YES"

jail_wiki2_rootdir="/home/jails/wiki2"
jail_wiki2_hostname="wiki2.j.mis.au.edu.tw"
jail_wiki2_ip="192.168.1.101"
jail_wiki2_devfs_enable="YES"

建立 mount point

# mkdir /home/jails/wiki1 /home/jails/wiki2

建立子 Jails 及複製骨架

# mkdir /home/vs
# cpdup /home/jails/skel /home/vs/wiki1
# cpdup /home/jails/skel /home/vs/wiki2  

設定 IP

# ifconfig em1 inet 192.168.1.100 alias
# ifconfig em1 inet 192.168.1.101 alias

啟動 Jails

# mount -a
# /etc/rc.d/jail start
# jls
   JID  IP Address      Hostname                      Path
     2  192.168.1.101   wiki2.j.mis.au.edu.tw         /home/jails/wiki2
     1  192.168.1.100   wiki1.j.mis.au.edu.tw         /home/jails/wiki1

連結 Host 的 Ports

# mkdir -p /home/jails/base/usr/ports/
# mount_nullfs /usr/ports /home/jails/wiki1/usr/ports/
# mount_nullfs /usr/ports /home/jails/wiki2/usr/ports/

這樣就大致完成

Follow 院長與芊比媽 on Google News