๋ฐ˜์‘ํ˜•


์ด์ œ ํ‡ด๊ทผํ•˜๊ณ  ๊ณต๋ถ€ํ• ๊ฒธ ๊ฒธ์‚ฌ๊ฒธ์‚ฌ ํŒจ์บ ์—์„œ ์ˆ˜๊ฐ•์‹ ์ฒญ์„ ํ–ˆ๋‹ค....
ํ˜ผ์ž์„œ ํ•˜๋ ค๋‹ˆ ๋ง‰๋ง‰ํ•˜๊ณ  ใ… 
๊ฒธ์‚ฌ๊ฒธ์‚ฌ ์ธ๊ฐ•๋“ค์œผ๋ฉด์„œ ๋ฌธ์ œํ’€์„๊ฒธ ์ˆ˜๊ฐ•์‹ ์ฒญํ–‡๋Š”๋ฐ
์•„์ง ๊ฐ•์˜๊ฐ€ ์˜คํ”ˆ๋˜๋ ค๋ฉด ์ข€ ๋‚จ์•„์„œ ๊ทธ๋•Œ๊นŒ์ง€ ํ‘น ๋…ธ๋Š”๊ฑธ๋กœ!!
๋ฌธ์ œ ๊ฐฏ์ˆ˜๋„ 369๋ฌธ์ œ์— ์†Œ์Šค์ฝ”๋“œ๋„ ์ œ๊ณตํ•ด์ค€๋‹คํ•ด์„œ 79,000์›์— ์ข‹์€๊ฐ€๊ฒฉ์ธ๊ฑฐ๊ฐ™๋‹ด
์ธ๊ฐ•์€ ์ž˜์•ˆ๋“ค์„๊ฑฐ๊ฐ™๊ธดํ•œ๋ฐ..์ด๊ฑฐ ๋“ค์œผ๋ฉด์„œ leetcode๋„ ๋„์ „๐Ÿฅบ

728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

robots.txt
0.00MB

robot.txt ํŒŒ์ผ ์ฒจ๋ถ€

728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

ํ•˜๋‘ก์˜ ๋ฌธ์ œ์ ์„ ๋ณด์™„ํ•˜๊ธฐ ์œ„ํ•ด ์ŠคํŒŒํฌ ์ƒ๊น€

 

ํ•˜๋‘ก์˜ ๋ฌธ์ œ๋Š”

1. ๋ฐ˜๋ณต์ ์ธ ์ž‘์—…์—๋Š” ๋น„ํšจ์œจ์ ์ž„

2. ๋งต๋ฆฌ๋“€์Šค์‹œ ๋„คํŠธ์›Œํฌ ํŠธ๋ž˜ํ”ฝ์œผ๋กœ ์ธํ•ด ์„ฑ๋Šฅ์ €ํ•˜๋จ.

 

์ŠคํŒŒํฌ๋ž€?

๊ธฐ์กด ๋งต๋ฆฌ๋“€์Šค์˜ ๋””์Šคํฌ ์ž…์ถœ๋ ฅ์„ ๋ณด์™„ํ•˜์—ฌ

์ธ ๋ฉ”๋ชจ๋ฆฌ๊ธฐ๋ฐ˜ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ํ”„๋ ˆ์ž„ ์›Œํฌ ์ด๋‹ค.

 

์ธ ๋ฉ”๋ชจ๋ฆฌ - ์ตœ์ดˆ ๋ฐ์ดํ„ฐ ์ž…๋ ฅ, ์ถœ๋ ฅ์—๋งŒ ๋””์Šคํฌ์— ์ž‘์„ฑํ•จ์œผ๋กœ ๋„คํŠธ์›Œํฌ ํŠธ๋ž˜ํ”ฝ ๋ฐœ์ƒ ๋‚ฎ์ถค, ์ค‘๊ฐ„ ๊ฒฐ๊ณผ๋Š” ๋ณ‘๋ ฌ์ฒ˜๋ฆฌํ•จ

 

์ŠคํŒŒํฌ์˜ ์ฃผ์š”๊ธฐ๋Šฅ - ์ŠคํŒŒํฌ SQL, ์ŠคํŒŒํฌ ์ŠคํŠธ๋ฆฌ๋ฐ, ์ŠคํŒŒํฌ MLlib, ์ŠคํŒŒํฌ GraphX, ์ŠคํŒŒํฌ ์ฝ”์–ด, ์ŠคํŒŒํฌ ์ž‘์—… ์ฒ˜๋ฆฌ

 

์ŠคํŒŒํฌ ์•„ํ‚คํ…์ฒ˜

๋…ธ๋“œ๋งค๋‹ˆ์ € ์•ˆ์—  ๋“œ๋ผ์ด๋ฒ„ ํ”„๋กœ๊ทธ๋žจ์ด ์žˆ์Œ.

1. ๋“œ๋ผ์ด๋ฒ„ ํ”„๋กœ๊ทธ๋žจ์ด SparkContext ์ธ์Šคํ„ด์Šค ์ƒ์„ฑํ•จ(์ด๋•Œ yarn๊ณผ ์—ฐ๊ฒฐ)

2. executors ๋ฅผ ์š”๊ตฌ

3. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฝ”๋“œ๋ฅผ executors์— ๋ณด๋‚ผ ๊ฒƒ

4. SparkContext ๋Š” executors๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด task๋ฅผ ๋ณด๋ƒ„

 

Spark์˜ Driver๋Š” YARN์—์„œ Application Master์™€ ๊ฐ™์Œ

 

์ŠคํŒŒํฌ ์„ค์น˜

1
2
3
$ wget https://downloads.apache.org/spark/spark-2.4.7/spark-2.4.7-bin-hadoop2.7.tgz
$ tar xvzf spark-2.4.7-bin-hadoop2.7.tgz
ln -s spark-2.4.7-bin-hadoop2.7/ spark
cs

 

์ŠคํŒŒํฌ์˜ RDD

RDD์˜ ๊ฐœ๋…(Resilient Distributed Datasets)

-์ŠคํŒŒํฌ ๋‚ด์— ์ €์žฅ๋˜๋Š” ๋ฐ์ดํ„ฐ ์…‹ ํƒ€์ž…

-๋‚ด๋ถ€์ ์œผ๋กœ ์—ฐ์‚ฐํ•˜๋Š” ๋ฐ์ดํ„ฐ๋“ค์„ ๋ชจ๋‘ RDD ํƒ€์ž…์œผ๋กœ ์ฒ˜๋ฆฌ

Immutable, Partitioned Collections of Records

์—ฌ๋Ÿฌ ๋ถ„์‚ฐ ๋…ธ๋“œ์— ๋‚˜๋ˆ„์–ด์ง€๋ฉฐ

๋‹ค์ˆ˜์˜ ํŒŒํ‹ฐ์…˜์œผ๋กœ ๊ด€๋ฆฌ๋จ

๋ณ€๊ฒฝ์ด ๋ถˆ๊ฐ€๋Šฅํ•œ ๋ฐ์ดํ„ฐ ์…‹

 

RDD์˜ ์ƒ์„ฑ

1. ์™ธ๋ถ€๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ฌ ๋•Œ

2. ์ฝ”๋“œ์—์„œ ์ƒ์„ฑ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ๋•Œ

 

RDD๋ฅผ ์ œ์–ดํ•˜๋Š” 2๊ฐœ์˜ ์—ฐ์‚ฐ ํƒ€์ž…

1.Transformation : RDD์—์„œ ์ƒˆ๋กœ์šด RDD ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜ (filter, map)

2.Action : RDD์—์„œ RDD๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ํƒ€์ž…์˜ ๋ฐ์ดํ„ฐ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜(count, collect)

 

RDD ๋ถ„์‚ฐ ์ฒ˜๋ฆฌ ๋ฐฉ๋ฒ•

1.Immutable : ๋ฐ์ดํ„ฐ์…‹ ์ƒ์„ฑ ๋’ค ๋ณ€ํ•˜์ง€ ์•Š์Œ

2.Partitoned : ๋ฐ์ดํ„ฐ์…‹์„ ์ž˜๊ฒŒ ์ž๋ฆ„

 

RDD Partitioning

ํ•˜๋‚˜์˜ RDD๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํŒŒํ‹ฐ์…˜์œผ๋กœ ๋‚˜๋‰œ๋‹ค.

ํŒŒํ‹ฐ์…˜์˜ ๊ฐœ์ˆ˜์™€ ํŒŒํ‹ฐ์…˜์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋‹ค.

 

RDD Dependency

-Narrow Dependency

ํŒŒํ‹ฐ์…˜์ด 1:1๋กœ ๋งคํ•‘ ๋˜์–ด ๋„คํŠธ์›Œํฌ ํ•„์š” ์—†๊ณ  ํ•˜๋‚˜์˜ ๋…ธ๋“œ์—์„œ ์ž‘์—… ๊ฐ€๋Šฅํ•˜๋‹ค, ๊ทธ๋ฆฌ๊ณ  ํŒŒํ‹ฐ์…˜ ๋ณต์› ์‰ฌ์›€  

-Wide Dependency

ํŒŒํ‹ฐ์…˜์ด 1:N๋กœ ๋งคํ•‘ ๋˜์–ด ํŒŒํ‹ฐ์…˜ ์žฌ๊ณ„์‚ฐ ๋น„์šฉ ๋น„์‹ธ๋ฉฐ, ๋„คํŠธ์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

RDD Lineage

RDD์—ฐ์‚ฐ ์ˆœ์„œ ๊ธฐ๋ก -> DAG (์ˆœํ™˜๋˜์ง€์•Š์Œ)

 Fault tolerant : ๊ณ„๋ณด๋กœ ๋˜‘๊ฐ™์€ RDD ์ƒ์„ฑ ๊ฐ€๋Šฅํ•จ

 Lazy execution

-Transformation ์—ฐ์‚ฐ ์‹œ ๊ณ„๋ณด ์ž‘์ • ๋จ

-Action ์—ฐ์‚ฐ ์‹œ ๊ณ„๋ณด ์‹คํ–‰๋จ

๋ฏธ๋ฆฌ ์ž‘์„ฑ๋œ ๊ณ„๋ณด๋กœ ์ž์›ํ• ๋‹น ์ฐธ๊ณ ํ•  ์ˆ˜ ์žˆ์Œ

ํ˜„์žฌ ์“ฐ๊ณ ์žˆ๋Š” ์ž์›, ์•ž์œผ๋กœ ์‚ฌ์šฉํ•  ์ž์›, Dependency๋กœ ์ž‘์—… ์Šค์ผ€์ค„๋ง์— ํ™œ์šฉ ๊ฐ€๋Šฅํ•จ

 

Spark YARN ์‹คํ–‰

1
2
3
4
5
6
scala : spark-shell --master yarn --queue queue_name
python : pyspark --master yarn --queue queue_name
 
--driver-memory 3G : spark driver๊ฐ€ ์‚ฌ์šฉํ•  ๋ฉ”๋ชจ๋ฆฌ default = 1024M
--executor-memory 3G : ๊ฐ spark executor๊ฐ€ ์‚ฌ์šฉํ•  ๋ฉ”๋ชจ๋ฆฌ์–‘
--executor-cores NUM : ๊ฐ spark executor์˜ ์ฝ”์–ด์˜ ์–‘
cs

Spark Shell ์ž…๋ ฅ ํ›„ ์ฝ”๋“œ ์ž‘์„ฑํ•ด๋ณด๊ธฐ

1
2
3
4
x=sc.parallelize([“spark”, ”rdd”, ”example”, “sample”, “example”], 3)
y=x.map(lambda x:(x,1))
y.collect()
[(‘spark’,1), (‘rdd’,1), (‘example’,1), (‘sample’,1), (‘example’,1)]
cs

x์— ์ŠคํŒŒํฌ ์ฝ˜ํ…์ŠคํŠธ ๋ณ‘๋ ฌํ™”๋กœ ์ƒ์„ฑํ•จ

y์— x๋ฅผ ๋งตํ˜•์‹์œผ๋กœ x๊ฐ’๊ณผ 1 ์ €์žฅํ•จ

collect ์จ์„œ ์ง‘ํ•ฉ ์ถœ๋ ฅํ•จ

 

์ž‘์„ฑํ•œ ์ŠคํŒŒํฌ์—์„œ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•

ํŒŒ์ด์ฌ ํŒŒ์ผ  (num์€ ์“ฐ๋ ˆ๋“œ ๊ฐœ์ˆ˜, default ๊ฐ’์€ 2~4๊ฐœ ์ •๋„)

1
spark-submit –master local[num] ํŒŒ์ผ๋ช….py 
cs

์ž๋ฐ”,์Šค์นผ๋ผ ํŒŒ์ผ

1
spark-submit \ --class “SimpleApp”\ --master local[num] /location~/name.jar
cs

 

์ŠคํŒŒํฌ์—์„œ ๋งต๋ฆฌ๋“€์Šค

1
2
3
4
val input: RDD[(K1, V1)] = ...
val mapOutput: RDD[(K2, V2)] = input.flatMap(mapFn)
val shuffled: RDD[(K2, Iterable[V2])] = mapOutput.groupByKey().sortByKey()
val output: RDD[(K3, V3)] = shuffled.flatMap(reduceFn)
cs

RDD (K1,V1) ๋ฐ์ดํ„ฐ ์ž…๋ ฅ

flatMap()์—ฐ์‚ฐ ์ˆ˜ํ–‰ํ•˜์—ฌ RDD (K2,V2) ์ถœ๋ ฅ

RDD (K2,V2) ๊ฐ’์œผ๋กœ ์…”ํ”Œํ•จ , groupByKey()๊ณผ sortByKey()์—ฐ์‚ฐ ์ˆ˜ํ–‰ํ•จ

RDD (K3, V3) ๊ฐ’์— shuffledํ›„ flatMap() ์—ฐ์‚ฐํ•œ ๊ฒฐ๊ณผ๊ฐ’ ์ €์žฅํ•จ

 

 

728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

์•„ํŒŒ์น˜ ์—์ด๋ธŒ๋กœ๋ž€ ? 

https://dennyglee.com/2013/03/12/using-avro-with-hdinsight-on-azure-at-343-industries/

- ํŠน์ • ์–ธ์–ด์— ์ข…์†๋˜์ง€ ์•Š๋Š” ์–ธ์–ด ์ค‘๋ฆฝ์  ๋ฐ์ดํ„ฐ ์ง๋ ฌํ™” ์‹œ์Šคํ…œ

- ํ•˜๋‘ก Writable์˜ ์ฃผ์š” ๋‹จ์ ์ธ ์–ธ์–ด ์ด์‹์„ฑ ํ•ด๊ฒฐ ์œ„ํ•ด ์ƒ๊ฒจ๋‚จ

 

์•„ํŒŒ์น˜ ์“ฐ๋ฆฌํ”„ํŠธ, ๊ตฌ๊ธ€ ํ”„๋กœํ† ์ฝœ ๋ฒ„ํผ์™€ ๋‹ค๋ฅธ ์ฐจ๋ณ„ํ™”๋œ ํŠน์„ฑ๊ฐ€์ง€๊ณ  ์žˆ์Œ

 

๋ฐ์ดํ„ฐ๋Š” ๋‹ค๋ฅธ ์‹œ์Šคํ…œ๊ณผ ๋น„์Šทํ•˜๊ฒŒ ์–ธ์–ด ๋…๋ฆฝ ์Šคํ‚ค๋งˆ๋กœ ๊ธฐ์ˆ ๋จ

์—์ด๋ธŒ๋กœ์—์„œ ์ฝ”๋“œ ์ƒ์„ฑ์€ ์„ ํƒ์‚ฌํ•ญ์ž„

๋ฐ์ดํ„ฐ๋ฅผ ์ฝ๊ณ  ์“ฐ๋Š” ์‹œ์ ์— ์Šคํ‚ค๋งˆ๋Š” ํ•ญ์ƒ ์กด์žฌํ•œ๋‹ค ๊ฐ€์ •ํ•จ - ๋งค์šฐ ๊ฐ„๊ฒฐํ•œ ์ฝ”๋”ฉ์ด ๊ฐ€๋Šฅ

 

์Šคํ‚ค๋งˆ์˜ ์ž‘์„ฑ

JSON

๋ฐ์ดํ„ฐ๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ ํฌ๋งท์œผ๋กœ ์ธ์ฝ”๋”ฉ

 

์—์ด๋ธŒ๋กœ ๋ช…์„ธ - ๋ชจ๋“  ๊ตฌํ˜„์ฒด๊ฐ€ ์ง€์›ํ•ด์•ผ ํ•˜๋Š” ๋ฒ„์ด๋„ˆ๋ฆฌ ํฌ๋งท์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ

API - ์—์ด๋ธŒ๋กœ ๋ช…์„ธ์—์„œ ๋น ์ ธ์žˆ๋Š” ๋‚ด์šฉ์ž„. ๊ฐ ํŠน์ •์–ธ์–ด์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒŒ ์ž‘์„ฑ๋จ. ์–ธ์–ด์˜ ๋ฐ”์ธ๋”ฉ ํŽธ์˜์„ฑ ๋†’์ด๊ณ  ์ƒํ˜ธ์šด์˜์„ฑ ์ €ํ•˜ ๋ฌธ์ œ ํ•ด๊ฒฐ๋จ

 

์Šคํ‚ค๋งˆํ•ด์„ - ์‹ ์ค‘ํ•˜๊ฒŒ ์ •์˜๋œ ์–ด๋– ํ•œ ์ œ์•ฝ์กฐ๊ฑด์—์„œ๋„ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์Šคํ‚ค๋งˆ์™€ ๋ฐ์ดํ„ฐ๋ฅผ ์“ฐ๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์Šคํ‚ค๋งˆ๊ฐ€ ๊ฐ™์ง€ ์•Š์•„๋„ ๋œ๋‹ค.(์Šคํ‚ค๋งˆ ๋ณ€ํ˜• ๋ฉ”์ปค๋‹ˆ์ฆ˜)

 

ex ) ๊ณผ๊ฑฐ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์„ ๋•Œ ์‚ฌ์šฉํ•œ ์Šคํ‚ค๋งˆ์— ์ƒˆ๋กœ์šด ํ•„๋“œ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ƒˆ๋กœ์šด ์‚ฌ์šฉ์ž์™€ ๊ธฐ์กด ์‚ฌ์šฉ์ž๋Š” ๋ชจ๋‘ ๊ณผ๊ฑฐ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฌธ์ œ์—†์ด ์ฝ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ์ƒˆ๋กœ์šด ์‚ฌ์šฉ์ž๋Š” ์ƒˆ๋กœ์šด ํ•„๋“œ๊ฐ€ ์ถ”๊ฐ€๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์“ธ์ˆ˜ ์žˆ๋‹ค. ๊ธฐ์กด ์‚ฌ์šฉ์ž๋Š” ์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๊ฒŒ๋˜๋Š”๋ฐ ์ƒˆ๋กœ์šด ํ•„๋“œ๋Š” ๋ฌด์‹œํ•˜๊ณ  ๊ธฐ์กด ๋ฐ์ดํ„ฐ ์ž‘์—…์ฒ˜๋Ÿผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๊ฐ์ฒด ์ปจํ…Œ์ด๋„ˆ ํฌ๋งท ์ œ๊ณต(ํ•˜๋‘ก ์‹œํ€€์Šค ํŒŒ์ผ๊ณผ ์œ ์‚ฌํ•จ)

์—์ด๋ธŒ๋กœ ๋ฐ์ดํ„ฐ ํŒŒ์ผ์€ ์Šคํ‚ค๋งˆ๊ฐ€ ์ €์žฅ๋œ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์„น์…˜์„ ํฌํ•จํ•˜๊ณ  ์žˆ์–ด ์ž์‹ ์„ ์„ค๋ช…ํ•˜๋Š” ํŒŒ์ผ์ž„

์—์ด๋ธŒ๋กœ ๋ฐ์ดํ„ฐ ํŒŒ์ผ์€ ์••์ถ•๊ณผ ๋ถ„ํ•  ๊ธฐ๋Šฅ ์ œ๊ณต

 

์—์ด๋ธŒ๋กœ ์ž๋ฃŒํ˜•๊ณผ ์Šคํ‚ค๋งˆ

์—์ด๋ธŒ๋กœ์˜ ๊ธฐ๋ณธ ์ž๋ฃŒํ˜• ํ‘œ์‹œ

1
2
3
4
5
6
7
8
{"type":"null"}
{"type":"boolean"}
{"type":"int"}
{"type":"long"}
{"type":"float"}
{"type":"double"}
{"type":"bytes"}
{"type":"string"}
cs

์—์ด๋ธŒ๋กœ ๋ณตํ•ฉ ์ž๋ฃŒํ˜•

array ์ˆœ์„œ์žˆ๋Š” ๊ฐ์ฒด ์ง‘ํ•ฉ, ๋™์ผ ํƒ€์ž…

1
2
3
4
5
{
 "type""array",
 "items""long"
}
 
cs

map ์ˆœ์„œ ์—†๋Š” ํ‚ค-๊ฐ’, ๋™์ผ ํƒ€์ž…

1
2
3
4
{
 "type""map",
 "values""string"
}
cs

record ์ž„์˜์˜ ์ž๋ฃŒํ˜•

1
2
3
4
5
6
7
8
9
10
11
{
 "type""record",
 "name""WeatherRecord",
 "doc""A weather reading.",
 "fields": [
 {"name""year""type""int"},
 {"name""temperature""type""int"},
 {"name""stationId""type""string"}
 ]
}
 
cs

enum ๋ช…๋ช…๋œ ๊ฐ’์˜ ์ง‘ํ•ฉ

1
2
3
4
5
6
7
{
 "type""enum",
 "name""Cutlery",
 "doc""An eating utensil.",
 "symbols": ["KNIFE""FORK""SPOON"]
}
 
cs

fixed ๊ณ ์ •๊ธธ์ด 8๋น„ํŠธ ๋ถ€ํ˜ธ ์—†๋Š” ๋ฐ”์ดํŠธ

1
2
3
4
5
6
{
 "type""fixed",
 "name""Md5Hash",
 "size"16
}
 
cs

union ์Šคํ‚ค๋งˆ์˜ ์œ ๋‹ˆ์˜จ, ๋ฐฐ์—ด์˜ ๊ฐ์š”์†Œ๋Š” ์Šคํ‚ค๋งˆ์ž„

1
2
3
4
5
[
 "null",
 "string",
 {"type""map""values""string"}
]
cs

 

 

์—์ด๋ธŒ๋กœ ์ž๋ฃŒํ˜•๊ณผ ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด ์ž๋ฃŒํ˜• ๋งคํ•‘ ํ•„์š”

 

์ž๋ฐ” - ์ œ๋„ค๋ฆญ ๋งคํ•‘ : ์Šคํ‚ค๋งˆ๋ฅผ ๊ฒฐ์ •ํ•  ์ˆ˜ ์—†์„ ๋•Œ

์ž๋ฐ”, C++ - ๊ตฌ์ฒด์  ๋งคํ•‘ : ์Šคํ‚ค๋งˆ ๋ฐ์ดํ„ฐ ํ‘œํ˜„ ์ฝ”๋“œ ์ƒ์„ฑ

์ž๋ฐ” - ๋ฆฌํ”Œ๋ ‰ํŠธ ๋งคํ•‘ : ์—์ด๋ธŒ๋กœ ์ž๋ฃŒํ˜•์„ ๊ธฐ์กด ์ž๋ฐ” ์ž๋ฃŒํ˜•์œผ๋กœ ๋งคํ•‘ 

 

 

์ธ๋ฉ”๋ชจ๋ฆฌ ์ง๋ ฌํ™”์™€ ์—ญ์ง๋ ฌํ™”

์—์ด๋ธŒ๋กœ ์Šคํ‚ค๋งˆ ์˜ˆ์‹œ - ํ•ด๋‹น ์—์ด๋ธŒ๋กœ ์Šคํ‚ค๋งˆ๋Š” StringPair.avsc ์— ์ €์žฅ๋จ 

1
2
3
4
5
6
7
8
9
{
 "type""record",
 "name""StringPair",
 "doc""A pair of strings.",
 "fields": [
 {"name""left""type""string"},
 {"name""right""type""string"}
 ]
}
cs

ํŒŒ์ผ์„ ํด๋ž˜์Šค ๊ฒฝ๋กœ์— ์ €์žฅํ•œ ํ›„ ๋กœ๋”ฉํ•จ

1
2
3
Schema.Parser parser = new Schema.Parser();
Schema schema = parser.parse(
getClass().getResourceAsStream("StringPair.avsc"));
cs

์ œ๋„ค๋ฆญ API ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—์ด๋ธŒ๋กœ ๋ ˆ์ฝ”๋“œ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•จ

1
2
3
4
GenericRecord datum = new GenericData.Record(schema);
datum.put("left""L");
datum.put("right""R");
cs

์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ์— ๋ ˆ์ฝ”๋“œ๋ฅผ ์ง๋ ฌํ™”ํ•จ

1
2
3
4
5
6
7
8
ByteArrayOutputStream out = new ByteArrayOutputStream();
DatumWriter<GenericRecord> writer =
new GenericDatumWriter<GenericRecord>(schema);
Encoder encoder = EncoderFactory.get().binaryEncoder(outnull);
writer.write(datum, encoder);
encoder.flush();
out.close();
cs

DatumReader : ๋ฐ์ดํ„ฐ ๊ฐ์ฒด๋ฅผ ์ธ์ฝ”๋”๊ฐ€ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” ์ž๋ฃŒํ˜•์œผ๋กœ ๋ฐ˜ํ™˜

GenericDatumReader : GenericRecord์˜ ํ•„๋“œ๋ฅผ ์ธ์ฝ”๋”๋กœ ์ „๋‹ฌ

์ด์ „์˜ ์ƒ์„ฑ๋œ ์ธ์ฝ”๋”๋ฅผ ์žฌ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ธ์ฝ”๋” ํŒฉํ† ๋ฆฌ์— null ์ „๋‹ฌ

writer() ์ŠคํŠธ๋ฆผ ๋‹ซ๊ธฐ ์ „์— ํ•„์š”ํ•˜๋ฉด ๋” ํ˜ธ์ถœ ๊ฐ€๋Šฅ

encoder.flush(); write๋ฉ”์„œ๋“œ ํ˜ธ์ถœ ํ›„ ์ธ์ฝ”๋” ํ”Œ๋Ÿฌ์‹œํ•˜๊ณ  ์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ ๋‹ซ์Œ

 

ํ•ด๋‹น ๊ณผ์ • ๋ฐ˜๋Œ€๋กœ ํ•˜๋ฉด ๋ฐ”์ดํŠธ ๋ฒ„ํผ์—์„œ ๊ฐ์ฒด ์ฝ์„ ์ˆ˜ ์žˆ์Œ

1
2
3
4
5
6
7
 DatumReader<GenericRecord> reader =
 new GenericDatumReader<GenericRecord>(schema);
 Decoder decoder = DecoderFactory.get().binaryDecoder(out.toByteArray(),
 null);
 GenericRecord result = reader.read(null, decoder);
 assertThat(result.get("left").toString(), is("L"));
 assertThat(result.get("right").toString(), is("R"));
cs

 

 

๊ตฌ์ฒด์ ์ธ API

๋ฉ”์ด๋ธ์— ์ถ”๊ฐ€ํ•˜์—ฌ ์ž๋ฐ”๋กœ๋œ ์Šคํ‚ค๋งˆ ์ฝ”๋“œ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<project>
 ...
 <build>
 <plugins>
 <plugin>
 <groupId>org.apache.avro</groupId>
 <artifactId>avro-maven-plugin</artifactId>
 <version>${avro.version}</version>
 <executions>
 <execution>
 <id>schemas</id>
 <phase>generate-sources</phase>
 <goals>
 <goal>schema</goal>
 </goals>
 <configuration>
 <includes>
 <include>StringPair.avsc</include>
 </includes>
 <stringType>String</stringType>
 <sourceDirectory>src/main/resources</sourceDirectory>
 <outputDirectory>${project.build.directory}/generated-sources/java
 </outputDirectory>
 </configuration>
 </execution>
 </executions>
 </plugin>
 </plugins>
 </build>
 ...
</project>
 
cs

์—์ด๋ธŒ๋กœ ๋ฐ์ดํ„ฐ ํŒŒ์ผ

์ธ๋ฉ”๋ชจ๋ฆฌ ์ŠคํŠธ๋ฆผ์—์„œ ํŒŒ์ผ ์ฝ๊ธฐ

๋ฐ์ดํ„ฐ ํŒŒ์ผ = ์—์ด๋ธŒ๋กœ ์Šคํ‚ค๋งˆ +  ํ—ค๋” (๋ฉ”ํƒ€๋ฐ์ดํ„ฐ (์‹ฑํฌ๋งˆ์ปค ํฌํ•จ)) +์ผ๋ จ์˜ ๋ธ”๋ก (์ง๋ ฌํ™”๋œ ์—์ด๋ธŒ๋กœ ๊ฐ์ฒด๊ฐ€ ์žˆ๋Š”)

๋ฐ์ดํ„ฐ ํŒŒ์ผ์— ๊ธฐ๋ก๋œ ๊ฐ์ฒด๋Š” ๋ฐ˜๋“œ์‹œ ํŒŒ์ผ์˜ ์Šคํ‚ค๋งˆ์™€ ์ผ์น˜ํ•ด์•ผํ•œ๋‹ค.

์ผ์น˜ํ•˜์ง€์•Š๋Š” ๊ฒฝ์šฐ์— append์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.

1
2
3
4
5
6
7
8
9
10
File file = new File("data.avro");
DatumWriter<GenericRecord> writer =
 new GenericDatumWriter<GenericRecord>(schema);
DataFileWriter<GenericRecord> dataFileWriter =
new DataFileWriter<GenericRecord>(writer);
dataFileWriter.create(schema, file);
dataFileWriter.append(datum);
dataFileWriter.close();
 
cs

 

ํŒŒ์ผ์— ํฌํ•จ๋œ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์ฐธ์กฐํ•˜์—ฌ ์ฝ๊ธฐ ๋•Œ๋ฌธ์— ์Šคํ‚ค๋งˆ๋ฅผ ๋”ฐ๋กœ ์ •์˜ํ•˜์ง€์•Š์•„๋„๋จ

getSchema()๋ฅผ ์ด์šฉํ•˜๋ฉด DataFileReader ์ธ์Šคํ„ด์Šค์˜ ์Šคํ‚ค๋งˆ ์ •๋ณด ์–ป์„ ์ˆ˜ ์žˆ๊ณ  ์›๋ณธ ๊ฐ์ฒด์— ์‚ฌ์šฉํ•œ ์Šคํ‚ค๋งˆ์™€ ๊ฐ™์€์ง€ ํ™•์ธ๊ฐ€๋Šฅ 

1
2
3
4
DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
DataFileReader<GenericRecord> dataFileReader =
new DataFileReader<GenericRecord>(file, reader);
assertThat("Schema is the same", schema, is(dataFileReader.getSchema()));
cs

DataFileReader๋Š” ์ •๊ทœ ์ž๋ฐ” ๋ฐ˜๋ณต์ž๋กœ hasNext, next๋ฉ”์„œ๋“œ๋ฅผ ๋ฐ˜๋ณต์ ์œผ๋กœ ํ˜ธ์ถœํ•˜์—ฌ

๋ชจ๋“  ๋ฐ์ดํ„ฐ ๊ฐ์ฒด๋ฅผ ์ˆœํ™˜ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ ˆ์ฝ”๋“œ๊ฐ€ ํ•œ๊ฐœ๋งŒ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ๊ธฐ๋Œ€ํ•œ ํ•„๋“œ๊ฐ’ ์žˆ๋Š” ์ง€ ํ™•์ธ

1
2
3
4
5
assertThat(dataFileReader.hasNext(), is(true));
GenericRecord result = dataFileReader.next();
assertThat(result.get("left").toString(), is("L"));
assertThat(result.get("right").toString(), is("R"));
assertThat(dataFileReader.hasNext(), is(false));
cs

์ƒํ˜ธ ์šด์˜์„ฑ

ํŒŒ์ด์ฌ API

1
2
3
4
5
6
import os
import string
import sys
from avro import schema
from avro import io
from avro import datafile
cs

 

์—์ด๋ธŒ๋กœ ๋„๊ตฌ

1
% java -jar $AVRO_HOME/avro-tools-*.jar tojson pairs.avro
cs

 

์Šคํ‚ค๋งˆ ํ•ด์„

๊ธฐ๋กํ•  ๋•Œ ์‚ฌ์šฉํ•œ writer ์Šคํ‚ค๋งˆ์™€ ๋‹ค๋ฅธ reader์˜ ์Šคํ‚ค๋งˆ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค์‹œ ์ฝ์„ ์ˆ˜ ์žˆ๋‹ค,.

์ถ”๊ฐ€๋œ ํ•„๋“œ - reader ์‹ ๊ทœ์ผ ๋•Œ, reader๋Š” ์‹ ๊ทœ ํ•„๋“œ์˜ ๊ธฐ๋ณธ๊ฐ’์ด์šฉ

์ถ”๊ฐ€๋œ ํ•„๋“œ - writer ์‹ ๊ทœ์ผ ๋•Œ, reader๋Š” ์‹ ๊ทœ ํ•„๋“œ ๋ชจ๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ๋ฌด์‹œํ•จ

์ œ๊ฑฐ๋œ ํ•„๋“œ - reader ์‹ ๊ทœ์ผ ๋•Œ, ์‚ญ์ œ๋œ ํ•„๋“œ ๋ฌด์‹œ

์ œ๊ฑฐ๋œ ํ•„๋“œ - writer ์‹ ๊ทœ์ผ ๋•Œ, ์ œ๊ฑฐ๋œ ํ•„๋“œ ๊ธฐ๋กํ•˜์ง€ ์•Š์Œ. reader ์˜ ์Šคํ‚ค๋งˆ๋ฅผ writer ์Šคํ‚ค๋งˆ์™€ ๊ฐ™๊ฒŒ ๋งž์ถ”๊ฑฐ๋‚˜ ์ด์ „์œผ๋กœ ๊ฐฑ์‹ ํ•จ

์ •๋ ฌ ์ˆœ์„œ

record๋ฅผ ์ œ์™ธ์•ˆ ๋ชจ๋“  ์ž๋ฃŒํ˜•์—๋Š” ์ˆœ์„œ๊ฐ€ ์ •ํ•ด์ ธ์žˆ์Œ

record๋Š” order ์†์„ฑ ๋ช…์‹œํ•˜์—ฌ ์ •๋ ฌ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋‹ค.

์˜ค๋ฆ„์ฐจ์ˆœ (๊ธฐ๋ณธ)

๋‚ด๋ฆผ์ฐจ์ˆœ : descending

๋ฌด์‹œ : ignore

 

์—์ด๋ธŒ๋กœ ๋งต๋ฆฌ๋“€์Šค

๋‚ ์”จ ๋ ˆ์ฝ”๋“œ 

1
2
3
4
5
6
7
8
9
10
{
 "type""record",
 "name""WeatherRecord",
 "doc""A weather reading.",
 "fields": [
 {"name""year""type""int"},
 {"name""temperature""type""int"},
 {"name""stationId""type""string"}
 ]
}
cs

์ตœ๊ณ  ๊ธฐ์˜จ์„ ์ฐพ๋Š” ๋งต๋ฆฌ๋“€์Šค ํ”„๋กœ๊ทธ๋žจ, ์—์ด๋ธŒ๋กœ ์ถœ๋ ฅ ๋งŒ๋“ฆ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
public class AvroGenericMaxTemperature extends Configured implements Tool {
 
 private static final Schema SCHEMA = new Schema.Parser().parse(
 "{" +
 " \"type\": \"record\"," +
 " \"name\": \"WeatherRecord\"," +
 " \"doc\": \"A weather reading.\"," +
 " \"fields\": [" +
 " {\"name\": \"year\", \"type\": \"int\"}," +
 " {\"name\": \"temperature\", \"type\": \"int\"}," +
 " {\"name\": \"stationId\", \"type\": \"string\"}" +
 " ]" +
 "}"
 );
 public static class MaxTemperatureMapper
 extends Mapper<LongWritable, Text, AvroKey<Integer>,
 AvroValue<GenericRecord>> {
 private NcdcRecordParser parser = new NcdcRecordParser();
 private GenericRecord record = new GenericData.Record(SCHEMA);
 @Override
 protected void map(LongWritable key, Text value, Context context)
 throws IOException, InterruptedException {
 parser.parse(value.toString());
 if (parser.isValidTemperature()) {
 record.put("year", parser.getYearInt());
 record.put("temperature", parser.getAirTemperature());
 record.put("stationId", parser.getStationId());
 context.write(new AvroKey<Integer>(parser.getYearInt()),
 new AvroValue<GenericRecord>(record));
 }
 }
 }
 
 public static class MaxTemperatureReducer
 extends Reducer<AvroKey<Integer>, AvroValue<GenericRecord>,
 AvroKey<GenericRecord>, NullWritable> {
 @Override
 protected void reduce(AvroKey<Integer> key, Iterable<AvroValue<GenericRecord>>
 values, Context context) throws IOException, InterruptedException {
 GenericRecord max = null;
 for (AvroValue<GenericRecord> value : values) {
 GenericRecord record = value.datum();
 if (max == null ||
360 | Chapter 12: Avro (Integer) record.get("temperature"> (Integer) max.get("temperature")) {
 max = newWeatherRecord(record);
 }
 }
 context.write(new AvroKey(max), NullWritable.get());
 }
 private GenericRecord newWeatherRecord(GenericRecord value) {
 GenericRecord record = new GenericData.Record(SCHEMA);
 record.put("year", value.get("year"));
 record.put("temperature", value.get("temperature"));
 record.put("stationId", value.get("stationId"));
 return record;
 }
 }
 @Override
 public int run(String[] args) throws Exception {
 if (args.length != 2) {
 System.err.printf("Usage: %s [generic options] <input> <output>\n",
 getClass().getSimpleName());
 ToolRunner.printGenericCommandUsage(System.err);
 return -1;
 }
 Job job = new Job(getConf(), "Max temperature");
 job.setJarByClass(getClass());
 job.getConfiguration().setBoolean(
 Job.MAPREDUCE_JOB_USER_CLASSPATH_FIRST, true);
 FileInputFormat.addInputPath(job, new Path(args[0]));
 FileOutputFormat.setOutputPath(job, new Path(args[1]));
 AvroJob.setMapOutputKeySchema(job, Schema.create(Schema.Type.INT));
 AvroJob.setMapOutputValueSchema(job, SCHEMA);
 AvroJob.setOutputKeySchema(job, SCHEMA);
 job.setInputFormatClass(TextInputFormat.class);
 job.setOutputFormatClass(AvroKeyOutputFormat.class);
 job.setMapperClass(MaxTemperatureMapper.class);
 job.setReducerClass(MaxTemperatureReducer.class);
 return job.waitForCompletion(true) ? 0 : 1;
 }
 
 public static void main(String[] args) throws Exception {
 int exitCode = ToolRunner.run(new AvroGenericMaxTemperature(), args);
 System.exit(exitCode);
 }
}
cs

ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰

1
2
3
4
export HADOOP_CLASSPATH=avro-examples.jar
export HADOOP_USER_CLASSPATH_FIRST=true # override version of Avro in Hadoop
% hadoop jar avro-examples.jar AvroGenericMaxTemperature \
 input/ncdc/sample.txt output

๊ฒฐ๊ณผ๋ฌผ์ถœ๋ ฅ

1
2
3
% java -jar $AVRO_HOME/avro-tools-*.jar tojson output/part-r-00000.avro
{"year":1949,"temperature":111,"stationId":"012650-99999"}
{"year":1950,"temperature":22,"stationId":"011990-99999"}
cs

 

์—์ด๋ธŒ๋กœ ๋งต๋ฆฌ๋“€์Šค ์ด์šฉํ•ด ์ •๋ ฌ

์—์ด๋ธŒ๋กœ ๋ฐ์ดํ„ฐ ํŒŒ์ผ์„ ์ •๋ ฌํ•˜๋Š” ๋งต๋ฆฌ๋“€์Šค ํ”„๋กœ๊ทธ๋žจ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public class AvroSort extends Configured implements Tool {
 static class SortMapper<K> extends Mapper<AvroKey<K>, NullWritable,
 AvroKey<K>, AvroValue<K>> {
 @Override
 protected void map(AvroKey<K> key, NullWritable value,
 Context context) throws IOException, InterruptedException {
 context.write(key, new AvroValue<K>(key.datum()));
 }
 }
 static class SortReducer<K> extends Reducer<AvroKey<K>, AvroValue<K>,
 AvroKey<K>, NullWritable> {
 @Override
 protected void reduce(AvroKey<K> key, Iterable<AvroValue<K>> values,
 Context context) throws IOException, InterruptedException {
 for (AvroValue<K> value : values) {
 context.write(new AvroKey(value.datum()), NullWritable.get());
 }
 }
 }
 @Override
 public int run(String[] args) throws Exception {
 
 if (args.length != 3) {
 System.err.printf(
 "Usage: %s [generic options] <input> <output> <schema-file>\n",
 getClass().getSimpleName());
 ToolRunner.printGenericCommandUsage(System.err);
 return -1;
 }
 
 String input = args[0];
 String output = args[1];
 String schemaFile = args[2];
 Job job = new Job(getConf(), "Avro sort");
 job.setJarByClass(getClass());
 job.getConfiguration().setBoolean(Job.MAPREDUCE_JOB_USER_CLASSPATH_FIRST, true);
 FileInputFormat.addInputPath(job, new Path(input));
 FileOutputFormat.setOutputPath(job, new Path(output));
 AvroJob.setDataModelClass(job, GenericData.class);
 Schema schema = new Schema.Parser().parse(new File(schemaFile));
 AvroJob.setInputKeySchema(job, schema);
 AvroJob.setMapOutputKeySchema(job, schema);
 AvroJob.setMapOutputValueSchema(job, schema);
 AvroJob.setOutputKeySchema(job, schema);
 job.setInputFormatClass(AvroKeyInputFormat.class);
 job.setOutputFormatClass(AvroKeyOutputFormat.class);
 job.setOutputKeyClass(AvroKey.class);
 job.setOutputValueClass(NullWritable.class);
 job.setMapperClass(SortMapper.class);
 job.setReducerClass(SortReducer.class);
 return job.waitForCompletion(true) ? 0 : 1;
 }
 
 public static void main(String[] args) throws Exception {
 int exitCode = ToolRunner.run(new AvroSort(), args);
 System.exit(exitCode);
 }
}
cs

์ •๋ ฌ์€ ๋งต๋ฆฌ๋“€์Šค ์…”ํ”Œ ๊ณผ์ •์—์„œ ์ผ์–ด๋‚˜๋ฉฐ ์ •๋ ฌ๊ธฐ๋Šฅ์€ ์—์ด๋ธŒ๋กœ์˜ ์Šคํ‚ค๋งˆ์— ์˜ํ•ด ์ •ํ•ด์ง

์ž…๋ ฅ๋ฐ์ดํ„ฐ ์ ๊ฒ€

1
2
3
4
5
% java -jar $AVRO_HOME/avro-tools-*.jar tojson input/avro/pairs.avro
{"left":"a","right":"1"}
{"left":"c","right":"2"}
{"left":"b","right":"3"}
{"left":"b","right":"2"}
cs

ํ”„๋กœ๊ทธ๋žจ์‚ฌ์šฉํ•˜์—ฌ ์ •๋ ฌ

1
2
% hadoop jar avro-examples.jar AvroSort input/avro/pairs.avro output \
 ch12-avro/src/main/resources/SortedStringPair.avsc
cs

์ •๋ ฌ ํ›„ ์ €์žฅ๋œ ํŒŒ์ผ ์ถœ๋ ฅ

1
2
3
4
5
% java -jar $AVRO_HOME/avro-tools-*.jar tojson output/part-r-00000.avro
{"left":"b","right":"3"}
{"left":"b","right":"2"}
{"left":"c","right":"2"}
{"left":"a","right":"1"}
cs
728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

์ธํ”„๋ผ ์šด์˜ํ•  ๋•Œ ์ฃผ์˜ํ•ด์•ผํ•  ์ 

 

root ๊ณ„์ • ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•˜๊ธฐ ๋•Œ๋ฌธ์— sudo๊ถŒํ•œ์„ ๋ถ€์—ฌ๋ฐ›์€ ๋‹ค๋ฅธ ๊ณ„์ •์„ ์‚ฌ์šฉํ•ด์„œ ์ธํ”„๋ผ ๊ตฌ์ถ•์„ ์ง„ํ–‰ํ•œ๋‹ค.

 

์‚ฌ์šฉํ•  ๊ณ„์ • ์ƒ์„ฑ

# useradd test

๊ณ„์ • ๋น„๋ฐ€๋ฒˆํ˜ธ ์ง€์ •

# passwd test

sudoers ์ˆ˜์ •ํ•˜์—ฌ ํ•ด๋‹น ๊ณ„์ • sudo ๊ถŒํ•œ๊ณผ ํ•˜๋‹จ์— ๊ฐ™์€ ๊ทธ๋ฃน๋„ ๋ชจ๋“  ์ปค๋งจ๋“œ ์ˆ˜ํ–‰๊ฐ€๋Šฅํ•œ ๋ถ€๋ถ„์˜ ์ฃผ์„ ์ œ๊ฑฐ

# vi /etc/sudoers

test   ALL(=ALL)  ALL(=ALL)

%wheel ~~

 

ํ•˜๋‘ก์—์ฝ”์‹œ์Šคํ…œ ๊ตฌ์ถ•ํ•  ๋•Œ ๊ณตํ†ต์ ์œผ๋กœ ํ•„์š”ํ•œ ๋ถ€๋ถ„์ด ์žˆ๋‹ค.

 

1. ๋ฐฉํ™”๋ฒฝ

# systemctl disable firewalld

# systemctl stop firewalld

# vi /etc/selinux/config

SELINUX=disabled

ํ›„ ์žฌ๋ถ€ํŒ…ํ•œ๋‹ค.

 

2. install

$ sudo yum install ntp

$ sudo systemctl enable ntpd

$ sudo chkconfig ntpd on

 

3. ssh-key ์ƒ์„ฑํ•˜๊ธฐ

$ ssh-key

$ ssh-copy-key test@ip_address

 

4. ์ž๋ฐ” ์„ค์น˜

$ sudo yum install java-1.8.0-openjdk

 

5. DB ์„ค์น˜

$ sudo yum install postgresql*

$ su - postgres

$ postgres-setup initdb

$ systemctl enable postresql.service

$ systemctl start postresql.service

 

728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

hue ์„ค์น˜ ํ•  ๋•Œ ์•ž์„œ ์žˆ๋˜ ํ•˜๋‘ก ์—์ฝ”์‹œ์Šคํ…œ๋“ค์ด ์–ด๋А์ •๋„ ์„ค์น˜๋˜์—ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๊ณ  ์ง„ํ–‰ํ•˜๊ฒ ๋‹ค.

ํœด์˜ ๊ฒฝ์šฐ ์„ค์น˜ํ•˜๊ธฐ์ „์— ์‚ฌ์ „์ž‘์—…์„ ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

postgres๋Š” ๋‹ค๋ฅธ ํฌ์ŠคํŠธ์—์„œ ์„ค์ •์„ ๋‹ค๋ฃจ๊ธฐ๋กœ ํ•˜๊ณ ,

ํœด ์„ค์น˜ ๊ฐ€์ด๋“œ ์—์„œ๋Š” ํœด์—์„œ ์‚ฌ์šฉํ•  ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ์ƒ์„ฑ์ •๋„๋งŒ ๋‹ค๋ฃฐ ์˜ˆ์ •์ด๋‹ค.

 

์‚ฌ์ „์ž‘์—…

ํœด๋Š” ํŒŒ์ด์ฌ์„ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ™˜๊ฒฝ๋ณ€์ˆ˜๋กœ ํŒŒ์ด์ฌ ๋ฒ„์ „์„ ์žก์•„์ค˜์•ผํ•œ๋‹ค.

ํ™˜๊ฒฝ๋ณ€์ˆ˜๋Š” .bash_profile ์— ์ถ”๊ฐ€ํ•˜์˜€๋‹ค.

ํŒŒ์ด์ฌ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ถ”๊ฐ€

$ sudo vi ~/..bash_profile

export PYTHON_VER=python3.8

 

psycopg2 ์„ค์น˜ (์ „์— pip๋„ ์„ค์น˜๋˜์–ด ์žˆ์–ด์•ผํ•จ)

$ pip install psycopg2

$ python setup.py build

$ sudo python setup.py install

$ pip install psycopg2-binary


nodejs ์„ค์น˜ (centos7 ๊ธฐ์ค€ ์ด๋‹ค.)

 
$ sudo yum install epel-release

$ sudo yum install nodejs


hue ์—์„œ ์‚ฌ์šฉํ•˜๋Š” package ์„ค์น˜

$ sudo yum install ant asciidoc cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-plain gcc gcc-c++ krb5-devel libffi-devel libxml2-devel libxslt-devel make mysql mysql-devel openldap-devel python-devel sqlite-devel gmp-devel
cs


maven ์„ค์น˜

$ wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp

$ sudo tar xf /tmp/apache-maven-3.6.3-bin.tar.gz -C /opt

$ sudo ln -s /opt/apache-maven-3.6.0 /opt/maven 

$ sudo vi ~/.bash_profile

#MAVEN

export MAVEN_HOME=/opt/maven

export M2_HOME=$MAVEN_HOME

PATH=$PATH:$M2_HOME/bin:

$ source ~/.bash_profile

$ vi /opt/maven/conf/settings.xml


mirror ์‚ฌ์ดํŠธ ์ถ”๊ฐ€ํ•˜๊ธฐ

maven build๊ฐ€ ํ•„์š”ํ•œ ์•„ํŒŒ์น˜ ์˜คํ”ˆ์†Œ์Šค๋“ค์ด ์žˆ๋Š”๋ฐ, centos์˜ ๊ฒฝ์šฐ yum install maven์‹œ 3.0.5๊ฐ€ ์„ค์น˜๋œ๋‹ค.
3.0.5๋ฒ„์ „์œผ๋กœ ๋นŒ๋“œ ์‹œ fail์ด ๋นˆ๋ฒˆํ•˜๊ธฐ๋„ํ•˜๊ณ , ๊ณต์‹์‚ฌ์ดํŠธ์—์„œ๋„ 3.3์ด์ƒ ๋ฒ„์ „ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•˜๊ธฐ ๋•Œ๋ฌธ์—
์•„ํŒŒ์น˜ ๋ฏธ๋Ÿฌ ์‚ฌ์ดํŠธ์—์„œ ์ตœ์‹ ๋ฒ„์ „ maven์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค.

postgres์— hue db, user ์ถ”๊ฐ€ํ•˜๊ธฐ

psql -U postgres

CREATE USER hue WITH PASSWORD 'hue';

CREATE DATABASE hue OWNER hue;

\l

ํœด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์˜ค๋„ˆ ํ™•์ธํ•˜๊ธฐ

---

Solr ์„ค์น˜

https://n-a-y-a.tistory.com/m/68

 

[Solr] Apache solr 8.5.0 ์„ค์น˜ํ•˜๊ธฐ

ranger, atlas๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์„ ์„ค์น˜ํ•ด์•ผํ•˜๋Š” ์˜คํ”ˆ์†Œ์Šค์ด๋‹ค. https://archive.apache.org/dist/lucene/solr/8.5.0/ Index of /dist/lucene/solr/8.5.0 archive.apache.org ํ•ด๋‹น ์‚ฌ์ดํŠธ์—์„œ 8.5.0๋ฒ„์ „์„ ๋‹ค์šด ๋ฐ›..

n-a-y-a.tistory.com

---

 

ํœด ์„ค์น˜

 
$ wget https://cdn.gethue.com/downloads/hue-4.0.1.tgz

$ tar -xvzf hue-4.0.1.tgz

$ ln -s hue-4.0.0 hue

$ cd hue

$ export PREFIX=/usr/local

$ make 7$ make install

 


ํœด ์‹คํ–‰

 
$ ./build/env/bin/supervisor &

$ netstat -nltp | grep 8888

์ž…๋ ฅ์‹œ ์„œ๋น„์Šค ์˜ฌ๋ผ์˜จ ๊ฒƒ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.


***HDFS***
***HIVE***
***HBASE***
๋“ฑ ๊ฐ ์„œ๋น„์Šค๋“ค์€ ํ˜„์žฌ ์—ฐ๊ฒฐ๋œ ์ƒํƒœ๋Š” ์•„๋‹ˆ๋ฏ€๋กœ
๋งž๋Š” config๊ฐ’๋“ค์„ ์ฐพ์•„ ์ˆ˜์ •ํ•ด์ค˜์•ผํ•œ๋‹ค.


์ฐธ๊ณ ์‚ฌ์ดํŠธ
docs.gethue.com/administrator/installation/

 

Installation :: Hue SQL Assistant Documentation

docs.gethue.com

 

728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

์ฃผํ‚คํผ๋ž€ ๋ถ„์‚ฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์œ„ํ•œ ๋ถ„์‚ฐ ์ฝ”๋””๋„ค์ด์…˜์ด๋‹ค.

 

znode(์ €๋„๋…ธ๋“œ)๊ฐ€ ๊ฐ๊ฐ์˜ ์„œ๋ฒ„์— ์œ„์น˜ํ•ด ์žˆ๋‹ค.

๊ฐ ํ•˜๋‘ก์˜ ์„œ๋น„์Šค๋“ค์ด ์ž˜ ๋™์ž‘ํ•˜๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

์ฃผ๊ธฐ์ ์œผ๋กœ ํ•˜ํŠธ๋น„ํŠธ ์š”๊ตฌํ•˜์—ฌ ๋ฐ›๋Š” ๋ฐฉ์‹์œผ๋กœ,

 

๋”ฐ๋ผ์„œ ์ฃผ๊ธฐํผ๋Š” ํ™€์ˆ˜๋กœ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š”๋ฐ

์—ฌ๊ธฐ์„œ ๋“ค์–ด๊ฐ€๋Š” ๊ฐœ๋…์ด ์ฟผ๋Ÿผ์ด๋‹ค.

 

์ฟผ๋Ÿผ์ด๋ž€? 

๋‹ค์ˆ˜๊ฒฐ๋กœ ์˜ˆ๋ฅผ ๋“ค์–ด 5๊ฐœ์˜ ์„œ๋ฒ„๋กœ ๊ตฌ์„ฑ ๋˜์–ด์žˆ๊ณ ,

2๊ฐœ์˜ ์„œ๋ฒ„๊ฐ€ ์ฃฝ๋Š”๋‹ค๊ณ  ๊ฐ€์ •ํ–ˆ์„ ๋•Œ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•œ๋‹ค๊ณ  ํŒ๋‹จํ•œ๋‹ค.

๊ทธ๋ฆฌ๊ณ  5๊ฐœ ์ค‘ 3๊ฐœ์˜ ์„œ๋ฒ„๊ฐ€ ์ฃฝ์—ˆ์„ ๊ฒฝ์šฐ, ๋‹ค์ˆ˜๊ฒฐ๋กœ ์ธํ•ด ๋น„์ •์ƒ์ด๋ผ๊ณ  ํŒ๋‹คํ•œ๋‹ค.

๊ทธ๋กœ ์ธํ•ด, ์ฃผํ‚คํผ๋Š” ํ™€์ˆ˜๋กœ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๊ตฌ์„ฑํ•œ๋‹ค.

 

zookeeper ํด๋Ÿฌ์Šคํ„ฐ๋Š”

ํ•˜๋‚˜์˜ ์„œ๋ฒ„๊ฐ€ ๋ฆฌ๋”์ด๊ณ , ๋‹ค๋ฅธ ์„œ๋ฒ„๋Š” ํŒ”๋กœ์›Œ์ด๋‹ค

๋ฆฌ๋” ์„œ๋ฒ„๋ฅผ ๊ธฐ์ค€์œผ๋กœ sync๋ฅผ ๋งž์ถ˜๋‹ค.

 

์ž์„ธํ•œ ๋‚ด์šฉ์€ ๊ณต์‹ ์‚ฌ์ดํŠธ ์ฐธ์กฐ๋ฐ”๋žŒ

 

์ฃผํ‚คํผ ์„ค์น˜ ๋ฐฉ๋ฒ•

์ฃผํ‚คํผ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ํ›„ ์••์ถ• ํ•ด์ œ ํ›„ ํ…Œ์ŠคํŠธ

1
2
3
4
wget https://mirror.navercorp.com/apache/zookeeper/zookeeper-3.5.9/apache-zookeeper-3.5.9.tar.gz
tar xvzf apache-zookeeper-3.5.9.tar.gz
cd bin/zkCli.sh -server 127.0.0.1:2181
./zkCli.sh -server 127.0.0.1:2181
cs

 

์ฃผํ‚คํผ conf์—์„œ zoo.cfg ํŒŒ์ผ ์ƒ์„ฑ

1
2
3
4
5
6
$ vi $ZOOKEEPER_HOME/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/userDIr/zookeeper
clientPort=2181
cs

 

์ฃผํ‚คํผ ์‹คํ–‰

1
bin/zkServer.sh start
cs

 

jps๋กœ ์ฃผํ‚คํผ ์‹คํ–‰ ์ค‘์ธ์ง€ ํ™•์ธ

1
2
3
jps
-------------------
Quorumpeermain
cs

netstat -nltp | grep 2181๋กœ ์ฃผํ‚คํผ ํ™•์ธํ•˜๊ธฐ

 

 

์ฃผํ‚คํผ์˜ ํฌํŠธ๋ฒˆํ˜ธ๋Š” zoo.cfg ํŒŒ์ผ์—์„œ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

livy-env.sh

export SPARK_HOME=/usr/lib/spark

export HADOOP_CONF_DIR=/etc/hadoop/conf

 

livy start

./bin/livy-server start

 

livy ์ •์ƒ๋™์ž‘ํ•˜๋Š”์ง€ spark์—์„œ ํ…Œ์ŠคํŠธํ•˜๋Š” ์˜ˆ์ œ

sudo pip install requests

 

import json, pprint, requests, textwrap

host = 'http://localhost:8998'

data = {'kind': 'spark'}

headers = {'Content-Type': 'application/json'}

r = requests.post(host + '/sessions', data=json.dumps(data), headers=headers)

r.json() {u'state': u'starting', u'id': 0, u'kind': u'spark'}

728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•
$ wget https://archive.apache.org/dist/hbase/2.2.0/hbase-2.2.0-bin.tar.gz 
$ tar xvzf hbase-2.2.0-bin.tar.gz
$ ln -s hbase-2.2.0-bin hbase 

hbase ์„ค์น˜ ํ›„ ์••์ถ• ํ’€๊ณ  ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๊ฑด๋‹ค.

 

<configuration>
<property>
        <name>hbase.rootdir</name>
        <value>hdfs://localhost:9000/hbase</value>
</property>
<property>
        <name>hbase.master.port</name>
        <value>60000</value>
</property>
<property>
        <name>hbase.master.info.port</name>
        <value>60010</value>
</property>
<property>
        <name>hbase.regionserver.info.bindAddress</name>
        <value>0.0.0.0</value>
</property>
<property>
        <name>hbase.regionserver.port</name>
        <value>60020</value>
</property>
<property>
        <name>hbase.regionserver.info.port</name>
        <value>60030</value>
</property>
<property>
        <name>hbase.zookeeper.quorum</name>
        <value>bdh2</value>
</property>
<property>
        <name>hbase.zookeeper.property.clientPort</name>
        <value>2181</value>
</property>
<property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
</property>
<property>
        <name>hbase.unsafe.stream.capability.enforce</name>
        <value>false</value>
</property>
<property>
        <name>hbase.superuser</name>
        <value>user_name</value>
</property>
<property>
        <name>hbase.coprocessor.region.classes</name>
        <value>org.apache.hadoop.hbase.security.access.AccessController</value>
</property>
<property>
        <name>hbase.coprocessor.master.classes</name>
        <value>org.apache.hadoop.hbase.security.access.AccessController</value>
</property>
<property>
        <name>hbase.rpc.engine</name>
        <value>org.apache.hadoop.hbase.ipc.SecureRpcEngine</value>
</property>
<property>
        <name>hbase.security.authorization</name>
        <value>true</value>
</property>

hbase-site.xml ์—์„œ config ๊ฐ’๋“ค์„ ์„ค์ •ํ•œ๋‹ค. 

$ bin/start-hbase.shโ€‹

hbase bin ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ hbase๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

 

$ jps
------------------------
11410 HMaster 

jvm์— hbase๊ฐ€ ์‹คํ–‰ ์ค‘์ธ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

master ์„œ๋ฒ„์—๋Š” HMaster๊ฐ€ ์˜ฌ๋ผ์˜ค๊ณ 

slave ์„œ๋ฒ„์—๋Š” HRegionserver๊ฐ€ ์˜ฌ๋ผ์˜จ๋‹ค.

 

728x90
๋ฐ˜์‘ํ˜•

+ Recent posts