ejzailã使ã£ãVIMAGE対å¿jailã®ä½ãæ¹
èæ¯
NFS ãµã¼ãã®ã¡ã¢ãªãä½ã£ã¦ããã®ãå¿ä½ç¡ãã®ã§ jail ç°å¢ãæ§ç¯ãããã¨æã£ãï¼
ããããªããï¼é常㮠jail ç°å¢ã®ä½ãæ¹ã§ã¯ï¼ãã¹ã OS ã® NIC ã« jail ç°å¢ç¨ IP ã¢ãã¬ã¹ã alias ããå¿
è¦ãããï¼NFS ã¯åãå¾
ã¡ IP ã¢ãã¬ã¹ãæå®ã§ããªãããï¼jail ç°å¢ç¨ IP ã¢ãã¬ã¹ã§ NFS ãµã¼ãã¹ãå¾
ã¡åãã¦ãã¾ãï¼ããã¯æå³ããªããã¨ãªã®ã§ãããããªãï¼
ã¨ãããã¨ãããã£ãã®ã§ãã¤ã¼ããããï¼VIMAGE ã§ããããï¼ã¨æãã¦ããã£ãã®ã§ ezjail ã使ã£ã¦ VIMAGE å¯¾å¿ jail ãä½ã£ã¦ã¿ãï¼
ï¼è¿½è¨ï¼
nfsd ã« -h [bindip] ã¨ãããªãã·ã§ã³ããããããï¼ããã使ãã°ããã£ããããããªãï¼
KVM ã¨ã®æ¯è¼
KVM ã 㨠vnet ã¤ã³ã¿ã¼ãã§ã¼ã¹ãèªåã§çæãã¦ããããï¼ããã« libvirt ã使ãã°ããªãã¸ã¾ã§è¡ãªã£ã¦ããããï¼ jail ã ezjail ã§ã¯ããã¾ã§ãã£ã¦ãããªãï¼
vnet ã¤ã³ã¿ã¼ãã§ã¼ã¹ç¸å½ã§ãã epair ã¤ã³ã¿ãã§ã¼ã¹ï¼epair0a, epair0b ã®æ§ãªãã¢ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ãã§ããï¼ãä½ã£ã¦çæ¹ãã²ã¹ã OS ã«æã£ã¦è¡ãã°ï¼ãã¹ã OS ã¨ã²ã¹ã OS ãããªãã¸ã®ããã«ç¹ããï¼ã¾ãï¼ãã¹ã OS å´ã® epair ã¨å¤ã«ç¹ããã¤ã³ã¿ã¼ãã§ã¼ã¹ãããªãã¸ãããã¨ã§ã²ã¹ã OS ã¯å¤ã¨ç¹ãããã¨ãã§ããï¼
ezjail ã®ã¡ã¢
- ports 㯠sysutils/ezjail
- è¨å®ãã¡ã¤ã«ã¯ /usr/local/etc/ezjail.conf
- ããã©ã«ãã 㨠ezjail ã®ã«ã¼ã㯠/usr/jails
- /usr/jails/basejail ã«ãã¤ããªãããï¼
- /usr/jails/newjail ã¯å jail ã®ã¹ã±ã«ãã³ï¼ããªã¼æ§é ãéè¦ï¼ãã¤ããªã®å®ä½ã¯ /usr/jails/basejailï¼å¿ è¦ãªãã®ã ããã·ã³ããªãã¯ãªã³ã¯ã§æã£ã¦ããï¼
- /usr/jails/flavour ã¯å jail æ¯ã«è¨å®ãã¡ã¤ã«çãä¸æ¸ãããã®ã«ä½¿ãï¼puppet ã¨é£æºãããã¨ä¾¿å©ã¨æã£ãï¼
- jail ã®ä½ãæ¹ï¼ezjail-admin create -f [flavour] [name] 0.0.0.0 ï¼ã¢ãã¬ã¹ã¯æçµçã«æ¶ãã®ã§é©å½ã§OKï¼
- å jail ã®è¨å®ãã¡ã¤ã«ï¼å jail ã®ã«ã¼ããã£ã¬ã¯ããªã IP ã¢ãã¬ã¹çï¼ï¼/usr/local/etc/ezjail/[name]
- jail ç°å¢ãä½ã£ãããããã¨
- /etc/fstab.[name] ãç·¨éï¼/usr/ports, /home ããã¦ã³ãããããã«ããï¼
- /usr/local/etc/ezjail/[name] ãç·¨éï¼IP ã¢ãã¬ã¹ãæ¶ãï¼å¾ã¯å¾è¿°ã®å¤æ´ãããï¼
åé¡ç¹ã¨èª²é¡ã®æ´ç
ezjail ã®ããã©ã«ãã§ã¯ä»¥ä¸3ç¹ã®åé¡ç¹ãããããã« ejzail ã ãã使ã£ã VIMAGE å¯¾å¿ jail ã®ä½æãåºæ¥ãªãï¼
- VIMAGE ã¯å¯¾å¿ jail ã«ããã«ã¯ jail ã« -c vnet ãªãã·ã§ã³ã渡ãå¿ è¦ããããï¼/etc/rc.d/jail 㯠-c ãªãã·ã§ã³æå®æã®ãã©ã¼ãããã«å¯¾å¿ãã¦ããªã*1ããï¼ç´ ã® /etc/rc.d/jail ã¯ä½¿ããªãï¼
- ããã©ã«ãã® devfs ã®ãã¦ã³ãæ¹æ³ã¯ VIMAGE 対å¿ãåæã¨ãã¦ããªãããï¼jail ç°å¢ã« /dev/*mem ããªãï¼jail ç°å¢ã§ã«ã¼ãã£ã³ã°ãåºæ¥ãªãï¼
- é常㮠jail ã¨ã¯éã£ã¦èµ·åæã« IP ã¢ãã¬ã¹ãå²ãå½ã¦ãªãï¼ãã®ããã²ã¹ãå´ã§ IP ã¢ãã¬ã¹è¨å®ï¼ã«ã¼ãã£ã³ã°è¨å®ï¼ãµã¼ãã¹(sshdç)å®è¡ã jail ç°å¢ãç«ã¡ä¸ããå¾ã«è¡ãå¿ è¦ãããï¼
ããã§ã¯èª²é¡ã¨ãã¦ã¯ä»¥ä¸ã®3ç¹ããããï¼
- /etc/rc.d/jail 㧠-c vnet ãªãã·ã§ã³ã使ããããã«ã㦠VIMAGE å¯¾å¿ jail ãä½æã§ããããã«ããï¼
- jail ç°å¢ã§ /dev/*mem ã使ããããã«ããï¼
- jail ç°å¢ãèµ·åããå¾ã« epair ã¤ã³ã¿ã¼ãã§ã¼ã¹ã渡ãã¦ï¼IP ã¢ãã¬ã¹ã®è¨å®ï¼ã«ã¼ãã£ã³ã°ã®è¨å®ï¼ãµã¼ãã¹ã®ç«ã¡ä¸ããè¡ãããã«ããï¼
以ä¸ã§3ã¤ã®èª²é¡ã«å¯¾ãã解決æé ãã¾ã¨ããï¼
解決çï¼1ã¤ç®ï¼ï¼/etc/rc.d/jail 㧠VIMAGE å¯¾å¿ jail ãä½æã§ããããã«ãã
ã¾ã㯠jail ã«æ¸¡ããªãã·ã§ã³ã/etc/rc.conf ã«è¨å®ããï¼
- /etc/rc.conf
jail_flags="-c vnet"
次ã«ãã®ãªãã·ã§ã³ã解éã§ããããã« /etc/rc.d/jail ãæ¸ãæããï¼
ããã©ã«ãã§ã¯ -c ãªãã·ã§ã³ç¡ããªã®ã§ã¹ãã¼ã¹åºåã㧠path hostname [ip[,..] ] command ã渡ãã¦ãããï¼-c ãªãã·ã§ã³æå®æã¯parameter=valueå½¢å¼ã§æå®ããå¿
è¦ãããï¼
- /etc/rc.d/jail
> diff -u /etc/rc.d/jail /usr/src/etc/rc.d/jail --- /etc/rc.d/jail 2011-05-06 00:18:19.000000000 +0900 +++ /usr/src/etc/rc.d/jail 2010-12-22 02:09:25.000000000 +0900 @@ -635,10 +635,8 @@ i=$((i + 1)) done - eval ${_setfib} jail -J ${_tmp_jail}_ ${_flags} host.hostname=${_hostname} name=`echo ${_hostname} | cut -f 1 -d .` \ - path=${_rootdir} persist - cat ${_tmp_jail}_ | cut -f 1 -d " " | cut -f 2 -d = > ${_tmp_jail} - rm -f ${_tmp_jail}_ + eval ${_setfib} jail ${_flags} -i ${_rootdir} ${_hostname} \ + \"${_addrl}\" ${_exec_start} > ${_tmp_jail} 2>&1 if [ "$?" -eq 0 ] ; then _jail_id=$(head -1 ${_tmp_jail}) @@ -699,7 +697,9 @@ eval env -i /usr/sbin/jexec ${_jail_id} ${_exec_stop} \ >> ${_consolelog} 2>&1 fi - jail -r ${_jail_id} + killall -j ${_jail_id} -TERM > /dev/null 2>&1 + sleep 1 + killall -j ${_jail_id} -KILL > /dev/null 2>&1 jail_umount_fs echo -n " $_hostname"
解決çï¼2ã¤ç®ï¼ï¼jail ç°å¢ã§ /dev/*mem ã使ããããã«ãã
devfs ããã¦ã³ãããã¨ãã«ã©ã®ããã¤ã¹ã使ããããã«ããã㯠/etc/default/devfs.rules ã«æ¸ãã¦ããã«ã¼ã«ã«å¾ã£ã¦ããï¼ã©ã®ã«ã¼ã«ã使ãã㯠/usr/local/etc/ezjail/[name] ã®å¤æ° jail_[name]_devfs_ruleset ã§æå®ãã¦ããï¼
ã«ã¼ã«ãè¦ã㨠devfsrules_unhide_basicã«ããã° /dev/*mem ã使ããããªã®ã§ï¼ /usr/local/etc/ezjail/[name] ã以ä¸ã®ããã«å¤æ´ããï¼
- /usr/local/etc/ezjail/[name]
- i.e. /usr/local/etc/ezjail/cattleya02_osaka_remu
export jail_cattleya02_osaka_remu_devfs_ruleset="devfsrules_unhide_basic"
解決çï¼3ã¤ç®ï¼ï¼jail ç°å¢ãèµ·åããå¾ã« epair ã¤ã³ã¿ã¼ãã§ã¼ã¹ã渡ãã¦ï¼IP ã¢ãã¬ã¹ã®è¨å®ï¼ã«ã¼ãã£ã³ã°ã®è¨å®ãè¡ãããã«ãã
/usr/local/etc/ezjail/[name] ã® jail_[name]_exec_xxx ã«è¨å®ãããã¨ã§ jail èµ·åæã«ãã¹ã OS å´ï¼ã²ã¹ã OS å´ã§ä»»æã®ã³ãã³ããå®è¡åºæ¥ãï¼ã³ã¬ã使ã£ã¦ epair ã¤ã³ã¿ã¼ãã§ã¼ã¹ã渡ãããï¼ã²ã¹ã OS å´ã® IP ã¢ãã¬ã¹è¨å®çãè¡ãï¼
ã²ã¹ã OS å´ã§å®è¡ãã¦ããã afterstart ããã¾ãåããªãã£ãã®ã§ï¼ãã¹ã OS å´ãã jexec ã³ãã³ãã使ã£ã¦ã²ã¹ã OS å´ã®è¨å®ãããï¼ä»¥ä¸ã®å
容ã /usr/local/etc/ezjail/[name] ã«è¿½å ããï¼
- /usr/local/etc/ezjail/[name]
- i.e. /usr/local/etc/ezjail/cattleya02_osaka_remu
export jail_cattleya02_osaka_remu_exec_prestart0="ifconfig epair0 create" export jail_cattleya02_osaka_remu_exec_prestart1="ifconfig epair0a up" export jail_cattleya02_osaka_remu_exec_prestart2="ifconfig bridge0 addm epair0a" export jail_cattleya02_osaka_remu_exec_poststart0="ifconfig epair0b vnet cattleya02" export jail_cattleya02_osaka_remu_exec_poststart1="jexec cattleya02 /sbin/ifconfig epair0b 10.3.2.21/24" export jail_cattleya02_osaka_remu_exec_poststart2="jexec cattleya02 /sbin/route add default 10.3.2.1" export jail_cattleya02_osaka_remu_exec_poststart3="jexec cattleya02 /etc/rc.d/sshd start" export jail_cattleya02_osaka_remu_exec_poststop0="ifconfig bridge0 deletem epair0a" export jail_cattleya02_osaka_remu_exec_poststop1="ifconfig epair0a destroy"
åè
hasegaw blog: FreeBSD VIMAGEを使ったTCP/IPのルーティング デモンストレーション
- VIMAGE æ¦è¦ã¨è¨å®ä¾ã«ã¤ãã¦åèã«ãã¾ãã
http://www.jp.freebsd.org/cgi/mroff.cgi?subdir=man&lc=1&cmd=&man=jail&dir=jpman-5.2.0%2Fman§=8
- NFS ãµã¼ãä¸ã§ jail ç°å¢ã§æ§ç¯ããã®ããªãããããç¡ãã®ããåèã«ãã¾ãã
- prestart, poststart ã®å®è¡ç°å¢ï¼ã¿ã¤ãã³ã°ãåèã«ãã¾ãã
*1:jail ã« -c ãªãã·ã§ã³ã使ãã¨ãã以å¤ã®å¼æ°ãå¤ããããï¼ezjailã®ã¹ã¯ãªãããæ¸ãæããå¿ è¦ããã