๐ŸŒฑ Infra/Hadoop_HDFS

Hadoop ํ•˜๋‘ก(2.10.1)! ๋ฌด์ž‘์ • ๋”ฐ๋ผํ•˜๊ธฐ #2

mini_world 2021. 2. 28. 09:47
๋ชฉ์ฐจ ์ ‘๊ธฐ

 

์ด ํฌ์ŠคํŒ…์€ ์ด์ „ํฌ์ŠคํŒ…๊ณผ ์ด์–ด์ง‘๋‹ˆ๋‹ค :)

์ง€๊ธˆ๊นŒ์ง€ ํ•˜๋‚˜์˜ ๋…ธ๋“œ์— Java์™€ ํ•˜๋‘ก์„ ์„ค์น˜ํ•˜๊ณ , ํ•˜๋‘ก ์„ค์ •ํŒŒ์ผ์„ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ๊ฐ ๋…ธ๋“œ์— ๋งž๊ฒŒ ์„ค์ •์„ ๋ณ€๊ฒฝํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค !!

 


1. Master์„œ๋ฒ„ ์„ค์ •

์ด๋ฒˆ ๋‹จ๊ณ„์—์„œ๋Š” Master ์„œ๋ฒ„์˜ ์„ค์ •์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค :)

๋”๋ณด๊ธฐ

Master ์„œ๋ฒ„์— SSH๋กœ ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค. 

1) Hostname ๋ณ€๊ฒฝ

hostnamectl ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

sudo hostnamectl set-hostname master.hadoop

 

2) /etc/hosts ํŒŒ์ผ ์ˆ˜์ •

hostsํŒŒ์ผ์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค. 
hosts ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜๊ธฐ ์ „, EC2์ฝ˜์†”์—์„œ ๊ฐ ์ธ์Šคํ„ด์Šค์˜ ํ”„๋ผ์ด๋น—IP์ฃผ์†Œ๋ฅผ ์•Œ์•„๋‘ก๋‹ˆ๋‹ค :)

sudo vi /etc/hosts
<ํ˜ธ์ŠคํŠธIP>            <ํ˜ธ์ŠคํŠธ Name>
172.31.3.145           master.hadoop    master
172.31.5.127            slave1.hadoop     slave1
172.31.1.245            slave2.hadoop    slave2
172.31.13.143          slave3.hadoop     slave3

 

3) SSH ํ‚ค ์ƒ์„ฑ ๋ฐ SSH ์„ค์ • ๋ณ€๊ฒฝ

ssh-keygen ๋ช…๋ น์–ด๋กœ SSHํ‚ค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  SSH๋กœ ์ ‘์† ๊ฐ€๋Šฅํ•˜๋„๋ก /etc/ssh/sshd_config ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.
* ์ฃผ์˜ * ์ง€๊ธˆ ํ•˜๋Š” SSH์„ค์ •์€ ๋งค์šฐ ์ทจ์•ฝํ•œ ์„ค์ •์ด๋ฉฐ, ํ…Œ์ŠคํŠธ ์šฉ๋„๋กœ๋งŒ ์‚ฌ์šฉํ•˜์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค. 

๋จผ์ €, SSH ํ‚ค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

sudo ssh-keygen

 ์ด์ œ ssh ์„ค์ •ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

sudo vi /etc/ssh/sshd_config 

 ๋จผ์ € 2๊ฐœ๋ฅผ ๋ณ€๊ฒฝํ• ๊ฑด๋ฐ, 38๋ฒˆ์งธ ์ค„์˜ "PermitRootLogin" ์˜ ์ฃผ์„์„ ํ•ด์ œํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  65๋ฒˆ์งธ ์ค„์˜ "PasswordAuthentication" ๋ฅผ yes๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

์ €์žฅํ›„ ์„ค์ •ํŒŒ์ผ์„ ๋ฆฌ๋กœ๋“œํ•˜๊ธฐ ์œ„ํ•ด ssh ๋ฐ๋ชฌ์„ ์žฌ์‹œ์ž‘ ํ•ฉ๋‹ˆ๋‹ค.

 sudo systemctl restart sshd

Root ๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

sudo passwd root

 

4) Slaves ํŒŒ์ผ ์„ค์ • 

์ด ์„ค์ •์€ Master ์„œ๋ฒ„์—์„œ๋งŒ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค!
/usr/local/hadoop-2.10.1/etc/hadoop/slaves ํŒŒ์ผ์€ Slave๊ฐ€ ๋  ๋…ธ๋“œ๋“ค์„ ๋ช…์‹œํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
vi ํŽธ์ง‘๊ธฐ๋กœ slaves ํŒŒ์ผ์˜ ์„ค์ •์„ ๋ณ€๊ฒฝํ•ด์ค๋‹ˆ๋‹ค.

vi /usr/local/hadoop-2.10.1/etc/hadoop/slaves
slave1
slave2
slave3

 

์ด์ œ ๋‹ค์Œ์œผ๋กœ ๋„˜์–ด๊ฐ‘๋‹ˆ๋‹ค.

 


2. Slave1~3 ์„œ๋ฒ„ ์„ค์ •

์ด๋ฒˆ ๋‹จ๊ณ„์—์„œ๋Š” Slave ์„œ๋ฒ„์˜ ์„ค์ •์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค :)
์•„๋ž˜ ์ˆœ์„œ๋Œ€๋กœ ๊ฐ Slave1, Slave2, Slave3์—์„œ ๋ชจ๋‘ ์‹คํ–‰์‹œ์ผœ์ฃผ์„ธ์š”!!

๋”๋ณด๊ธฐ

Slave ์„œ๋ฒ„์— SSH๋กœ ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค. 

1) Hostname ๋ณ€๊ฒฝ

hostnamectl ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. 
๊ฐ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์— ๋งž๊ฒŒ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

sudo hostnamectl set-hostname slave1.hadoop

 

2) /etc/hosts ํŒŒ์ผ ์ˆ˜์ •

hostsํŒŒ์ผ์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

sudo vi /etc/hosts
<ํ˜ธ์ŠคํŠธIP>            <ํ˜ธ์ŠคํŠธ Name>
172.31.3.145           master.hadoop    master
172.31.5.127            slave1.hadoop     slave1
172.31.1.245            slave2.hadoop    slave2
172.31.13.143          slave3.hadoop     slave3

 

3) SSH ํ‚ค ์ƒ์„ฑ ๋ฐ SSH ์„ค์ • ๋ณ€๊ฒฝ

ssh-keygen ๋ช…๋ น์–ด๋กœ SSHํ‚ค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  SSH๋กœ ์ ‘์† ๊ฐ€๋Šฅํ•˜๋„๋ก /etc/ssh/sshd_config ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.
* ์ฃผ์˜ * ์ง€๊ธˆ ํ•˜๋Š” SSH์„ค์ •์€ ๋งค์šฐ ์ทจ์•ฝํ•œ ์„ค์ •์ด๋ฉฐ, ํ…Œ์ŠคํŠธ ์šฉ๋„๋กœ๋งŒ ์‚ฌ์šฉํ•˜์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค. 

๋จผ์ €, SSH ํ‚ค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

sudo ssh-keygen

 ์ด์ œ ssh ์„ค์ •ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

sudo vi /etc/ssh/sshd_config 

 ๋จผ์ € 2๊ฐœ๋ฅผ ๋ณ€๊ฒฝํ• ๊ฑด๋ฐ, 38๋ฒˆ์งธ ์ค„์˜ "PermitRootLogin" ์˜ ์ฃผ์„์„ ํ•ด์ œํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  65๋ฒˆ์งธ ์ค„์˜ "PasswordAuthentication" ๋ฅผ yes๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

์ €์žฅํ›„ ์„ค์ •ํŒŒ์ผ์„ ๋ฆฌ๋กœ๋“œํ•˜๊ธฐ ์œ„ํ•ด ssh ๋ฐ๋ชฌ์„ ์žฌ์‹œ์ž‘ ํ•ฉ๋‹ˆ๋‹ค.

 sudo systemctl restart sshd

Root ๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

sudo passwd root

 

์ด์ œ ๋‹ค์Œ์œผ๋กœ ๋„˜์–ด๊ฐ‘๋‹ˆ๋‹ค.

 


3. SSH ํ‚ค ๊ตํ™˜ 

์ด ๋‹จ๊ณ„๋Š” ๊ฐ ์„œ๋ฒ„์—์„œ ๋™์ผํ•˜๊ฒŒ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค!  (Master, Slave1, Slave2, Slave3 4๋Œ€์˜ ์‹œ์Šคํ…œ ๋ชจ๋‘์—์„œ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค)
์ ๋‹ค๋ณด๋‹ˆ Master์„œ๋ฒ„์—์„œ๋งŒ ์ง„ํ–‰ํ•ด๋„ ๋˜์ง€ ์•Š์•˜๋‚˜ ํ•˜๋Š” ์˜๋ฌธ์ด ๋“œ๋Š”๋ฐ... ๋‹ค์Œ์— ๋‹ค์‹œ ํ…Œ์ŠคํŠธ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!! ์ผ๋‹จ ์ง€๊ธˆ์€ ์ด๋ ‡๊ฒŒ ๊ฐ‘๋‹ˆ๋‹ค!
์ด ์„ค์ •์„ ์™„๋ฃŒํ•˜๋ฉด ssh ๋ช…๋ น์–ด๋กœ ์–ด๋–ค ์„œ๋ฒ„์—๋‚˜ ๊ทธ๋ƒฅ ์ ‘์†ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค!!

๋”๋ณด๊ธฐ

Master ์„œ๋ฒ„์™€ ํ‚ค๋ฅผ ๊ตํ™˜ํ•ฉ๋‹ˆ๋‹ค.

ssh-copy-id root@master

slave1 ์„œ๋ฒ„์™€ ํ‚ค๋ฅผ ๊ตํ™˜ํ•ฉ๋‹ˆ๋‹ค.

ssh-copy-id root@slave1

slave2 ์„œ๋ฒ„์™€ ํ‚ค๋ฅผ ๊ตํ™˜ํ•ฉ๋‹ˆ๋‹ค.

ssh-copy-id root@slave2

slave3 ์„œ๋ฒ„์™€ ํ‚ค๋ฅผ ๊ตํ™˜ํ•ฉ๋‹ˆ๋‹ค.

ssh-copy-id root@slave3

 ๋ชจ๋‘ ์™„๋ฃŒ ๋˜์—ˆ๋‹ค๋ฉด! ๋‹ค์Œ ๋‹จ๊ณ„๋กœ ๋„˜์–ด๊ฐ‘๋‹ˆ๋‹ค.

 


4. HDFS ํŒŒ์ผ ํฌ๋ฉง

์ฒ˜์Œ ๋””์Šคํฌ๋ฅผ ์‚ฌ์šฉํ• ๋•Œ, OS์— ๋งž๊ฒŒ ํŒŒ์ผ ์‹œ์Šคํ…œ์„ ํฌ๋ฉงํ•˜๋Š”๊ฒƒ ์ฒ˜๋Ÿผ, HDFS๋ฅผ ์‹œ์ž‘ํ•˜๊ธฐ ์ „ ํฌ๋ฉง์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค :)
NameNode ํฌ๋ฉง์€ Master ์„œ๋ฒ„์—์„œ, DataNode ํฌ๋ฉง์€ Slave1, Slave2, Slave3 ์„œ๋ฒ„์—์„œ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค!

๋”๋ณด๊ธฐ

1) NameNode ํฌ๋ฉง

๋จผ์ € ๋งˆ์Šคํ„ฐ ์„œ๋ฒ„์—์„œ ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
๋ช…๋ น์–ด ์‹คํ–‰ ํ›„ /data ๋””๋ ‰ํ„ฐ๋ฆฌ๊ฐ€ ์ƒ์„ฑ๋œ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

/usr/local/hadoop-2.10.1/bin/hdfs namenode -format

(์ค‘๊ฐ„์ƒ๋žต)

 

2) DataNode ํฌ๋ฉง

 Slave ๋…ธ๋“œ (DataNode) 3๋Œ€ ๋ชจ๋‘์—์„œ ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
๋งˆ์ฐฌ๊ฐ€์ง€๋กœ, ๋ช…๋ น์–ด ์‹คํ–‰ ํ›„ /data ๊ฒฝ๋กœ๊ฐ€ ์ƒ์„ฑ๋จ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

(์ค‘๊ฐ„์ƒ๋žต)

 


5. HDFS & YARN ์‹œ์ž‘ํ•˜๊ธฐ

ํ•˜๋‘ก ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ, HDFS๋ฅผ ์‹œ์ž‘ํ•œ ํ›„์— YARN์„ ์‹คํ–‰์‹œ์ผœ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 
HDFS๋Š” ๋ง ๊ทธ๋Œ€๋กœ ํŒŒ์ผ์‹œ์Šคํ…œ, ๊ทธ๋ฆฌ๊ณ  YARN์€ ๋ฆฌ์†Œ์Šค ๋งค๋‹ˆ์ €์ž…๋‹ˆ๋‹ค :)

๋”๋ณด๊ธฐ

1) HDFS ์‹œ์ž‘ํ•˜๊ธฐ

์•„๋ž˜ ๋ช…๋ น์–ด๋กœ HDFS๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
/usr/local/hadoop-2.10.1/etc/hadoop/slaves์— ๋“ฑ๋ก๋œ ๋…ธ๋“œ์— ๋ชจ๋‘ SSH Trusted Access ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด, 
์•„๋ž˜ ๋ช…๋ น์–ด ํ•œ์ค„๋กœ ๋ชจ๋“  ๋…ธ๋“œ์˜ ๋ฐ๋ชฌ์„ ๋„์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค :)

/usr/local/hadoop-2.10.1/sbin/start-dfs.sh

์ด์ œ ๊ฐ ๋…ธ๋“œ์—์„œ๋Š” ์•„๋ž˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด, Master ๋…ธ๋“œ์—์„œ๋Š” NameNode ๋ฐ๋ชฌ์ด ๋™์ž‘ํ•˜๊ณ , Slave ๋…ธ๋“œ์—์„œ๋Š” DataNode ๋ฐ๋ชฌ์ด ๋™์ž‘ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
๊ฐ ๋ฐ๋ชฌ์ด ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋Š” jps ๋ช…๋ น์–ด๋กœ ํ™•์ธํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.!

HDFS๋ฅผ ์ •์ƒ์ ์œผ๋กœ ์‹œ์ž‘ํ•˜์…จ๋‹ค๋ฉด ์›น๋ธŒ๋ผ์šฐ์ €๋กœ ์ ‘์† ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค:)

http://<Master IP>:50070

 

2) YARN (Resource Manager) ์‹œ์ž‘ํ•˜๊ธฐ

์•„๋ž˜ ๋ช…๋ น์–ด๋กœ YARN๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
/usr/local/hadoop-2.10.1/etc/hadoop/slaves์— ๋“ฑ๋ก๋œ ๋…ธ๋“œ์— ๋ชจ๋‘ SSH Trusted Access ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด, 
์•„๋ž˜ ๋ช…๋ น์–ด ํ•œ์ค„๋กœ ๋ชจ๋“  ๋…ธ๋“œ์˜ ๋ฐ๋ชฌ์„ ๋„์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค :)

/usr/local/hadoop-2.10.1/sbin/start-yarn.sh 

Yarn์„ ์ •์ƒ์ ์œผ๋กœ ์‹œ์ž‘ ํ•˜์…จ๋‹ค๋ฉด, ์›น๋ธŒ๋ผ์šฐ์ €์—์„œ๋„ ์ ‘์† ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค :)

http://<Master IP>:8088

์ด๊ฒƒ์ €๊ฒƒ ํด๋ฆญํ•ด์„œ ํ™•์ธํ•ด๋ณด์„ธ์š”!
์—ฌ๊ธฐ๊นŒ์ง€ ์ง„ํ–‰ ํ•˜์…จ๋‹ค๋ฉด HDFS๋ฅผ ๊ตฌ์ถ•ํ•˜๋Š” ๋ถ€๋ถ„์€ ์™„๋ฃŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!! ๐Ÿค—๐Ÿค—๐Ÿค—

 


5. HDFS & YARN ์ข…๋ฃŒํ•˜๊ธฐ

์‹œ์ž‘๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ข…๋ฃŒํ• ๋•Œ์—๋„ ์ˆœ์„œ์— ๋งž์ถฐ ์ง„ํ–‰ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค :)

๋”๋ณด๊ธฐ

HDFS & YARN์„ ์ข…๋ฃŒํ•˜๋Š” ๊ฒƒ์€ ์•„๋ž˜ ๋‘ ๋ช…๋ น์–ด๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ์ง„ํ–‰ํ•˜์‹œ๊ฑฐ๋‚˜ stop-all.sh๋ฅผ ์‹คํ–‰์‹œ์ผœ์ฃผ์…”๋„ ๋ฉ๋‹ˆ๋‹ค :)

/usr/local/hadoop-2.10.1/sbin/stop-yarn.sh 
/usr/local/hadoop-2.10.1/sbin/stop-dfs.sh 

 


728x90