Top > FreeBSD > jail fulltree 10.0-Release
FreeBSD 10.0-Releaseにjail fulltreeを導入した時の備忘的まとめです
今後、このfulltreeを使用して minitree を作成していきます
jail fulltree 8.2-Release (i386+512M)
mainte jail fulltree 8.1-RELEASE
common jailstp
以上のサイトを参考にさせていただいております
基本的にはwirednoize様のmainte jail fulltree のそのままです
ですので、詳細はmainte jail fulltree 8.1-RELEASEを参照してください
HOST環境での作業
ftp サーバよりrelease/baseファイルを取得して、jail環境を構築します
'bsdinstall jail' を使用したかったのですが、ダウンロードするアドレスに間違いあって動かなかったので、従来の方法で構築します
# mkdir /tmp/base # cd /tmp/base
# fetch ftp://ftp.jp.freebsd.org/pub/FreeBSD/releases/amd64/10.0-RELEASE/base.txz
# zfs create tank0/jail # zfs create -o mountpoint=/home/mainte tank0/jail/mainte100
# cat base.txz | tar --unlink -xpJf - -C /home/mainte
# mount -t devfs devfs /home/mainte/dev # jail /home/mainte test.localdomain 192.168.100.90 /bin/tcsh
# 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.1' > /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=ftp://ftp3.jp.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR} WRKDIRPREFIX=/tmp DISTDIR=/tmp/distfiles CPUTYPE=nocona CFLAGS= -O2 -fno-strict-aliasing -pipe COPTFLAGS= -O2 -fno-strict-aliasing -pipe
# exit
HOST環境での作業
# vi /usr/local/etc/rc.d/mainte90_jail.sh #!/bin/sh #--------------------------------------- Jid="240" Secu="-1" NtwkIF="lo0" HsFQDN="mainte90.localdomain" IPAdrs="192.168.1.240 BDcast="192.168.1.240" NTmask="255.255.255.255" PsName="mainte90" 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/mainte_jail.sh
/usr/local/etc/rc.d/mainte_jaile.sh start /usr/local/etc/rc.d/mainte_jaile.sh stop
# /usr/local/etc/rc.d/mainte_jail.sh start # jexec 240 /bin/tcsh
JAIL環境での作業
# portsnap fetch && portsnap extract && portsnap update 2回目以降 # portsnap fetch && portsnap update
portsnap fetch の代わりに portsnap cron を使ったスクリプトを記述します
portsnap の実行ログを保存します
後で、ログローテーションの対象にするので、ひたすら追記書きさせます
portsnap を cron で流して ports の自動更新をします。
# mkdir /root/update # cd /root/update # vi 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 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 * N
ports 更新の有無を簡単に知る為に、定期的に portversion のコマンド結果をメールで送信します
# vi portvermail.sh #!/bin/sh #------------------------------------------ MailTO="root" MilTmp=/tmp/pkgversion.txt MilHed="mainte pkg version list" #------------------------------------------ echo $MilHed > $MilTmp echo "" >> $MilTmp /usr/sbin/pkg_version -v >> $MilTmp cat $MilTmp | /usr/bin/mail -s "$MilHed" $MailTO
chmod u+x portvermail.sh
echo '/root/update/portvermail.sh' >> ports_update_cron.sh
ports の更新やインストールに pkg_replace を入れます
# cd /usr/ports/ports-mgmt/pkg_replace # make install clean # rehash
portをインストールする際の設定をmake install でも同じくするためのツールだそうです
# pkg_replace -vcCN ports-mgmt/portconf
ports ソフトウェアの脆弱性をチェックします
# pkg audit -F
毎日 pkg audit のチェック結果をメールで報告させます
#cd /root/update #vi pkg_auditmail.sh #!/bin/sh RanDOM=`jot -r 1 1 1800` /bin/sleep $RanDOM #------------------------------------------ MailTO="root" MilTmp="/tmp/pkg_audit.txt MilHed="pkg audit report" #------------------------------------------ echo $MilHed > $MilTmp echo "" >> $MilTmp /usr/sbin/pkg audit -F >> $MilTmp cat $MilTmp | /usr/bin/mail -s "$MilHed" $MailTO
chmod u+x pkg_auditmail.sh
vi /etc/crontab # pkg audit 1 5 * * * root /root/update/pkg_auditmail.sh > /dev/null 2>&1
結果メールを送信する為に sendmail を起動し、送信後に sendmail を止めるスクリプトを作成します
# vi /root/update/hosts.allow_deny ALL : ALL : deny
# vi /root/update/hosts.allow_mail sendmail : localhost : allow sendmail : 192.168.1.90 : allow sendmail : .localdomain : allow ALL : ALL : deny
cp /etc/rc.conf rc.conf_none
# cp /etc/rc.conf rc.conf_mail # sed -i -e "/^sendmail_/d" /root/update/rc.conf_mail # echo 'sendmail_enable="NO"' >> /root/update/rc.conf_mail
echo 'admin@localdomain' > /root/.forward
#!/bin/sh cp -p /root/update/rc.conf_mail /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 resend.sh
echo '/root/update/resend.sh' >> /root/update/portvermail.sh
echo '/root/update/resend.sh' >> /root/update/portauditmail.sh
freebsd-updateがディレクトリ指定で updateできるようなのでその機能を利用します
# exit
HOST環境での作業
# mkdir /root/update # cd /root/update # vi freebsd-update_cron.sh #!/bin/sh ### HOST用 /usr/sbin/freebsd-update cron #/usr/sbin/freebsd-update install ### mainte jail用 /usr/sbin/freebsd-update -b /home/mainte90 -d /home/mainte90/var/db/freebsd-update fetch /usr/sbin/freebsd-update -b /home/mainte90 -d /home/mainte90/var/db/freebsd-update install
chmod u+x 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