2928272625/ 24/ 2322212019
------------------------------------------------------------------------

jail環境構築(ezjail)

HOST 192.168.110.5
jail    192.168.110.6
------------------------------------------------------------------------

***************************************
ezjailインストール
***************************************

# cd /usr/ports/sysutils/ezjail/
# make install clean
# cp -p /usr/local/etc/ezjail.conf.sample /usr/local/etc/ezjail.conf

# vi /usr/local/ezjail.conf

////////////////////////////////////////////////////////////////////////////
# Location of jail root directories
#
# Note: If you have spread your jails to multiple locations, use softlinks
# to collect them in this directory
ezjail_jaildir=/usr/jails

# Location of the tiny skeleton jail template
ezjail_jailtemplate=${ezjail_jaildir}/newjail

# Location of the huge base jail
ezjail_jailbase=${ezjail_jaildir}/basejail

# Location of your copy of FreeBSD's source tree
ezjail_sourcetree=/usr/src

# In case you want to provide a copy of ports tree in base jail, set this to
# a cvsroot near you
# ezjail_portscvsroot=:pserver:anoncvs@anoncvs.at.FreeBSD.org:/home/ncvs
#ezjail_portscvsroot=":pserver:anoncvs@anoncvs.jp.FreeBSD.org:/home/ncvs"
# This is where the install sub command defaults to fetch its packages from
# ezjail_ftphost=ftp.freebsd.org

# base jail will provide a soft link from /usr/bin/perl to /usr/local/bin/perl
# to accomodate all scripts using '#!/usr/bin/perl'...
# ezjail_uglyperlhack="YES"

# Default options for newly created jails
#
# Note: Be VERY careful about disabling ezjail_mount_enable. Mounting
# basejail via nullfs depends on this. You will have to find other
# ways to provide your jail with essential system files
ezjail_mount_enable="YES"
ezjail_devfs_enable="YES"
ezjail_devfs_ruleset="devfsrules_jail"
ezjail_procfs_enable="YES"
ezjail_fdescfs_enable="YES"
////////////////////////////////////////////////////////////////////////////

# ezjail-update //長時間掛かるので注意

jail-remove.txtで不要なファイルを削除

# fetch http://memberwebs.com/stef/freebsd/jails/docs/6.x/jail-remove.txt
# sed "s#^/#/usr/jails/newjail/#" < jail-remove.txt | xargs rm -rfv
# sed "s#^/#/usr/jails/basejail/#" < jail-remove.txt | xargs rm -rfv

/usr/jails 158MB
jail-remove.txtで余計なファイルを消して121M

host# vi /etc/rc.conf
ezjail_enable="YES"
inetd_flags="-wW -C 60 -a 192.168.110.5"
ifconfig_fxp0_alias0="inet 192.168.110.6 netmask 255.255.255.255"
rpcbind_enable="NO" //ポートマッパーを止める

aliasの設定
host# ifconfig fxp0 inet 192.168.110.6 netmask 255.255.25.255 alias

jailでpingやtracerouteが使えるようにする。
host# vi /etc/sysctl.conf
security.jail.allow_raw_sockets=1

jailにSSHをアクセス
host# vi /etc/ssh/sshd_config
ListenAddress 192.168.110.5

このまま環境作ろうとすると

Warning: Some services already seem to be listening on all IPと出るので一度再起動。

jail環境構築
host# ezjail-admin create virtual 192.168.110.6 //一瞬で終わる。

jailにログイン
host# jexec 1 /bin/tcsh //JIDは変わる時があるのでjlsコマンドで確認すること


パスワード変更やユーザ追加
jail# passwd root
jail# adduser hoge
ホストのほうから.cshrcをコピーしておく。


ログアウトしてホストでcrontabをコメントアウト
host# exit
vi /usr/jails/virtual/etc/crontab
1,31 0-5 * * * root adjkerntz -a

/etc/fstab の設定
host# touch /usr/jails/virtual/etc/fstab

resolv.conf の設定をして名前解決出来るようにする

host# cp /etc/resolv.conf /usr/jails/virtual/etc/

ローカルタイムの設定
host# cd /usr/jails/virtual/etc
host# touch wall_cmos_clock
host# ln -sf ../usr/share/zoneinfo/Asia/Tokyo localtime

# vi /usr/jails/virtual/etc/rc.conf
defaultrouter="192.168.110.5"
hostname="virtual.example.com"
network_interfaces="" //ネットワークインターフェースの設定を無効
inetd_enable="YES"
inetd_flags="-wW -C 60 -a 192.168.110.6"
rpcbind_enable="NO" //ポートマッパーを無効
sendmail_enable="NONE" //sendmailを無効
sendmail_submit_enable="NONE"
sendmail_outbound_enable="NONE"
sendmail_msp_queue_enable="NONE"
sshd_enable="YES"
sshd_flags="-4"
syslogd_flags="-ss"
tcp_keepalive="NO"
tcp_extensions="NO"
cron_flags="-J 15"

/usr/jails/virtual/etc/ssh/sshd_config に一行加えます
ListenAddress 192.168.110.6

/usr/jails/virtual/etc/inetd.confや/usr/jails/virtual/etc/namedb/named.conf を編集する

jailでportsが使えるようにportsツリーのマウントポイントの設定
host# vi /etc/fstab //ホスト環境
/usr/ports /usr/jails/virtual/basejail/usr/ports nullfs ro,noauto 0 0
/usr/src /usr/jails/virtual/basejail/usr/src nullfs ro,noauto 0 0

portsの書き込み用ディレクトリ作成
jail# mkdir /var/ports
jail# mkdir /var/ports/distfiles
jail# mkdir /var/ports/packages

jail#/etc/make.conf
WRKDIRPREFIX= /var/ports
DISTDIR= /var/ports/distfiles
PACKAGES= /var/ports/packages
WITHOUT_X11=yes


portsツリーをマウント
host# mount /usr/jails/virtual/basejail/usr/portshost
host# mount /usr/jails/virtual/basejail/usr/src


今のままだとnullfsが使えないのでkldstatでカーネルモジュール一覧を確認。
nullfs.koがなければkldload nullfsで読み込む。

参考
FreeBSDでサーバの仮想化技術「jail」を使った複数ドメインでの運用

ezjailでFreeBSDのjailを作る
>>commemt
name
tittle
color 反転用
mail
url
text
pass   Vodafone絵文字 i-mode絵文字 Ezweb絵文字
>>trackback
この記事にトラックバックする>>
  top  
忍者ブログ [PR]通販 入院保険


Copyright (C) 2007-2010 大塚味噌醸造所 All Rights Reserved.