まだ書きかけです
i386機にjail fulltreeを導入した時のまとめです
今後、このfulltreeを使用して minitree を作成していきます
mainte jail fulltree 8.2-RELEASE
mainte jail fulltree 8.1-RELEASE
otsune's FreeBSD memo :: jailの作り方
以上のサイトを参考にさせていただいております
と、wirednoize様のサーバポリシーのどっぷりな感じです
HOST環境での作業
ftp サーバよりrelease/baseファイルを取得して、jail環境を構築します
# mkdir /tmp/base # cd /tmp/base
# fetch ftp://ftp.jp.freebsd.org/pub/FreeBSD/releases/i386/8.2-RELEASE/base/CHECKSUM.MD5 # cat CHECKSUM.MD5 | sed 's/^MD5 (//' | sed 's/).*$//' | \ sed 's/^/ftp:\/\/ftp.jp.freebsd.org\/pub\/FreeBSD\/releases\/i386\/8.2-RELEASE\/base\//'\ | xargs -L1 fetch
# zfs create -o mountpoint=/home/mainte82 tank0/jail/mainte82
# setenv DESTDIR "/home/mainte82" # chmod u+x install.sh # ./install.sh # unsetenv DESTDIR
# mount -t devfs devfs /home/mainte82/dev # jail /home/mainte82 test.localdomain 192.168.100.82
# touch /etc/fstab
# newaliases
# vi /etc/rc.conf network_interface="" rpcbind_enable="NO" inet_enable="NO" syslogd_flags="-ss" sshd_enable="NO" sendmail_enable="NO" sendmail_submit_enable="NO" sendmail_outbound_enable="NO" sendmail_msp_queue_enable="NO"
# echo 'nameserver 192.168.1.251' > /etc/resolv.conf
# vipw root::0:0::0:0:Charlie &:/root:/usr/sbin/nologin toor:*:0:0::0:0:Bourne-again Superuser:/root:/usr/sbin/nologin 上記2行のみ変更
# cp -p /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
# vi /etc/crontab # SHELL=/bin/sh PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin HOME=/var/log # #minute hour mday month wday who command 1 0 * * * root newsyslog その他は削除
# vi /etc/newsyslog.conf # logfilename [owner:group] mode count size when flags [/pid_file][sig_num] /var/log/all.log 600 7 * @T00 - その他は削除
# echo '*.* /var/log/all.log > /etc/syslog.conf # touch /var/log/all.log # chmod 600 /var/log/all.log
# echo 'ALL : ALL : deny' > /etc/hosts.allow
# vi /etc/make.conf WITHOUT_X11=yes WITHOUT_GUI=yes NO_X=true WITHOUT_IPV6=yes WITH_MBSTRING=yes SUPHOST=cvsup3.jp.freebsd.org MASTER_SITE_OVERRIDE=ftp3.jp.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR} WRKDIRPREFIX=/tmp DISTDIR=/tmp/distfiles CPUTYPE=i686 CFLAGS= -O2 -fno-strict-aliasing -pipe COPTFLAGS= -O2 -fno-strict-aliasing -pipe
# exit
HOST環境での作業
# vi /usr/local/etc/rc.d/mainte82_jail.sh #!/bin/sh #--------------------------------------- Jid="82" Secu="-1" NtwkIF="lo0" HsFQDN="mainte82.localdomain" IPAdrs="192.168.1.82" BDcast="192.168.1.82" NTmask="255.255.255.255" PsName="mainte82" ChRoot="/home/$PsName" MTdpnf="$ChRoot/dev /tmp/$PsName/tmp $ChRoot/tmp" #---------------------------------------------------------------------- BFsrtJ="/bin/mkdir -p /tmp/$PsName/tmp/distfiles /bin/chmod 1777 /tmp/$PsName/tmp /sbin/mount -t zfs tank0/ports /home/$PsName/usr/ports" AFsrtJ="" BFstpJ="jexec Jid /bin/sh /etc/rc.shutdown" AFstpJ="/bin/rm -rf /tmp/$PsName" Jstcom="/bin/sh /etc/rc" #--------------------------------------- . /usr/local/etc/rc.d/common_Njailstp.file jailstartop $1
chmod u+x /usr/local/etc/rc.d/mainte82_jail.sh
/usr/local/etc/rc.d/mainte82_jaile.sh start /usr/local/etc/rc.d/mainte82_jaile.sh stop
# /usr/local/etc/rc.d/mainte82_jail.sh start # jexec 82 /bin/tcsh
JAIL環境での作業
# ls /etc/portsnap.conf
初回 # portsnap fetch && portsnap extract && portsnap update 2回目以降 # portsnap fetch && portsnap update
portsnap fetch の代わりに portsnap cron という cron 動作用のコマンドがあり、1秒から3600秒の間でランダムに時間を遅らせる機能を持っているので、それを使ったスクリプトを記述します
portsnap の実行ログを保存します
後で、ログローテーションの対象にするので、ひたすら追記書きさせます
portsnap を cron で流して ports の自動更新をします。
# mkdir /root/update # vi /root/update/ports_update_cron.sh #!/bin/sh LogFile="/var/log/ports_update.log" echo "### `date` ###" >> $LogFile /usr/sbin/portsnap cron >> $LogFile 2>&1 /usr/sbin/portsnap update >> $LogFile 2>&1 echo "### `date` ###" >> $LogFile
# vi /root/update/port_update.sh #!/bin/sh /usr/sbin/portsnap fetch /usr/sbin/portsnap update
# chmod u+x ports_update.sh ports_update_cron.sh
vi /etc/crontab # portsnap ports_update 1 9 * * 1,4 root /root/update/ports_update_cron.sh > /dev/null 2>&1
vi /etc/newsyslog.conf # logfilename [owner:group] mode count size when flags [/pid_file][sig_num] /var/log/all.log 600 7 * @T00 - /var/log/ports_update.log 600 7 1 *
ports 更新の有無を簡単に知る為に、定期的に portversion のコマンド結果をメールで送信します
今の設定ではメールを送れないので、後の「sendmail の設定」も必ず行ってください
# vi portvermail.sh #!/bin/sh #------------------------------------------ MailTO="root" MilTmp=/tmp/portversion.txt MilHed="mainte portversion info" #------------------------------------------ echo $MilHed > $MilTmp echo "" >> $MilTmp /usr/sbin/pkg_version -v >> $MilTmp cat $MilTmp | /usr/bin/mail -s "$MilHed" $MailTO
chmod u+x /root/update/portvermail.sh
echo '/root/update/portvermail.sh' >> /root/update/ports_update_cron.sh
ports の更新やインストールに pkg_replace を入れます
portupgrade では、依存パッケージがたくさん入ってしまいますが、pkg_replace なら一切入りません
# cd /usr/ports/ports-mgmt/pkg_replace # make install cleanハッシュテーブルの再構築
rehash
portをインストールする際の設定をmake install でも同じくするためのツールだそうです
# pkg_replace -vcCN ports-mgmt/portconf
ports ソフトウェアの脆弱性をチェックします。これに引っかかったアプリケーションは速やかなアップデートが必要となります
# pkg_replace -vcCN ports-mgmt/portaudit
# /usr/local/sbin/portaudit -Fda
毎日 portaudit のチェック結果をメールで報告させます
jot コマンドを利用して、1秒から 1800秒の間でランダムに sleep をさせています
今の設定ではメールを送れないので、後の「sendmail の設定」も必ず行ってください
#vi /root/update/portauditmail.sh #!/bin/sh RanDOM=`jot -r 1 1 1800` /bin/sleep $RanDOM #------------------------------------------ MailTO="root" MilTmp="/tmp/portaudit.txt" MilHed="ports vulnerabilities report" #------------------------------------------ echo $MilHed > $MilTmp echo "" >> $MilTmp /usr/local/sbin/portaudit -Fdav >> $MilTmp cat $MilTmp | /usr/bin/mail -s "$MilHed" $MailTO MailTO には自分の送りたいメールアドレスを指定します
chmod u+x /root/untidy/portauditmail.sh
vi /etc/crontab # portaudit 1 5 * * * root /root/untidy/portauditmail.sh > /dev/null 2>&1
結果メールを送信する為に sendmail を起動し、送信後に sendmail を止めるスクリプトを作成します
# vi /root/update/host.allow_deny ALL : ALL : deny
# vi /root/update/hosts.allow_mail sendmail : localhost : allow sendmail : 192.168.1.82 : allow sendmail : .localdomain : allow ALL : ALL : deny'
cp /etc/rc.conf /root/update/rc.conf_none
# cp /etc/rc.conf /root/update/rc.conf_no # sed -i -e "/^sendmail_/d" /root/update/rc.conf_no # echo 'sendmail_enable="NO"' >> /root/update/rc.conf_no
echo 'admin@localdomain' > /root/.forward
# vi /root/update/resend.sh #!/bin/sh cp -p /root/update/rc.conf_no /etc/rc.conf cp -p /root/update/hosts.allow_mail /etc/hosts.allow sh /etc/rc.sendmail start sleep 6 sh /etc/rc.sendmail stop sleep 4 pkill sendmail cp -p /root/update/hosts.allow_deny /etc/hosts.allow cp -p /root/update/rc.conf_none /etc/rc.conf
# chmod u+x /root/update/resend.sh
echo '/root/update/resend.sh' >> /root/update/ports_update_cron.sh
echo '/root/update/resend.sh' >> /root/update/portauditmail.sh
freebsd-updateがディレクトリ指定で updateできるようなのでその機能を利用します
# exit
HOST環境での作業
# vi /rootfreebsd-update_cron.sh #!/bin/sh ### HOST用 /usr/sbin/freebsd-update cron #/usr/sbin/freebsd-update install ### mainte jail用 /usr/sbin/freebsd-update -b /home/mainte82 -d /home/mainte82/var/db/freebsd-update fetch /usr/sbin/freebsd-update -b /home/mainte82 -d /home/mainte82/var/db/freebsd-update install
chmod u+x /root/freebsd-update_cron.sh
vi /etc/crontab # freebsd-update 0 6 * * 2,4,6 root /root/freebsd-update_cron.sh > /var/log/freebsd-update.log 2>&1
echo 'admin@localdomain' > /root/.forward