Ȼ/05

Top / Ȼ / 05

줫Ƥ򤹤뤿ˡunix ưδܤˤĤ.

Unix ưƤȤ

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

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

ưƤ륽եȥ

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

ޤϺưƤ륽եȥ򸫤Ƥߤ

ps Ȥޥɤޤϴ.

 jman ps

 man ps

ȤơޤϤΥޥɤˤĤĴ٤褦. ʤȤʤ狼äˤʤä顤θ塤

ps -axu 

ȤƤߤ褦*1. ƤΥץ. ٤ʸɽڤƤޤɤɤʤȤϡ

 ps -axuww

ʤɤȤФ褤.

ˡºݤưƤơΥץɤ줯餤٤򤫤ƤΤĴ٤Ƥߤ褦.
Ūˤ top ȤޥɤŬƤ. ޥ˥奢ҤƤ顤ºݤ

 top

ȤƤߤ褦. ץξưŪˤߤġcpu ξʤɤߤ뤳Ȥ狼.

ˡ͡ʥե򳫤Ƥץξߤ뤿Υޥɡlsof ȤäƤߤ褦.
lsof ϥ󥹥ȡ뤵Ƥʤ⤷ʤ. ξϡports 餵äȥ󥹥ȡ뤷Ƥ.
(󥹥ȡ)ޤϥޥ˥奢ҤƤ顤

 lsof | less

ȤƤߤ褦. ֤褯狼ʤ顤٤

lsof -i4
lsof -i4 -P

ȤƤߤ褦. ȥͥåȥ port ξ(Ԥޤ)Τ뤳ȤǤ.
ϥͥåȥӥ򤹤ݤ˽פʾǤꡤΤ lsof Ͻ롥

½

⤷󥹥ȡ뤵ƤʤСlsof ʲΤ褦ˤƥ󥹥ȡ뤷Ƥ*2.

 portsnap fetch  Ϥޤ ports ǡäƤơ 
 portsnap update  ƤΤʤˤƤ. ŤΤȲ꤬.
 portinstall lsof  줫饤󥹥ȡ.

kernel

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

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

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

  • ưѤˡ
    • ֡Ȼˡ(loader)ˡäơפǼư񤭴Ȥˡ.
      ͥäޤưʤʤɤȤˤϽפʼʤ*5.
      ŪˤϡޥươưΥ˥塼
      01.png
      Ф˥ڡ򲡤ƤäƤ顤 6 򲡤.
      02.png
      ȤץץȤǤƥ줿Ȥ狼.
      ξǤ ? 򲡤лȤ륳ޥɤФ. Ǻä顤autoboot Ȥ̤̾굯ưΤǤȤ.
      ʤߤˡǻȤ륳ޥɤϡ(FreeBSD ̤ưƤȤ) jman loader ȤХޥ˥奢뤬Ҥ.
  • /boot/loader.conf 񤭴ƤƤ()ư. եΥǥե /boot/defaults/loader.conf ˤΤǤߤƤߤ褦(򤤤ȡ OS Τ褦˵ư˲ФȤǤ).
  • ưѤˡ.
    • sysctl Ȥ. ޤϥޥ˥奢ñɤ⤦. 줫顤(ߤʤʤΤ) root
       sysctl -a -h | less
      ʤɤȤƤߤ褦. ǫ˸ƤȡʤȤʤ狼ܤ⤢.
      ʤߤˡ񤭴Ƥߤ sysctl ѿ̾= ǽ񤭴ǽƤʤϤޤꤪᤷʤ(^-^)
  • ͥ⥸塼Υ,ɤԤ. ޥɤ kldload kldunload . ǥХɥ饤Ф򤢤줳Ѥʤɤˤäˤʤ.
    2ޥɤΥޥ˥奢Ҥ褽򤷤Ƥ.
    üʥϡɥȤݤʤɤˤϤäˤʤ.
  • ͥ򥳥ѥ뤷ƺäƤޤ(ʤ٤ޥǽ)
    ̤ϡ/usr/src/sys/i386/conf ˤ GENERIC ե򥳥ԡƽ񤭴Ƥ饳ѥ뤷ľȤƧ.
    ˤǽ񤭤ʤΤǡFreeBSD θŪǤ ϥɥ֥å(FreeBSDͥΥե졼) Ҳ𤷤Ƥ.
    μˡFreeBSD Ρǽפ礭Ѥ뤳ȤǤΤǡޥӤˤäƤϥͥκƥѥƤ褤.

½

ޥƵư(loader)äƤߤ褦.
ˡloader lsmod Ȥơɤʥ⥸塼뤬ɤ߹ޤƤ뤫ߤƤߤ褦.
ճˤߤǤ狼Τ⤢Ϥ.
ޤheap ȤƤߤơλѾ򸫤Ƥߤ褦.
줬ä顤autoboot Ȥơ̾Υ֡Ȥ򤵤褦.

ˡ(ʹߤ̾ FreeBSD ) sysctl ɽįơʬʬʤõƤߤ.

init

unix ǤƤΥץˤϡƤ鵯ưҤȤֿƻҴطפ.
ơunix OS ǡ֥ץפȤưռץ/ץƤΡֻġץץब init Ǥ.
̾ pid 1 Ǥ*6.

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

½

ޤps -axu Ȥäơinit Τ pid 1 ưƤΤǧ褦.

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

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

 kill -INT 1

ԤäƤߤ(root ǤʤȽʤȻפ).

Daemon

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

½

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

ӥ׵᤬äȤ˵ư륽եȥ

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

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

ǡ֤ޤɬפʻ뤬ä˿®ʥ쥹ݥ󥹤ʤȤ褤פȤӥˤĤƤϡָƤФƤ鵯ưפȤ褦ꤷƤ̵̤ʤ.
Ӥ˻ȤΤ֥ѥС"inetd" *9Ǥ.
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 ȤΤΤƤΤǡ줬ޥɤȤƤ󥹥ȡ뤵Ƥ*10Ȥǧ褦.
 fortune ưƤߤ褦.
03.png
Τ褦ˡФ줿ʸ? ϤϤ.

θ塤/etc/inetd.conf

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

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

inetd Ȥˤ: inetd Ω夲

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

 inetd_enable="YES"

Ƚ񤤤ƤФ褤.

½

̤ /etc/rc.conf ɵƺƵưinetd ư褦ˤ褦.
Τ inetd ưƤ뤫

 lsof -i4 -P

ȤơꤷȤ port 17 inetd ʹΩƤƤ뤳Ȥǧ褦.

inetd Ȥˤ: ³

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

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

 ץ̾ : ³Ƥޥ̾ : /Ե

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

֤󡤳νǤϺǽ

 ALL : ALL : allow

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

½

 telnet localhost 17

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

telnet (ޥ̾) 17

Ȥ
04.png
Τ褦ˤ̾Ϥ뤫.

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

 ALL : localhost : allow
 fortune : ALL : deny

ȤԤ񤭹Ǥ*13inetd öߤơư*14.
ˤ

 /etc/rc.d/inetd restart

ȤФ褤.

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

Ū˵ư륽եȥ

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

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

cron

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

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

  1. /var/cron/tabs/桼̾ ľܥǥǤ餺ˡ"crontab -e" ȥޥɤưԽ.
    Υޥ "crontab" *16ˤĤƤ "jman crontab" ǥޥ˥奢ɤळȤǤ.
    ޤեˤĤƤ*17 "jman 5 crontab" Ȥȥޥ˥奢뤬Ҥ.
    ե˽񤤤Ƥ¹Ԥ뤫ɤϤΥ桼 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 ǤФ褦ˤʤäƤ*18.
periodic ޥɤ /etc/periodic.conf Ǥʤ(äѤä򤷤ƤʤϤΥեϤʤƤ褤).
Υǥեͤ /etc/defaults/periodic.conf ˽񤫤Ƥ.

newsyslog

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

½

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

ݡ

ԤäȤˤĤ furihata ä cmc.osaka-u.ac.jp ˥᡼𤻤.
Ƽ

  1. °(ز)
  2. ֹ
  3. ǯ
  4. ̾
  5. οΥݡ(θȤˤĤƵŤ)

񤯤Τ˺ʤ褦.

ޤ

λȤƤ ʸterminal(ü) ȤϡʲΤ褦ʤΤǤ.
terminal-01.jpg
ܤϡ˥ȥܡɤˤʤ.
terminal-04.jpg
̤˥ͥåȥؤ³ͥ. ¦ϼǤĤ¤Τ.
ξΥͥåȥȤϤ 9600bps (ܤ Ethernet®٤ 10Mbps 1/1000 ®!)Ǥʤʸν񤭴ܻǤ٥ä.
terminal-02.jpg
? ̤ϥΥ. ¿(ܤͥȤ)꡼󤫥Сä.
terminal-03.jpg
ɤߤ "VT100⡼" Ȥʸ
ϡʸüΥǥեȥɤǤ DEC Ҥ VT100 üȸߴΤ⡼ɤư֤̣Ƥ.
Ǥ⤳ vt100 ⡼ɤϻȤƤơ

 grep vt100 /etc/termcap

ʤɤȤȤߤ뤳ȤǤ.


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

źեե: file04.png 237 [ܺ] fileterminal-04.jpg 207 [ܺ] fileterminal-03.jpg 210 [ܺ] file03.png 210 [ܺ] filewarning.png 137 [ܺ] filenotes.png 137 [ܺ] file01.png 726 [ܺ] fileterminal-02.jpg 691 [ܺ] fileterminal-01.jpg 786 [ܺ] file02.png 233 [ܺ]