Pig从入门到精通2:Pig安装配置

Pig的安装模式有两种:本地模式和MapReduce模式(集群模式)。二者的区别是:本地模式操作的是本地Linux文件系统,不需要Hadoop的支持,所以不需要配置PIG_CLASSPATH参数,本地模式常用于测试;MapReduce模式又叫做集群模式,顾名思义,该模式需要Hadoop的支持,操作的是HDFS文件系统,需要通过PIG_CLASSPATH参数指定Hadoop配置文件的所在路径,MapReduce模式常用于实际的生产环境。本节就来介绍这两种模式详细的安装配置过程。

本节用到的安装介质:

pig-0.17.0.tar.gz

1.Pig本地模式的安装配置

(1)官网下载Pig的最新安装包

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@bigdata ~]# ls /root/tools/pig-0.17.0.tar.gz
/root/tools/pig-0.17.0.tar.gz</pre>

(2)解压至安装目录

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@bigdata ~]# tar -zxvf /root/tools/pig-0.17.0.tar.gz -C /root/trainings/</pre>

(3)设置PATH环境变量

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@bigdata ~]# vim /root/.bash_profile
PIG_HOME=/root/trainings/pig-0.17.0
export PIG_HOME
PATH=PIG_HOME/bin:PATH
export PATH
[root@bigdata ~]# source /root/.bash_profile</pre>

(4)启动本地模式

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@bigdata ~]# pig -x local
[root@bigdata tools]# pig -x local
18/09/24 16:17:06 INFO pig.ExecTypeProvider: Trying ExecType : LOCAL
18/09/24 16:17:06 INFO pig.ExecTypeProvider: Picked LOCAL as the ExecType
2018-09-24 16:17:06,985 [main] INFO org.apache.pig.Main - Apache Pig version 0.17.0 (r1797386) compiled Jun 02 2017, 15:41:58
2018-09-24 16:17:06,985 [main] INFO org.apache.pig.Main - Logging error messages to: /root/tools/pig_1537777026984.log
2018-09-24 16:17:07,010 [main] INFO org.apache.pig.impl.util.Utils - Default bootup file /root/.pigbootup not found
2018-09-24 16:17:07,174 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - mapred.job.tracker is deprecated. Instead, use mapreduce.jobtracker.address
2018-09-24 16:17:07,175 [main] INFO org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to hadoop file system at: file:///
2018-09-24 16:17:07,349 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - io.bytes.per.checksum is deprecated. Instead, use dfs.bytes-per-checksum
2018-09-24 16:17:07,362 [main] INFO org.apache.pig.PigServer - Pig Script ID for the session: PIG-default-4c59aed0-92e1-4fe5-b974-d8d55c254695
2018-09-24 16:17:07,363 [main] WARN org.apache.pig.PigServer - ATS is disabled since yarn.timeline-service.enabled set to false
grunt></pre>

说明:-x选项用于指明工作模式,local表示本地模式。

根据下面的打印出的日志可以知道当前Pig运行模式为本地模式,操作的是本地文件系统file:

Picked LOCAL as the ExecType

Connecting to hadoop file system at: file:///

(5)测试本地模式

查看当前工作目录:

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">grunt> pwd
file:/root/tools</pre>

查看根目录下面的内容:

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">grunt> ls /
file:/boot <dir>
file:/dev <dir>
file:/proc <dir>
file:/run <dir>
file:/sys <dir>
file:/etc <dir>
file:/root <dir>
file:/var <dir>
file:/tmp <dir>
file:/usr <dir>
file:/bin <dir>
file:/sbin <dir>
file:/lib <dir>
file:/lib64 <dir>
file:/home <dir>
file:/media <dir>
file:/mnt <dir>
file:/opt <dir>
file:/srv <dir>
file:/.autorelabel<r 1> 0</pre>

(6)退出pig

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">grunt> quit;
2018-09-24 16:23:25,663 [main] INFO org.apache.pig.Main - Pig script completed in 6 minutes, 19 seconds and 259 milliseconds (379259 ms)</pre>

2.Pig MapReduce模式的安装配置

(1)官网下载Pig的最新安装包

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@bigdata ~]# ls /root/tools/pig-0.17.0.tar.gz
/root/tools/pig-0.17.0.tar.gz</pre>

(2)解压至安装目录

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@bigdata ~]# tar -zxvf /root/tools/pig-0.17.0.tar.gz -C /root/trainings/</pre>

(3)设置PATH环境变量

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@bigdata ~]# vim /root/.bash_profile
PIG_HOME=/root/trainings/pig-0.17.0
export PIG_HOME
PATH=PIG_HOME/bin:PATH
export PATH
[root@bigdata ~]# source /root/.bash_profile</pre>

(4)设置PIG_CLASSPATH环境变量

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@bigdata ~]# vim /root/.bash_profile
PIG_CLASSPATH=/root/trainings/hadoop-2.7.3/etc/hadoop
export PIG_CLASSPATH
[root@bigdata ~]# source /root/.bash_profile</pre>

(5)启动Hadoop集群

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@bigdata hadoop]# start-all.sh
This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh
Starting namenodes on [bigdata]
bigdata: starting namenode, logging to /root/trainings/hadoop-2.7.3/logs/hadoop-root-namenode-bigdata.out
localhost: starting datanode, logging to /root/trainings/hadoop-2.7.3/logs/hadoop-root-datanode-bigdata.out
Starting secondary namenodes [0.0.0.0]
0.0.0.0: starting secondarynamenode, logging to /root/trainings/hadoop-2.7.3/logs/hadoop-root-secondarynamenode-bigdata.out
starting yarn daemons
starting resourcemanager, logging to /root/trainings/hadoop-2.7.3/logs/yarn-root-resourcemanager-bigdata.out
localhost: starting nodemanager, logging to /root/trainings/hadoop-2.7.3/logs/yarn-root-nodemanager-bigdata.out
[root@bigdata hadoop]# jps
2720 DataNode
2900 SecondaryNameNode
2582 NameNode
3064 ResourceManager
3322 NodeManager
3487 Jps</pre>

(6)启动Pig的MapReduce模式

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@bigdata ~]# pig
18/09/24 16:32:12 INFO pig.ExecTypeProvider: Trying ExecType : LOCAL
18/09/24 16:32:12 INFO pig.ExecTypeProvider: Trying ExecType : MAPREDUCE
18/09/24 16:32:12 INFO pig.ExecTypeProvider: Picked MAPREDUCE as the ExecType
2018-09-24 16:32:12,188 [main] INFO org.apache.pig.Main - Apache Pig version 0.17.0 (r1797386) compiled Jun 02 2017, 15:41:58
2018-09-24 16:32:12,188 [main] INFO org.apache.pig.Main - Logging error messages to: /root/pig_1537777932187.log
2018-09-24 16:32:12,208 [main] INFO org.apache.pig.impl.util.Utils - Default bootup file /root/.pigbootup not found
2018-09-24 16:32:12,652 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - mapred.job.tracker is deprecated. Instead, use mapreduce.jobtracker.address
2018-09-24 16:32:12,652 [main] INFO org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to hadoop file system at: hdfs://bigdata:9000
2018-09-24 16:32:13,144 [main] INFO org.apache.pig.PigServer - Pig Script ID for the session: PIG-default-137e17fb-e88a-4d00-821a-06b59a0349e0
2018-09-24 16:32:13,144 [main] WARN org.apache.pig.PigServer - ATS is disabled since yarn.timeline-service.enabled set to false
grunt>

说明:pig命令不加任何参数,默认启动MapReduce模式。
根据打印出的日志可以知道当前Pig的运行模式是MapReduce模式,操作的是HDFS文件系统:
Picked MAPREDUCE as the ExecType
Connecting to hadoop file system at: hdfs://bigdata:9000</pre>

(6)测试MapReduce模式

查看当前工作目录:

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">grunt> pwd
hdfs://bigdata:9000/user/root</pre>

查看HDFS根目录下的内容:

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">grunt> ls /
hdfs://bigdata:9000/hbase <dir>
hdfs://bigdata:9000/input <dir>
hdfs://bigdata:9000/output <dir>
hdfs://bigdata:9000/tmp <dir>
hdfs://bigdata:9000/user <dir></pre>

(7)退出pig

<pre style="box-sizing: border-box; border: 0px; font-family: "Courier 10 Pitch", Courier, monospace; font-size: 1.5rem; font-style: normal; font-weight: 400; margin: 0px 0px 1.6em; outline: 0px; padding: 1.6em; vertical-align: baseline; background: rgb(238, 238, 238); line-height: 1.6; max-width: 100%; overflow: auto; color: rgb(64, 64, 64); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">grunt> quit;
2018-09-24 16:36:24,915 [main] INFO org.apache.pig.Main - Pig script completed in 4 minutes, 12 seconds and 907 milliseconds (252907 ms)</pre>

本节详细介绍了Pig两种工作模式的安装配置过程,祝你玩得愉快!

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 201,784评论 5 474
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,745评论 2 378
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 148,702评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,229评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,245评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,376评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,798评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,471评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,655评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,485评论 2 318
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,535评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,235评论 3 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,793评论 3 304
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,863评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,096评论 1 258
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,654评论 2 348
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,233评论 2 341

推荐阅读更多精彩内容