๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
DevOps/IaC ์ž๋™ํ™”

[Puppet] ํผํŽซ ์†Œ๊ฐœ ๋ฐ ์„ค์น˜

by ๐ŸŒปโ™š 2021. 1. 10.

Puppet์ด๋ž€?

 Puppet์€ ruby๋กœ ๋งŒ๋“ค์–ด์ง„ ์‹œ์Šคํ…œ ๊ด€๋ฆฌ ์ž๋™ํ™” ํˆด์ด๋‹ค. ์ฃผ๋กœ ์„ค์ •, ๊ด€๋ฆฌ, ๋ฐฐํฌ, orchestrate์™€ ๊ฐ™์€ ์ผ์„ ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค. puppet์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋ฐ˜๋ณต๋˜๋Š” ์—…๋ฌด๋ฅผ ์ž๋™ํ™”ํ•˜๊ธฐ ์œ„ํ•จ์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ํŒจํ‚ค์ง€๋ฅผ 5๊ฐœ์˜ ์„œ๋ฒ„์— ์„ค์น˜ํ•ด์•ผํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋ฉด... ์˜ค๋žœ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ์ง€ ์•Š์•„ ๋ฐ˜๋ณต๋˜๋Š” ์ž‘์—…์„ ์ง์ ‘ ๋ถ™์–ด์„œ ํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ, ๋งŒ์•ฝ 100๊ฐœ, 1000๊ฐœ ์ด์ƒ์˜ ์„œ๋ฒ„์— ๊ฐ™์€ ์ž‘์—…์„ ํ•ด์•ผํ•œ๋‹ค๋ฉด? ์ง์ ‘ ํ•˜๊ธฐ์—๋Š” ์†Œ์š”๋˜๋Š” ๋น„์šฉ์ด ๋„ˆ๋ฌด ํฝ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ด์œ ๋กœ ์ธํ”„๋ผ, ๋ฐ๋ธŒ์˜ต์Šค ์—”์ง€๋‹ˆ์–ด๊ฐ€ ์กฐ์ง์˜ ์—…๋ฌด๋ฅผ ์ž๋™ํ™”ํ•˜๊ธฐ ์œ„ํ•ด ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค.

 

puppet ์ฃผ์š” ํŠน์ง•

Master Agent Pull ๊ธฐ๋ฐ˜

์‹œ์Šคํ…œ ๊ด€๋ฆฌ ํˆด์€ Pull๊ธฐ๋ฐ˜๊ณผ Push๊ธฐ๋ฐ˜์œผ๋กœ ๋‚˜๋‰œ๋‹ค. Puppet์€ Pull๊ธฐ๋ฐ˜ ํˆด์ด๋ฉฐ Master์™€ Agent๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

puppet์ฒ˜๋ฆผ ์‹œ์Šคํ…œ์„ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ํˆด ์ค‘์— Push Base ํˆด์€ Ansible์ด ์žˆ๋‹ค. ์šฉ์–ด๋‚˜ ๊ทธ๋ฆผ์—์„œ ์•Œ ์ˆ˜ ์žˆ๋“ฏ์ด... Pull Base๋Š” master์—๊ฒŒ ์š”์ฒญํ•ด์„œ ์ž‘์—…ํ•ด์•ผํ•˜๋Š” ์—…๋ฌด๋ฅผ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ด๊ณ , Push Base๋Š” Master๊ฐ€ ์ง์ ‘ ์ž‘์—…์„ ํ•˜๋‹ฌํ•œ๋‹ค. Puppet์€ ๊ฐ๊ฐ ๊ด€๋ฆฌํ•˜๋Š” ์„œ๋ฒ„์— agent ์„ค์น˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค. agent๋Š” default 1800์ดˆ ๋งˆ๋‹ค Master์—๊ฒŒ ํ•„์š”ํ•œ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ํ™•์ธํ•˜๊ณ  ๋ฐ˜์˜ํ•œ๋‹ค.

 

Agent ์„œ๋ฒ„๋Š” Linux, Window, Solaris ๋“ฑ ๋Œ€๋ถ€๋ถ„์˜ OS๋ฅผ ์ง€์›ํ•˜์ง€๋งŒ, Master์„œ๋ฒ„์˜ ๊ฒฝ์šฐ Linux์„œ๋ฒ„ ์œ„์— ์„ค์น˜๋˜์–ด์•ผํ•œ๋‹ค.

 

DSL ์ œ๊ณต, declarative

 Puppet์€ DSL(Domain Specific Language)์„ ์ œ๊ณตํ•˜๊ณ  declarative ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์ง€์›ํ•œ๋‹ค. ์ด ๊ด€์ ์—์„œ imperative vs declarative์— ๋Œ€ํ•œ ๊ฐœ๋…์„ ๊ฐ–๊ณ  ์žˆ๋Š”๋ฐ... imperative๋Š” ๋ชจ๋“  ์ž‘์—… ๊ณผ์ •์„ ์ผ์ผํžˆ ์ž‘์—…ํ•ด์ฃผ๋Š” ๊ฒƒ์ด๊ณ  declarative๋Š” ์ •์˜ํ•œ ๋‚ด์šฉ๋Œ€๋กœ ์ž‘์—… ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์ง์ ‘ ์šด์ „ํ•˜๋Š” ๊ฒƒ๊ณผ ์ž์œจ์ฃผํ–‰์œผ๋กœ ์˜ˆ๋ฅผ ๋“ค์–ด๋ณด๋ฉด...

์œ„์˜ ์˜ˆ์‹œ์ฒ˜๋Ÿผ Declarativeํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด Imperativeํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ณด๋‹ค ๊ฐ€์šฉ์„ฑ์ด ๋†’์€ ์ƒํƒœ๋กœ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ์ฆ‰, puppet์€ ๋ฏธ๋ฆฌ ์ •์˜ํ•œ resource๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž์ฒด ์–ธ์–ด๋ฅผ ์ œ๊ณตํ•˜์—ฌ ๊ธด ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ ์€ ๋‚ด์šฉ์œผ๋กœ ๊ตฌํ˜„ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

 

๋ฉฑ๋“ฑ์„ฑ

์ž‘์—…์„ ์—ฌ๋Ÿฌ ๋ฒˆ ์ˆ˜ํ–‰ํ•ด๋„ ํ•ญ์ƒ ๊ฒฐ๊ณผ๊ฐ€ ๊ฐ™์€ ์„ฑ์งˆ์„ ์˜๋ฏธํ•œ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด ์–ด๋–ค ํŒŒ์ผ์— "This is first line"์ด๋ผ๋Š” ๋ฌธ๊ตฌ๋ฅผ ๋„ฃ๋Š” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ–ˆ๋Š”๋ฐ ํ•œ ๋ฒˆ ๋” ์ˆ˜ํ–‰ํ–ˆ์„ ๋•Œ, ํ•ด๋‹น ๋ฌธ๊ตฌ๊ฐ€ ์ด๋ฏธ ๋“ค์–ด๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ•œ ๋ฒˆ ๋” ์ˆ˜ํ–‰๋˜์ง€ ์•Š๊ณ  ๊ฒฐ๊ณผ๊ฐ€ ๊ฐ™๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. provision์ด๋‚˜ ์ž๋™ํ™”์˜ ๊ฐœ๋…์—์„œ ๋งค์šฐ ์ค‘์š”ํ•œ ์„ฑ์งˆ์ž…๋‹ˆ๋‹ค.

 

 

Puppet ์ž‘์—… ํ๋ฆ„

์ง€๊ธˆ๊นŒ์ง€ Puppet ์˜ ๋Œ€๋žต์ ์ธ ๊ตฌ์กฐ์™€ ํŠน์ง•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ดค๋‹ค๋ฉด... ์ด์ œ๋Š” Puppet์ด ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•˜๋Š”์ง€์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ž.

๊ด€๋ฆฌ์ž๋Š” master์— ์ ‘์†ํ•ด์„œ agent์— ๋ฐ˜์˜ ํ•  puppet code๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. puppet code์ž‘์„ฑ์— ๋Œ€ํ•œ ๋ถ€๋ถ„์€ ๋‹ค์Œ ๊ธ€์—์„œ ๋‹ค๋ฃฌ๋‹ค.

puppet code ์ž‘์„ฑ์ด ์™„๋ฃŒ๋˜๋ฉด agent๊ฐ€ master์™€ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋„๋ก secure certificates๋ฅผ ์ •์˜ํ•˜๊ณ  puppet master๋Š” 8140ํฌํŠธ๋ฅผ ๊ฐœ๋ฐฉํ•˜์—ฌ ํ†ต์‹ ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•œ๋‹ค. ์—ฌ๊ธฐ๊นŒ์ง€๋Š” ์ž‘์—…์„ ์œ„ํ•œ ์„ค์ •๊ณผ์ •์ด๊ณ , agent๊ฐ€ master์—๊ฒŒ ๋ณ€๊ฒฝ์ž‘์—…์ด ํ•„์š”ํ•œ์ง€ ํ™•์ธํ•  ๋•Œ ์•„๋ž˜ ํ๋ฆ„๋Œ€๋กœ ์ž‘์—…์ด ์ด๋ฃจ์–ด์ง„๋‹ค.

 

 

  1. ํ†ต์‹ ์ด ์ •์˜๋˜์—ˆ๋‹ค๋ฉด agent๋Š” master์—๊ฒŒ agent host์˜ ์ „๋ฐ˜์ ์ธ ์ •๋ณด์ธ Fact ์ •๋ณด(hostname, kernal detail, ip address ๋“ฑ)๋ฅผ ๋ณด๋‚ธ๋‹ค.
  2. puppet์€ ์ด๋Ÿฌํ•œ Fact์ •๋ณด๋ฅผ ์ด์šฉํ•ด์„œ agent์— ๋ฐ˜์˜๋˜์–ด์•ผํ•  ์„ค์ • ๋ชฉ๋ก์ธ Catalog(ํŒจํ‚ค์ง€ ์ œ์–ด, ๊ณ„์ • ์ œ์–ด, ์‹œ์Šคํ…œ ์žฌ์‹œ์ž‘ ๋“ฑ)๋ฅผ ์ปดํŒŒ์ผํ•˜๊ณ  agent๋Š” ๋ฐ›์€ Catalog๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๋ฐ˜์˜ํ•œ๋‹ค.
  3. agent๋Š” ์ดํ›„ master์—๊ฒŒ ๋ณ€๊ฒฝ ๊ฒฐ๊ณผ ์—ฌ๋ถ€๋ฅผ ๋ณด๊ณ ํ•˜๋Š” Report๋ฅผ ๋ณด๋‚ธ๋‹ค.

 

Puppet ์„ค์น˜

os : CentOS 7.8
hostnames:
  master.centos.test
  node01.centos.test
  node02.centos.test
puppet version : 5.5.22

ํ•ด๋‹น ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด Vagrant๋ฅผ ์ด์šฉํ•œ provisioning์„ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

์„œ๋ฒ„ ํ™˜๊ฒฝ์„ค์ •์ด ์ƒˆ๋กญ๊ฒŒ ํ•„์š”์‹œ Vagrant์™€ Virtual Box๋ฅผ ์ด์šฉํ•œ ์ž๋™ํ™˜๊ฒฝ ์ƒ์„ฑ ํ›„ ์‹ค์Šต ์ง„ํ–‰ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

Vagrantfile์„ ํฌํ•จํ•œ ๊ธฐ๋ณธ ์‹ค์Šต ์„ค์ •๋‚ด์šฉ์ž…๋‹ˆ๋‹ค.

 

myJamong/Vagrant-CentOS-Master-Agent-Base

base vagrant settings for master and alpha agents. Contribute to myJamong/Vagrant-CentOS-Master-Agent-Base development by creating an account on GitHub.

github.com

 

 

 

 yum install -y https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm

master์™€ agent ๋…ธ๋“œ ๋ชจ๋“œ ์„ค์น˜ํ•ด์ค€๋‹ค.

 

master

 yum install -y puppetserver

puppet server๋ฅผ ์„ค์น˜ํ•ด์ค€๋‹ค.

 

 

/etc/puppetlabs/puppet/puppet.conf

[main]
certname = master.centos.test
environment = node
server = master.centos.test
runinterval = 600

certname: master์™€ secure connection์„ ์œ„ํ•œ name

environment: host ๊ตฌ๋ถ„์„ ์œ„ํ•œ ํ™˜๊ฒฝ --> manifest ์ •๋ณด๋ฅผ ๋ฐ›์•„์˜ฌ๋•Œ ์‚ฌ์šฉ

server: puppet master ์„œ๋ฒ„ ์ •์˜

runinterval: ์ดˆ๋‹จ์œ„๋กœ master์—๊ฒŒ ๋ณ€๊ฒฝ์‚ฌํ•ญ ์š”์ฒญํ•˜๋Š” ์‹œ๊ฐ„. default 1800

 

ํ•ด๋‹น ์„ค์ •์— ๋Œ€ํ•œ ๋ถ€๋ถ„์€ master ๋…ธ๋“œ๋„ agent๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์„ค์ •ํ•œ๋‹ค. ๋‹ค๋ฅธ agent์—์„œ๋„ ๋น„์Šทํ•˜๊ฒŒ ์„ค์ •ํ•œ๋‹ค.

 

systemctl start puppetserver
netstat -lntup | grep 8140

8140 ํฌํŠธ๊ฐ€ ๋„์›Œ์ ธ ์žˆ์œผ๋ฉด ์ด์ƒ์—†์ด puppetserver๊ฐ€ ์‹คํ–‰๋จ.

 

ํ•„์š”์— ๋”ฐ๋ผ firewall์„ ํ•ด์ œํ•˜๊ฑฐ๋‚˜ 8140๋ฒˆ ํฌํŠธ๋ฅผ ๊ฐœ๋ฐฉํ•œ๋‹ค.

 

mkdir -p /etc/puppetlabs/code/environments/node/manifest

์‚ฌ์šฉํ•  environment node์˜ manifest ๊ฒฝ๋กœ๋ฅผ ์ƒ์„ฑํ•ด์ค€๋‹ค. ์ดํ›„์— agent์—์„œ ํ†ต์‹  ํ™•์ธํ•˜๋Š” ์ž‘์—… ์ค‘... ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ, ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด์ค€๋‹ค.

 

agents

๊ด€๋ฆฌํ•  ๋…ธ๋“œ์— ๊ฐ๊ฐ puppet agent๋ฅผ ์„ค์น˜ํ•˜๊ณ  ์„ค์ •ํŒŒ์ผ์„ ์ˆ˜์ •ํ•œ๋‹ค.

ํ•ด๋‹น ์˜ˆ์ œ์—์„œ๋Š”  node01, node02๋ฒˆ ์„œ๋ฒ„์— ์„ค์ •ํ•œ๋‹ค.

 

 yum install -y puppet

puppet agent๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

 

/etc/puppetlabs/puppet/puppet.conf

[main]
certname = node01.centos.test
environment = node
server = master.centos.test
runinterval = 600

certname์—๋Š” ๊ฐ๊ฐ hostname์— ๋งž๊ฒŒ ์„ค์ •ํ•œ๋‹ค.

 

์„ค์น˜๋Š” ์ด๋ ‡๊ฒŒ ๋๋‚˜๊ณ  ํ†ต์‹ ์„ํ•˜๊ธฐ ์œ„ํ•œ sercure certification ์„ค์ •์ด ํ•„์š”ํ•˜๋‹ค.

 

secure certification

master์™€ ํ†ต์‹ ํ•˜๊ธฐ ์œ„ํ•ด secure certification ๋“ฑ๋ก์ด ํ•„์š”ํ•˜๋‹ค. ํ•ด๋‹น ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๊ธฐ ์ด์ „์— master server์˜ 8140ํฌํŠธ๊ฐ€ ๊ฐœ๋ฐฉ๋˜์–ด ์žˆ์–ด์•ผํ•œ๋‹ค.

 

agents

๊ฐ๊ฐ agent์—์„œ puppet ํ†ต์‹ ์„ ์œ„ํ•œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

puppet agent -tv

ํ•ด๋‹น ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋ฉด ssl key๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ†ต์‹ ์„ ์‹œ๋„ํ•˜์ง€๋งŒ...  certificate์„ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค๋Š” ๋กœ๊ทธ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

master์—์„œ certificate์— ๋Œ€ํ•ด์„œ ๋“ฑ๋กํ•ด์ค˜์•ผํ•œ๋‹ค.

 

master

puppet cert list

certification ์š”์ฒญ์„ ํ™•์ธํ•˜๊ณ  ๋“ฑ๋ก์„ ์ง„ํ–‰ํ•œ๋‹ค.

 

puppet cert sign node01.centos.test
puppet cert sign node02.centos.test

cert list ๋ช…๋ น์–ด๋กœ ํ™•์ธํ•œ certname์„ ์ธ์ž๋กœ ๋“ฑ๋กํ•œ๋‹ค.

 

puppet cert list --all

์ •์ƒ์ ์œผ๋กœ ๋“ฑ๋ก๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

 

agents ํ™•์ธ

๋‹ค์‹œ agent ์„œ๋ฒ„๋กœ ๋Œ์–ด์™€์„œ ์—ฐ๊ฒฐ์ด ์ด์ƒ์—†์ด ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

puppet agent -tv

์•„๊นŒ์™€๋Š” ๋‹ค๋ฅด๊ฒŒ ์ •์ƒ์ ์œผ๋กœ ํ†ต์‹ ์ด node environment๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์—ฐ๊ฒฐ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ์ง€๊ธˆ์€ manifest๊ฐ€ ์—†์–ด ์•„๋ฌด๋Ÿฐ ์ž‘์—…์„ ํ•˜์ง€ ์•Š์ง€๋งŒ, manifest๋ฅผ ๋“ฑ๋กํ•ด์ฃผ๊ณ  ํ•„์š”ํ•œ ์ž‘์—…์„ ์„ค์ •ํ•ด์ฃผ๋ฉด ์ž‘์—…์— ๋Œ€ํ•œ ๋กœ๊ทธ๊ฐ€ ๋‚จ๊ฒŒ ๋œ๋‹ค.

 

 

๋Œ“๊ธ€