Ȼ/05

Top / Ȼ / 05

Unix ưƤȤ

unix Ȥ OS ưƤȤȤϡ桼ФƤޤޤľܤ˱򤹤ǤϤʤ.
ޤޤʱ֥ӥפ뤿ˡظǾưƤ륽եȥäꡤ׵˱ƥեȥưŪΩ夬äꡤŪ˵ưꤹ륽եȥ.

˾̤ΥӥԤ碌뤿ǤϤʤưθΨ̤⥻ƥ̤⤳եȥκߤΤ뤳ȤɬפǤ.
ϤּưŪ˵ư륽եȥפˤĤƳؤ.

ưƤ륽եȥ

unix ˸¤餺٤εϤ OS ǤϤޤޤʥӥ󶡤뤿˾ưƤ륽եȥ¸ߤ.

ưƤ륽եȥ򸫤ˤ?

ps -axu 

ȤƤߤȡƤΥץ.
٤ʸɽڤƤޤɤɤʤȤϡ

 ps -axuww

ʤɤȤ褦.

 top

ȤȡץξưŪˤߤġcpu ξʤɤߤ.

lsof -i4 -i6 
lsof -i4 -i6 -P

Ȥȡɤ port ǤɤʥեȤԤƤ뤫ʬ(root Ǥ٤).
lsof ϥ󥹥ȡ뤬ɬפ. ports 餵äȥ󥹥ȡ뤷Ƥ.

½

lsof 򥤥󥹥ȡ뤷Ƥ.

kernel

OS ΤΡˤǤ륽եȥ̾ kernel ȸƤФ졤ưƤ.
kernel ܤϤ OS ưեȥȡƥեȥ˻(ꡤϡɥǥ I/O )󶡤뤳Ȥˤ.
ŪˤϡCPU ʤɤΥϡɥδŪ桤ξǤŪʻ(ۥʤ)ι, ƥեȥؤλ񸻳*1ʤɤǤ, unix OS Υեȥǡ֤äȤפʥեȥΰġפǤ.

kernel ϸߤ FreeBSD Ǥ /boot/kernel ǥ쥯ȥˤ.

kernel ưѤˤϡѤˡ kernel Ȥ򥳥ѥ뤷ƺľˡ*2.
ܤ񤯤Ȱʲ̤Ǥ롥

  • ưѤˡ
    • ֡ȥˡäơפǼưǽ񤭴: ưΥ˥塼Ф 6 ٤Х. ξǤ ? 򲡤лȤ륳ޥɤФ. Ǻä顤autoboot Ȥ̤̾굯ưΤǤȤ.
    • /boot/loader.conf 񤭴ƤƤ()ư. եΥǥե /boot/defaults/loader.conf ˤΤǤߤƤߤ褦.
  • ưѤˡ.
    • sysctl Ȥ. ߤʤʤΤǡroot
       sysctl -a -h | less
      ʤɤȤƤߤ褦. ʤߤˡ񤭴Ƥߤ sysctl -w Ǥ뤬ޤꤪᤷʤ(^-^)
    • ͥ⥸塼Υ,ɤԤ. ޥɤ kldload kldunload . ǥХɥ饤Ф򤢤줳Ѥʤɤˤäˤʤ.
  • ͥ򥳥ѥ뤷ƺäƤޤ(ʤ٤ޥǽ)
    ̤ϡ/usr/src/sys/i386/conf ˤ GENERIC ե򥳥ԡƽ񤭴Ƥ饳ѥ뤷ľȤƧ.
    ˤǽ񤭤ʤΤǡFreeBSD θŪǤ ϥɥ֥å(FreeBSDͥΥե졼) Ҳ𤷤Ƥ.
    μˡFreeBSD Ρǽפ礭Ѥ뤳ȤǤΤǡޥӤˤäƤϥͥκƥѥƤ褤.

½

äƤߤ褦.
sysctl ɽįơʬʬʤõƤߤ.

init

unix OS ǡ֥ץפȤưռץ/ץƤΡֻġץץǤ.
̾ pid 1 Ǥ*3.

unix Ǥ init ƤץϡֿƥץפäƤꡤƥץȤˤϤλҥץ̤ȤˤʤäƤ.
ǤΤǡƤΥץα󤤿Ƥˤ init ̤ȥƥब֡Ȥʤɡinit εưϥƥΤ礭ʱƶͿ.
init ϵư塤/etc/rc, /etc/rc.subr, /etc/rc.conf ʤɤɤߡ˽äƼ /etc/rc.d/ʲˤ뤵ޤޤ daemon ưȤή͡ʥեȥư.
ܤϡinit Υޥ˥奢򻲾Ȥ줿.

½

init Υޥ˥奢ɤȥͥΥƥ٥ˤĤƤεҤ.
sysctl νϤǤΤϤɤĴ٤*4.
ơͤɤʤäƤ뤫Ĵ٤.

ޤinit Υޥ˥奢ɤȡkill ۤۤ 1 ˤĤƤĤ⤬ܤäƤ.
򤷤ǡ

 kill -INT 1

ԤäƤߤ(root ǤʤȽʤ⤷ʤ).

Daemon

ʤ餫Υӥ󶡤뤿˥Хå饦ɤǾưƤ(⤷ϸƤӽФ줿¨ư)եȥϰ̤ daemon (󡤥ǡ)*5ȸƤФ.
٤ unix DzǤΤ daemon ߤʬ.
ޤϤɤ daemon ưƤΤ̾ǤߤƤߤ褦.

½

ps, top, lsof ˤĤƤ򤷤ƤߤơߤɤΤ褦ʥեȥ(daemon)ưƤơɤԤפ򤷤Ƥ뤫¬Ƥߤ.

ӥ׵᤬äȤ˵ư륽եȥ

˥Хå饦ɤǥեȤưƤ뤳ȤˤϼΤ褦ȷ.

  • ȿǤ()
  • CPU 򤽤ʤ˾񤹤(

ǡ֤ޤɬפʻ뤬ä˿®ʥ쥹ݥ󥹤ʤȤ褤פȤӥˤĤƤϡָƤФƤ鵯ưפȤ褦ꤷƤ̵̤ʤ.
Ӥ˻ȤΤ֥ѥС"inetd" *6Ǥ.
inetd Ω夲ƤСɬפ˱ƸƤФ줿եȥư³ƤΤ.
inetd ϤΡפ椨˥ƥŪʴˤ⤿餷䤹ᡤǶϥǥեȤǤưƤʤȤ¿ΤǡưݤˤŪꤷʤȤʤȤդ褦.

inetd Ȥˤ

inetd Ȥˤϡ

  1. /etc/inetd.conf ǸƤФ줿Ω夬륽եȥ򤹤.
  2. inetd ⤽Ω夬äƤʤʤΩ夲.
  3. ³ɬפʥեȤξϡ³ĤФƤ.

ȤʳƧФ褤.
ʲ褦.

inetd Ȥˤ: /etc/inetd.conf ν񤭴

/etc/inetd.conf 򸫤ȼ㤬񤫤쥳ȥȤƤΤǡ褽Ϥ狼.
7ܤƤ礶äѤ˽Ҥ٤ȡ

  1. ӥ̾: /etc/services ˽񤫤ƤΤȰפʤȤʤ. inetd services ξȤ.
  2. åȥ: ̾ TCP ʤ stream, UDP ʤ dgram .
  3. ץȥ: ̾ TCP UDP . TCP Ϥ򤹤̿ˡUDP ϷҤ̿˸Ƥ뤾.
  4. ³Ƥ inetd εư: ̾ TCP ʤ nowait UDP ʤ wait . nowait ˤ nowait/5 ʤɤȤƱ³(㤨Фξ 5ޤǤ)¤Ǥ.
  5. Ω夲 deamon μ¹Ը: ƥͤüʥ桼θ¤ˤ뤳ȤǶήԤ.Ȥꤢ root ˤƤХƥʳϤޤ굯ʤ
  6. Ω夲 deamon path: եȤκ߽. internal ȤΤ inetd Ȥ󶡤Ǥ륵ӥ.
  7. Ω夲 deamon Υޥ: ޥɥ饤󥪥ץʤ󤫤񤱤.

ȤʤäƤ.

ʤ inetd ưƤ֤ /etc/inetd.conf 񤭴ϡ

 kill -HUP (inetd pid)

Ȥ inetd.conf ɤľƤ.

½

ˡͥåȥ³ơֺ̾ʹƤץӥ¸Ƥߤ褦(^-^)
ˤϡӥ׵ᤵ줿̾ϤץץΩ夲ɤ.
ץˤ fortune ȤΤΤƤΤǡ줬ޥɤȤƤ󥹥ȡ뤵Ƥ*7Ȥǧ褦.

θ塤/etc/inetd.conf

 qotd stream tcp nowait root /usr/games/fortune fortune

( 7. ܴ֤ϥ֤Ƕڤ)
Ƚ񤭲äФνϽ.

inetd Ȥˤ: inetd Ω夲

ưˤĤư褦ˤƤˤϡ /etc/rc.conf

 inetd_enable="YES"

Ƚ񤤤ƤФ褤.
ưΩ夲ˤϡroot

 /etc/rc.d/inetd start

ȤФ褤.

½

inetd ư褦ˤ褦.

inetd Ȥˤ: ³

ƥкȤơTCP wrappers ˤ³ġ٤ FreeBSD ˤƳƤ.
inetd ϥǥեȤǤϤ³٤Ѥ*8.

ŪˤϡεĤɤʤäƤ뤫 /etc/hosts.allow ǵҤ.
Ҥϸʬ뤬

 ץ̾ : ³Ƥޥ̾ : /Ե

Ȥ褦ˤʤäƤꡤιԤֳ뤫ɤפĴ٤Ƥ褦ˤʤäƤ.
ơֺǽ˳פͭˤʤȤߤ*9.

֤󡤳νǤϺǽ

 ALL : ALL : allow

Ƚ񤤤Ƥ顤ޤϤʤǤ.
ξ硤Ǥ̵¤³뤳ȤˤʤΤǡ׻ǤʤФǤդ٤ΰĤǤ.

½

 telnet localhost 17

ȼʬΥޥ³Ƥߤơ̾Ϥ뤫.
ˡʤȤ⼫ʬǤʤ¾ͤΥޥФƱͤ

telnet (ޥ̾) 17

ȤƤ̾Ϥ뤫.

ˡ/etc/hosts.allow ALL : ALL : allow

 ALL : localhost : allow
 fortune : ALL : deny

ȤԤ񤭹Ǥ*10inetd öߤơư*11.
ˤ

 /etc/rc.d/inetd stop; /etc/rc.d/inetd start

ȤФ褤.

줫顤ʬΥޥ³Ƥߤ̾Ϥ뤳ȡ¾Υޥ󤫤³äƳΤ˥ӥϼʤȤǧ.

Ū˵ư륽եȥ

˽Ҥ٤֤ĤưƤסָƤФ줿ư褦ԵƤפȤեȥ¾ˡŪưץեȥ.
ƥĴ update ʤɡŪ˼¹ԤɤΤ.

ŪʻȤߤȤƤ inetd ɤƤꡤŪˤΥեȤư "cron" daemon , cron ˽ä͡ʥեȥư褦ˤʤäƤ.

cron

ư cron ϰʬܳФᡤ٤եåƤ˽äƾˤեȥư褦ˤʤäƤ.
äơե񤭴ˤη̤ȿǤ뤿̤ɬפʤĤϤǤʤ⤢褦*12.

cron ˺Ȥ򤵤뤿եϰ̤ crontab ȸƤФ졤Τ褦ब.

  1. /var/cron/tabs/桼̾ ľܥǥǤ餺ˡ"crontab -e" ȥޥɤưԽ.
    Υޥ "crontab" *13ˤĤƤ "jman crontab" ǥޥ˥奢ɤळȤǤ.
    ޤեˤĤƤ*14 "jman 5 crontab" Ȥȥޥ˥奢뤬Ҥ. 桼̾(6).
    ե˽񤤤Ƥ¹Ԥ뤫ɤϤΥ桼 cron μ¹Ը¤뤫ɤ˰¸.
    äѤˤϡ/var/cron/allow եˤΥ桼̾񤤤Ƥꡤ/var/cron/deny եˤΥ桼̵̾Ф褤.
  2. /etc/crontab ƥ. ľܥǥԽ.

½

cron ȤäƤߤ褦.

ޤ̾桼Ǥ cron Ȥ褦ˡ/var/cron/allow ꤻ.
Ūˤϡ桼̾Τߤ񤤤Ԥ /var/cron/allow ˤФ褤(ιԤ˥ڡ䥿֤ʤɡ桼̾ʳʸäƤƤϤʤ).

̾桼 cron ȤäƤߤ褦.

 crontab -e 

ȤơŬƤϿƤߤȤȤ. 㤨С

 */1 * * * * tail /var/log/messages >> Ŭʥե̾

(6. ܴ֤ϥ֤Ƕڤ. Ǹι "tail ... " "tail" ޥɤȤäޥʸʤΤǡȤǴ֤ϥڡǶڤäƤ)
ʤɤϿƤСmessages κǸ 10Ԥ 1ʬɲä쵭Ͽ뤳Ȥˤʤ.
ϿǤɤ

 crontab -l 

ȤФ狼.

ǡºݤưƤ뤫ɤϡ(root) /var/log/cron ɤ cron ΥʬΤȽǤ.
ޤʤϡߤϿ꤬ʤ褯ߤ褦.
ޤϿͭˤʤäƤʤȤ褦ʾϡcron Ф kill -HUP 򤫤褦.

(ޤäȤϺƤ crontab -e ʤɤȤäϿ򳰤, ǰΰ٤ cron Ф kill -HUP 򤫤Ƥ)

periodic

Ū˹Ԥ륷ƥȤΤäŵŪʤΤ /etc/periodic ʲˤ졤periodic ޥɤư.
periodic ޥɤ cron ǤФ褦ˤʤäƤ*15.
periodic ޥɤ /etc/periodic.conf Ǥʤ.
Υǥեͤ /etc/defaults/periodic.conf ˽񤫤Ƥ.

newsyslog

newsyslog cron ƤӽФ뤳ȤꤷƤ륽եȥǡ͡ʥեȥΥեԤΤǤ.
ŪˤϡߤΥե̾Ѥ¸ơեѰդȤԤ.
/etc/newsyslog.conf ǹԤ.
Ŭڤ˹ԤʤäƤʤȡե뤬礭ʤꤹƥϡɥǥ줿ꤹ.

½

/etc/newsyslog.conf ɤǡλǤɤΤ褦ʥե뤬ɤΤ褦Ƥ뤫Ĵ٤.

ݡ

ԤäȤ𡤤ӺưƤ daemon ˤĤơơɤΤ褦 daemon ʤΤĴ٤ƥꥹȤˤƤfurihata ä cmc.osaka-u.ac.jp ˥᡼դ.
ƼΡֽ°ǯֹ桤̾פ񤯤Τ˺ʤ褦.


*1 ޥCPUʤɤλ񸻤֤˳ľȤǼ¸
*2 ʤ OS ˤΤΤʬǺľȤǤΤ
*3 nest init ư뤳ȤǽʴĶ¸ߤ. ܤ jman jail ʤɤȤƤߤ.
*4 ޥ˥奢褯ɤफsysctl -a -h η̤Ŭڤ grep Ф褤
*5 daemon ϼȤꥷä˽ФƤȾȾͤΤȤǡ(demon)ǤϤʤȤդ. ֤꤬㤦. ޤꥫͤǤ褯򤹤櫓. ʤBSD unix Ǥ daemon ϥޥåȤȤƤνפ䤬. ܤ http://www.freebsd.org/ja/copyright/daemon.html 򸫤.
*6 Τʤ? ʤФޥ˥奢ߤ褦. ޥ˥奢򤹤뤳Ȥ unix Ǥϡ֤褤ȡפȤ
*7 󥹥ȡ뤵ƤʤСsysinstall Configure Distributions games ǥ󥹥ȡ뤻
*8 Ѥʤ褦ˤǤ
*9 ܤ "jman hosts_access" Ȥƥޥ˥奢򻲾Ȥ
*10 fortune ǤϤʤ qotd Ƚ񤭤ˤʤ뤬ǤϤʤΤդ뤳
*11 "kill -HUP (inetd pid)" Ǥɤǰΰ
*12 Ĥޤ, ե񤭴äѤ "kill -HUP (cron pid)" Ȥۤ褤
*13 Ʊ䤹crontab Ȥޥɤ⤢Τ
*14 /etc/crontab ɤץˤʤ
*15 /etc/crontab periodic ƤǤʬϤ