์ƒˆ์†Œ์‹

DevOps/Server

[Linux] yum-cron ์ž๋™ ์—…๋ฐ์ดํŠธ ์„ค์น˜ ๋ฐ ๊ตฌ์„ฑ

  • -

 

 

 

 

์ •๊ธฐ์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ ์ „๋ฐ˜์ ์ธ ์‹œ์Šคํ…œ ๋ณด์•ˆ์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์ธก๋ฉด ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค. ์šด์˜ ์ฒด์ œ์˜ ํŒจํ‚ค์ง€๋ฅผ ์ตœ์‹  ๋ณด์•ˆ ํŒจ์น˜๋กœ ์—…๋ฐ์ดํŠธํ•˜์ง€ ์•Š์œผ๋ฉด ์‹œ์Šคํ…œ์ด ๊ณต๊ฒฉ์— ์ทจ์•ฝํ•ด์ง‘๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ž๋™ ์—…๋ฐ์ดํŠธ๋ฅผ ์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 


 

#1. ์„ค์น˜ ๋ฐ ์„œ๋น„์Šค ํ™œ์„ฑํ™” ๋ฐ ์‹คํ–‰

$ sudo yum install yum-cron
$ sudo systemctl enable yum-cron
$ sudo systemctl start yum-cron

 

 

$ systemctl status yum-cron

# โ— yum-cron.service - Run automatic yum updates as a cron job
#    Loaded: loaded (/usr/lib/systemd/system/yum-cron.service; enabled; vendor preset: disabled)
#    Active: active (exited) since Sat 2019-05-04 21:49:45 UTC; 8min ago
#   Process: 2713 ExecStart=/bin/touch /var/lock/subsys/yum-cron (code=exited, status=0/SUCCESS)
#  Main PID: 2713 (code=exited, status=0/SUCCESS)
#    CGroup: /system.slice/yum-cron.service

 

#2. yum-cron ๊ตฌ์„ฑ

์ฒซ ๋ฒˆ์งธ ์„น์…˜์ธ [commands]์—์„œ๋Š” ์—…๋ฐ์ดํŠธํ•  ํŒจํ‚ค์ง€ ์œ ํ˜•์„ ์ •์˜ํ•˜๊ณ , ๋ฉ”์‹œ์ง€ ๋ฐ ๋‹ค์šด๋กœ๋“œ๋ฅผ ํ™œ์„ฑํ™”ํ•˜๋ฉฐ, ์—…๋ฐ์ดํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์„ ๋•Œ ์ž๋™์œผ๋กœ ์ ์šฉํ•˜๋„๋ก ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ update_cmd๋Š” ๋ชจ๋“  ํŒจํ‚ค์ง€๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์„ค์ •๋ฉ๋‹ˆ๋‹ค. ์ž๋™ ๋ฌด์ธ ์—…๋ฐ์ดํŠธ๋ฅผ ์„ค์ •ํ•˜๋ ค๋ฉด ๊ฐ’์„ ๋ณด์•ˆ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์ด ๊ฐ’์€ ๋ณด์•ˆ ๋ฌธ์ œ๋งŒ ํ•ด๊ฒฐํ•˜๋Š” ํŒจํ‚ค์ง€๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋ผ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

 

๋‹ค์Œ ์˜ˆ์—์„œ๋Š” apply_updates๋ฅผ yes๋กœ ์„ค์ •ํ•˜์—ฌ update_cmd๋ฅผ ๋ณด์•ˆ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ๋ฌด์ธ ์—…๋ฐ์ดํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

# /etc/yum/yum-cron-hourly.conf

[commands]
update_cmd = security
update_messages = yes
download_updates = yes
apply_updates = no
random_sleep = 360

 

emitters ์„น์…˜์—์„œ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๋Š” ๋ฐฉ๋ฒ•์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. stdout ๋ฐ e-๋ฉ”์ผ๋กœ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๋ ค๋ฉด extect_via์˜ ๊ฐ’์„ stdio, e-๋ฉ”์ผ๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

# /etc/yum/yum-cron-hourly.conf

[emitters]
system_name = None
emit_via = stdio,email
output_width = 80

 

์ „์ž ๋ฉ”์ผ(email) ์„น์…˜์—์„œ ๋ฐœ์‹ ์ž ๋ฐ ์ˆ˜์‹ ์ž ์ „์ž ๋ฉ”์ผ ์ฃผ์†Œ๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. mailx ๋˜๋Š” postfix์™€ ๊ฐ™์ด ์‹œ์Šคํ…œ์— ์ „์ž ๋ฉ”์ผ์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ๋„๊ตฌ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

# /etc/yum/yum-cron-hourly.conf

[email]
email_from = root@centos.host
email_to = me@example.com
email_host = localhost

 

base ์„น์…˜์—์„œ yum.conf ํŒŒ์ผ์— ์ •์˜๋œ ์„ค์ •์„ ์žฌ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํŠน์ • ํŒจํ‚ค์ง€๋ฅผ ์—…๋ฐ์ดํŠธ์—์„œ ์ œ์™ธํ•˜๋ ค๋ฉด ์ œ์™ธ ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์˜ˆ์ œ์—์„œ๋Š” [mongodb] ํŒจํ‚ค์ง€๋ฅผ ์ œ์™ธํ•ฉ๋‹ˆ๋‹ค.

# /etc/yum/yum-cron-hourly.conf

[base]
debuglevel = -2
mdpolicy = group:main
exclude = mongodb*

 

#3. ๋กœ๊ทธ ํ™•์ธ

 

grep๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ yum๊ณผ ์—ฐ๊ฒฐ๋œ cron ์ž‘์—…์ด ์‹คํ–‰๋˜์—ˆ๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

sudo grep yum /var/log/cron

# May  4 22:01:01 localhost run-parts(/etc/cron.hourly)[5588]: starting 0yum-hourly.cron
# May  4 22:32:01 localhost run-parts(/etc/cron.daily)[5960]: starting 0yum-daily.cron
# May  4 23:01:01 localhost run-parts(/etc/cron.hourly)[2121]: starting 0yum-hourly.cron
# May  4 23:01:01 localhost run-parts(/etc/cron.hourly)[2139]: finished 0yum-hourly.cr

 

yum ์—…๋ฐ์ดํŠธ ๋‚ด์—ญ์€ /var/log/yum ํŒŒ์ผ์— ๊ธฐ๋ก๋ฉ๋‹ˆ๋‹ค. tail ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์—ฌ ์ตœ์‹  ์—…๋ฐ์ดํŠธ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

sudo tail -f  /var/log/yum.log

# May 04 23:47:28 Updated: libgomp-4.8.5-36.el7_6.2.x86_64
# May 04 23:47:31 Updated: bpftool-3.10.0-957.12.1.el7.x86_64
# May 04 23:47:31 Updated: htop-2.2.0-3.el7.x86_64

 

 

์ถœ์ฒ˜

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜Š

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ๐Ÿ‘