<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Mon, 16 Sep 2024 05:44:52 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>[原创] 如何判断已经启动的TF-Serving服务是否正在使用</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%b7%b2%e7%bb%8f%e5%90%af%e5%8a%a8%e7%9a%84tf-serving%e6%9c%8d%e5%8a%a1%e6%98%af%e5%90%a6%e6%ad%a3%e5%9c%a8%e4%bd%bf%e7%94%a8/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%b7%b2%e7%bb%8f%e5%90%af%e5%8a%a8%e7%9a%84tf-serving%e6%9c%8d%e5%8a%a1%e6%98%af%e5%90%a6%e6%ad%a3%e5%9c%a8%e4%bd%bf%e7%94%a8/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 16 Sep 2024 04:27:03 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[TF-Serving]]></category>
		<category><![CDATA[TFServing]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=14136</guid>

					<description><![CDATA[<p>在一台服务器上，如果启动了一个TF-Serving服务，我们知道它占了资源，却不知道它是在空跑还是<span style="color:#ff0000;">真的在用</span>。<br />
本文描述了怎样判断它是否真的在用。<br />
<span id="more-14136"></span></p>
<div>
	用 nvidia-smi 命令能看到 TF-Serving 服务在运行：</div>
<p><img decoding="async" alt="TF-Serving is running" src="https://www.codelast.com/wp-content/uploads/2024/09/tf_serving_running.png" style="width: 700px; height: 149px;" /></p>
<div>
<div>
		其进程id是 22871，于是进一步查询这个进程的信息：</div>
<blockquote>
<div>
			ps -ef &#124; grep 22871</div>
</blockquote>
<div>
		输出类似于：</div>
<blockquote>
<div>
			root&#160; &#160; &#160;22871 22729 83 13:42 pts/0&#160; &#160; 00:06:35 tensorflow_model_server --port=8500 --rest_api_port=8501 --model_name=codelast --model_base_path=/models/codelast</div>
</blockquote>
<div>
		可见其REST服务的端口号为 8501。<br />
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>
<div>
			于是我们可以用 tcpdump 来捕获并分析流量，运行以下命令(需要 root 权限)：：</div>
<blockquote>
<div>
				sudo tcpdump -vv -i any &#39;port 8501&#39;</div>
</blockquote>
<div>
			如果有客户端正在向这个TF-Serving服务发送请求，我们应会看到这个命令有输出，不断在刷屏，类似于：
<div>
				<span style="color:#0000ff;">14:27:59.174425 IP (tos 0x0, ttl 60, id 51707, offset 0, flags [DF], proto TCP (6), length 1500)</span></div>
<div>
				<span style="color:#0000ff;">node.codelast.com.60679</span></div></div></div></div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%b7%b2%e7%bb%8f%e5%90%af%e5%8a%a8%e7%9a%84tf-serving%e6%9c%8d%e5%8a%a1%e6%98%af%e5%90%a6%e6%ad%a3%e5%9c%a8%e4%bd%bf%e7%94%a8/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<p>在一台服务器上，如果启动了一个TF-Serving服务，我们知道它占了资源，却不知道它是在空跑还是<span style="color:#ff0000;">真的在用</span>。<br />
本文描述了怎样判断它是否真的在用。<br />
<span id="more-14136"></span></p>
<div>
	用 nvidia-smi 命令能看到 TF-Serving 服务在运行：</div>
<p><img decoding="async" alt="TF-Serving is running" src="https://www.codelast.com/wp-content/uploads/2024/09/tf_serving_running.png" style="width: 700px; height: 149px;" /></p>
<div>
<div>
		其进程id是 22871，于是进一步查询这个进程的信息：</div>
<blockquote>
<div>
			ps -ef | grep 22871</div>
</blockquote>
<div>
		输出类似于：</div>
<blockquote>
<div>
			root&nbsp; &nbsp; &nbsp;22871 22729 83 13:42 pts/0&nbsp; &nbsp; 00:06:35 tensorflow_model_server --port=8500 --rest_api_port=8501 --model_name=codelast --model_base_path=/models/codelast</div>
</blockquote>
<div>
		可见其REST服务的端口号为 8501。<br />
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<div>
			于是我们可以用 tcpdump 来捕获并分析流量，运行以下命令(需要 root 权限)：：</div>
<blockquote>
<div>
				sudo tcpdump -vv -i any &#39;port 8501&#39;</div>
</blockquote>
<div>
			如果有客户端正在向这个TF-Serving服务发送请求，我们应会看到这个命令有输出，不断在刷屏，类似于：</p>
<div>
				<span style="color:#0000ff;">14:27:59.174425 IP (tos 0x0, ttl 60, id 51707, offset 0, flags [DF], proto TCP (6), length 1500)</span></div>
<div>
				<span style="color:#0000ff;">node.codelast.com.60679 &gt; 172.17.0.2.cmtp-mgt: Flags [.], cksum 0x310f (correct), seq 617580:619040, ack 1, win 63, length 1460</span></div>
<div>
				<span style="color:#0000ff;">14:27:59.174453 IP (tos 0x0, ttl 60, id 39347, offset 0, flags [DF], proto TCP (6), length 1500)</span></div>
<div>
				<span style="color:#0000ff;">node.codelast.com.32739 &gt; 172.17.0.2.cmtp-mgt: Flags [.], cksum 0x9354 (correct), seq 44268904:44270364, ack 1, win 86, length 1460</span></div>
<p>			如果没有请求发到TF-Serving服务，那么上面的命令什么都不会输出，就表明TF-Serving服务没在用。<br />
			<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
			<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
			转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
			感谢关注我的微信公众号（微信扫一扫）：<br />
			<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
			以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
				<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
</p></div>
<p>
		&nbsp;</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%b7%b2%e7%bb%8f%e5%90%af%e5%8a%a8%e7%9a%84tf-serving%e6%9c%8d%e5%8a%a1%e6%98%af%e5%90%a6%e6%ad%a3%e5%9c%a8%e4%bd%bf%e7%94%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 解决IntelliJ idea启动崩溃：error occurred during error reporting (), id 0x6, SIGABRT (0x6) at pc=...</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3intellij-idea%e5%90%af%e5%8a%a8%e5%b4%a9%e6%ba%83%ef%bc%9aerror-occurred-during-error-reporting-id-0x6-sigabrt-0x6-at-pc/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3intellij-idea%e5%90%af%e5%8a%a8%e5%b4%a9%e6%ba%83%ef%bc%9aerror-occurred-during-error-reporting-id-0x6-sigabrt-0x6-at-pc/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Fri, 15 Mar 2024 09:48:13 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[综合]]></category>
		<category><![CDATA[crash]]></category>
		<category><![CDATA[IntelliJ IDEA]]></category>
		<category><![CDATA[SIGABRT]]></category>
		<category><![CDATA[启动]]></category>
		<category><![CDATA[崩溃]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=14081</guid>

					<description><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2024/03/intellij_idea_logo.jpeg" style="width: 225px; height: 225px;" /></div>
<p>有时候，一个用了好久、一直好用的方法突然失灵，并且还折腾了几天，真的会逼疯人。<br />
前几天我就遇到了这种破事：在Ubuntu开发机上自己升级IntelliJ idea到最新版之后，就无法再启动它。<br />
启动时永远会崩溃，无论是重启系统、删除IntelliJ idea的本地缓存，或者使用回旧版，都无法再启动它（仿佛什么文件被&#34;污染&#34;了，再也回不去了），十分烦人。经过几天各种方法的尝试，终于解决了问题，我的解决办法不具有普适性，但如果你遇到了此类问题，或许可以为你提供一些解决思路。<br />
<span id="more-14081"></span><br />
OS：<span style="color:#0000ff;">Ubuntu 20.04.6 LTS</span><br />
JDK：<span style="color:#0000ff;">1.8.0_382</span><br />
原来安装的IntelliJ idea版本：<span style="color:#b22222;">idea-IC-232.8660.185</span><br />
从JetBrains官网上下载的新版IntelliJ idea版本：<span style="color:#b22222;">idea-IC-233.14808.21</span><br />
我当时不是利用IDE里的升级功能来升级的，而是自己下载了新版的压缩包，解压出来一个&#160;idea-IC-233.14808.21 目录，直接进入 bin 目录下执行 idea.sh 来跑的新版。众所周知，这样跑起来之后，新版会自动把旧版里的配置引入进来，只要没有问题，是可以无缝切换到新版不需要重新配置的。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
然而，启动新版的时候挂了，最后看到命令行报错：</p>
<blockquote>
<div>
		[error occurred during error reporting (), id 0x6, SIGABRT (0x6) at pc=0x00007fed3c5cf00b]</div>
<div>
		Aborted (core dumped)</div>
</blockquote>
<div>
	进不了IDE主界面。同时在/home目录下生成了一个内容超长的错误报告文件 java_error_in_idea_xxx.log</div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3intellij-idea%e5%90%af%e5%8a%a8%e5%b4%a9%e6%ba%83%ef%bc%9aerror-occurred-during-error-reporting-id-0x6-sigabrt-0x6-at-pc/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2024/03/intellij_idea_logo.jpeg" style="width: 225px; height: 225px;" /></div>
<p>有时候，一个用了好久、一直好用的方法突然失灵，并且还折腾了几天，真的会逼疯人。<br />
前几天我就遇到了这种破事：在Ubuntu开发机上自己升级IntelliJ idea到最新版之后，就无法再启动它。<br />
启动时永远会崩溃，无论是重启系统、删除IntelliJ idea的本地缓存，或者使用回旧版，都无法再启动它（仿佛什么文件被&quot;污染&quot;了，再也回不去了），十分烦人。经过几天各种方法的尝试，终于解决了问题，我的解决办法不具有普适性，但如果你遇到了此类问题，或许可以为你提供一些解决思路。<br />
<span id="more-14081"></span><br />
OS：<span style="color:#0000ff;">Ubuntu 20.04.6 LTS</span><br />
JDK：<span style="color:#0000ff;">1.8.0_382</span><br />
原来安装的IntelliJ idea版本：<span style="color:#b22222;">idea-IC-232.8660.185</span><br />
从JetBrains官网上下载的新版IntelliJ idea版本：<span style="color:#b22222;">idea-IC-233.14808.21</span><br />
我当时不是利用IDE里的升级功能来升级的，而是自己下载了新版的压缩包，解压出来一个&nbsp;idea-IC-233.14808.21 目录，直接进入 bin 目录下执行 idea.sh 来跑的新版。众所周知，这样跑起来之后，新版会自动把旧版里的配置引入进来，只要没有问题，是可以无缝切换到新版不需要重新配置的。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
然而，启动新版的时候挂了，最后看到命令行报错：</p>
<blockquote>
<div>
		[error occurred during error reporting (), id 0x6, SIGABRT (0x6) at pc=0x00007fed3c5cf00b]</div>
<div>
		Aborted (core dumped)</div>
</blockquote>
<div>
	进不了IDE主界面。同时在/home目录下生成了一个内容超长的错误报告文件 java_error_in_idea_xxx.log<br />
	我一开始并没有看这个log文件，而是按网上搜到的方法，分别尝试了：<br />
	1、重启系统<br />
	2、删除IntelliJ idea的缓存<br />
	3、使用回旧版IntelliJ idea<br />
	4、仿照<a href="https://youtrack.jetbrains.com/issue/IDEA-315192/IntelliJ-would-not-open-after-being-closed-once-on-Ubuntu-22.04-LTS.-The-only-solution-is-rebooting." rel="noopener" target="_blank">这个</a>类似的问题，卸载了snap又重新安装<br />
	以上方法都没用。<br />
	实在没辙了，只能硬着头皮看崩溃产生的日志文件&nbsp;java_error_in_idea_xxx.log，没想到一看就发现了端倪。<br />
	开头有一段内容是：</p>
<div>
<blockquote>
<div>
				# Problematic frame:</div>
<div>
				# C&nbsp; [x86_64-linux-gnu-tree-sitter-cpp.so+0x38ec09]&nbsp; tree_sitter_cpp_external_scanner_deserialize+0x179</div>
</blockquote>
<div>
<div>
				虽然我不知道它是什么确切的意思，但是这里写的是&quot;问题帧&quot;，说明崩溃和它有关。<br />
				<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></div>
<div>
				再往下看日志，会看到：</p>
<blockquote>
<div>
						---------------&nbsp; T H R E A D&nbsp; ---------------</div>
<div>
						&nbsp;</div>
<div>
						Current thread (0x00007fec7c02b370):&nbsp; JavaThread &quot;AWT-EventQueue-0&quot; [_thread_in_native, id=352672, stack(0x00007feb95ae5000,0x00007feb95be6000)]</div>
<div>
						&nbsp;</div>
<div>
						Stack: [0x00007feb95ae5000,0x00007feb95be6000],&nbsp; sp=0x00007feb95be0310,&nbsp; free space=1004k</div>
<div>
						Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)</div>
<div>
						C&nbsp; [x86_64-linux-gnu-tree-sitter-cpp.so+0x38ec09]&nbsp; tree_sitter_cpp_external_scanner_deserialize+0x179</div>
<div>
						C&nbsp; [x86_64-linux-gnu-tree-sitter.so+0x30b3e]&nbsp; ts_parser_reset+0x30e</div>
<div>
						C&nbsp; [x86_64-linux-gnu-tree-sitter.so+0x2e329]&nbsp; ts_parser_set_language+0x399</div>
<div>
						C&nbsp; [x86_64-linux-gnu-tree-sitter.so+0xb4875]&nbsp; Java_org_treesitter_TSParser_ts_1parser_1set_1language+0x25</div>
<div>
						j&nbsp; org.treesitter.TSParser.ts_parser_set_language(JJ)Z+0</div>
<div>
						j&nbsp; org.treesitter.TSParser.setLanguage(Lorg/treesitter/TSLanguage;)Z+10</div>
<div>
						j&nbsp; ai.codegeex.plugin.lang.agent.d.a()V+64</div>
<div>
						j&nbsp; ai.codegeex.plugin.lang.agent.d.&lt;init&gt;()V+365</div>
<div>
						j&nbsp; ai.codegeex.plugin.lang.agent.d.a()Lai/codegeex/plugin/lang/agent/d;+10</div>
<div>
						j&nbsp; ai.codegeex.plugin.lang.agent.CodegeexAgentCompletionService.e()V+0</div>
<div>
						j&nbsp; ai.codegeex.plugin.lang.agent.CodegeexAgentCompletionService.&lt;init&gt;()V+266</div>
</blockquote>
<div>
<div>
						可见，和出问题的&quot;x86_64-linux-gnu-tree-sitter-cpp.so+0x38ec09&quot;有关系的插件，第一个出现的就是&quot;ai.codegeex.plugin&quot;，这个对应的就是我安装的CodeGeeX插件。</div>
<div>
						所以我怀疑，删除这个插件可以解决IntelliJ idea启动崩溃的问题。</div>
<div>
						在Ubuntu系统上，插件安装在这个目录下：<span style="color:#0000ff;">~/.local/share/JetBrains/IdeaIC2023.3</span></div>
<div>
						其中，IdeaIC2023.3是IntelliJ idea的版本号，每升级一个版本，~/.local/share/JetBrains 目录下都会生成一个新的目录。</div>
<div>
						在这个目录下，会看到有一个名为&quot;CodeGeeX&quot;的目录，这个目录就是CodeGeeX插件的安装目录，删除它即可。</div>
<div>
						然后再次尝试启动IntelliJ idea，发现已经可以正常启动了。<br />
						虽然我现在还不知道为什么CodeGeeX插件会引起这个问题，但是如果你像我一样，实在找不到IDE崩溃的原因时，删除可能有问题的插件或许是解决问题的一个办法。<br />
						<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
						<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
						转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
						感谢关注我的微信公众号（微信扫一扫）：<br />
						<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
						以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
							<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
</p></div>
</p></div>
</p></div>
</p></div>
</p></div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3intellij-idea%e5%90%af%e5%8a%a8%e5%b4%a9%e6%ba%83%ef%bc%9aerror-occurred-during-error-reporting-id-0x6-sigabrt-0x6-at-pc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>如何查看指定的Hadoop(HDFS)目录的配额</title>
		<link>https://www.codelast.com/%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%8c%87%e5%ae%9a%e7%9a%84hadoophdfs%e7%9b%ae%e5%bd%95%e7%9a%84%e9%85%8d%e9%a2%9d/</link>
					<comments>https://www.codelast.com/%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%8c%87%e5%ae%9a%e7%9a%84hadoophdfs%e7%9b%ae%e5%bd%95%e7%9a%84%e9%85%8d%e9%a2%9d/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Thu, 11 May 2023 09:12:49 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[综合]]></category>
		<category><![CDATA[hadoop fs -count -q]]></category>
		<category><![CDATA[Hadoop目录配额]]></category>
		<category><![CDATA[HDFS目录配额]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13908</guid>

					<description><![CDATA[<p style="font-size: 16px; line-height: inherit; margin: 0px 0px 16px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-stretch: inherit; font-family: system-ui, -apple-system, BlinkMacSystemFont, &#34;Segoe UI&#34;, Roboto, &#34;Helvetica Neue&#34;, Arial, &#34;Noto Sans&#34;, sans-serif, &#34;Apple Color Emoji&#34;, &#34;Segoe UI Emoji&#34;, &#34;Segoe UI Symbol&#34;, &#34;Noto Color Emoji&#34;; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; vertical-align: baseline; color: rgb(17, 24, 39);">
	Hadoop目录的配额是指为了限制一个HDFS文件夹中所包含的数据块和名称空间元素（如子文件夹和文件）的数量而设置的最大值。简单来说，就是对一个文件夹中可存储数据的上限进行管理和控制，以便于维护整个系统的健康和性能。</p>
<p style="font-size: 16px; line-height: inherit; margin: 0px 0px 16px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-stretch: inherit; font-family: system-ui, -apple-system, BlinkMacSystemFont, &#34;Segoe UI&#34;, Roboto, &#34;Helvetica Neue&#34;, Arial, &#34;Noto Sans&#34;, sans-serif, &#34;Apple Color Emoji&#34;, &#34;Segoe UI Emoji&#34;, &#34;Segoe UI Symbol&#34;, &#34;Noto Color Emoji&#34;; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; vertical-align: baseline; color: rgb(17, 24, 39);">
	通过设置适当的配额，管理员可以确保每个目录不会超出其可承受的容量范围，防止集群资源被长时间占用或滥用。同时也可以通过监视使用情况来优化系统性能并减少故障风险。</p>
<p><span id="more-13908"></span></p>
<p>
	使用 <span style="color:#ff0000;">hadoop fs -count -q&#160;</span><span style="color:#0000ff;">&#60;your_hdfs_dir&#62;</span> 命令可以查看指定目录的配额，该命令输出有八列，以下是每列的含义：</p>
<ul>
<li>
		QUOTA：文件和目录的总数限制</li>
<li>
		REMAINING_QUOTA：该用户可以创建的剩余文件和目录总数</li>
<li>
		SPACE_QUOTA：授予该用户的空间配额</li>
<li>
		REMAINING_SPACE_QUOTA：该用户剩余的空间配额</li>
<li>
		DIR_COUNT：当前目录总数</li>
<li>
		FILE_COUNT：当前文件总数</li>
<li>
		CONTENT_SIZE：当前文件大小</li>
<li>
		PATH_NAME：目录路径</li>
</ul>
<p></p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;版权声明&#160;<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&#160;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" />&#8230; <a href="https://www.codelast.com/%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%8c%87%e5%ae%9a%e7%9a%84hadoophdfs%e7%9b%ae%e5%bd%95%e7%9a%84%e9%85%8d%e9%a2%9d/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p style="font-size: 16px; line-height: inherit; margin: 0px 0px 16px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-stretch: inherit; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, &quot;Helvetica Neue&quot;, Arial, &quot;Noto Sans&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Color Emoji&quot;; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; vertical-align: baseline; color: rgb(17, 24, 39);">
	Hadoop目录的配额是指为了限制一个HDFS文件夹中所包含的数据块和名称空间元素（如子文件夹和文件）的数量而设置的最大值。简单来说，就是对一个文件夹中可存储数据的上限进行管理和控制，以便于维护整个系统的健康和性能。</p>
<p style="font-size: 16px; line-height: inherit; margin: 0px 0px 16px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-stretch: inherit; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, &quot;Helvetica Neue&quot;, Arial, &quot;Noto Sans&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Color Emoji&quot;; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; vertical-align: baseline; color: rgb(17, 24, 39);">
	通过设置适当的配额，管理员可以确保每个目录不会超出其可承受的容量范围，防止集群资源被长时间占用或滥用。同时也可以通过监视使用情况来优化系统性能并减少故障风险。</p>
<p><span id="more-13908"></span></p>
<p>
	使用 <span style="color:#ff0000;">hadoop fs -count -q&nbsp;</span><span style="color:#0000ff;">&lt;your_hdfs_dir&gt;</span> 命令可以查看指定目录的配额，该命令输出有八列，以下是每列的含义：</p>
<ul>
<li>
		QUOTA：文件和目录的总数限制</li>
<li>
		REMAINING_QUOTA：该用户可以创建的剩余文件和目录总数</li>
<li>
		SPACE_QUOTA：授予该用户的空间配额</li>
<li>
		REMAINING_SPACE_QUOTA：该用户剩余的空间配额</li>
<li>
		DIR_COUNT：当前目录总数</li>
<li>
		FILE_COUNT：当前文件总数</li>
<li>
		CONTENT_SIZE：当前文件大小</li>
<li>
		PATH_NAME：目录路径</li>
</ul>
<p></p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%8c%87%e5%ae%9a%e7%9a%84hadoophdfs%e7%9b%ae%e5%bd%95%e7%9a%84%e9%85%8d%e9%a2%9d/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 如何下载HLS流视频文件</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e4%b8%8b%e8%bd%bdhls%e6%b5%81%e8%a7%86%e9%a2%91%e6%96%87%e4%bb%b6/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e4%b8%8b%e8%bd%bdhls%e6%b5%81%e8%a7%86%e9%a2%91%e6%96%87%e4%bb%b6/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Wed, 03 May 2023 10:12:39 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[下载HLS]]></category>
		<category><![CDATA[下载m3u8]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13899</guid>

					<description><![CDATA[<p>在互联网上，有些视频以HLS流的形式呈现，当你用一些工具捕获到它的播放地址时，会发现是一个以 .m3u8&#160;结尾的URL。<br />
那么，什么是 HLS&#160;和&#160;m3u8&#160;呢？</p>
<blockquote>
<p>
		HLS（HTTP Live Streaming）是一种基于HTTP协议的流媒体传输协议，而M3U8则是一种基于文本的播放列表文件格式。在HLS中，媒体数据被划分成多个小文件进行传输，并使用M3U8文件作为索引来指向这些媒体数据文件。M3U8文件包含了所有的媒体数据文件的URL地址及其相关信息，如码率、分辨率、编码格式等。因此，当一个客户端请求播放一个HLS流时，它将下载对应的M3U8索引文件，并且根据其中包含的地址去下载其他的媒体数据文件。简单来说，HLS和M3U8是两个不同但紧密相连的概念，其中M3U8作为HLS协议中索引与定位资源的重要组成部分。</p>
</blockquote>
<p>问题来了：如何下载HLS流视频文件呢？<br />
<span id="more-13899"></span><br />
有多种方法，下面略举一二。</p>
<p><span style="background-color: rgb(0, 255, 0);">➤</span>&#160;使用Chrome插件：<span style="color:#0000ff;">Video DownloadHelper</span><br />
这个插件可以捕获视频地址，也可以直接下载。但是直接下载HLS流视频每天有次数限制（很久以前是这样，不知道现在是什么情况），所以用此插件直接下载不可取。<br />
那么我们可以用它获取视频地址，再用类似于 <a href="https://github.com/HeiSir2014/M3U8-Downloader" rel="noopener" target="_blank">M3U8-Downloader</a>&#160;这样的桌面软件去下载这个地址指向的视频。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="background-color: rgb(0, 255, 0);">➤</span>&#160;使用跨平台的HLS下载工具&#160;<span style="color:#0000ff;">N_m3u8DL-RE</span><br />
<a href="https://github.com/nilaoda/N_m3u8DL-RE" rel="noopener" target="_blank">N_m3u8DL-RE</a>&#160;是一款跨平台的DASH/HLS/MSS下载工具，功能很强大。<br />
以Ubuntu Linux系统为例，只需简单地下载其release包，解压出来得到一个可执行程序&#160;N_m3u8DL-RE，然后这样用就可以下载HLS流视频了：</p>
<blockquote>
<p>
		./N_m3u8DL-RE &#60;m3u8_url&#62;</p>
</blockquote>
<p>N_m3u8DL-RE&#160;支持的参数非常多，可以参考其文档。<br />
如果首次运行的时候提示没有安装 ffmpeg，可以用 apt install ffmpeg&#160;安装，再运行。</p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;版权声明&#160;<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e4%b8%8b%e8%bd%bdhls%e6%b5%81%e8%a7%86%e9%a2%91%e6%96%87%e4%bb%b6/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>在互联网上，有些视频以HLS流的形式呈现，当你用一些工具捕获到它的播放地址时，会发现是一个以 .m3u8&nbsp;结尾的URL。<br />
那么，什么是 HLS&nbsp;和&nbsp;m3u8&nbsp;呢？</p>
<blockquote>
<p>
		HLS（HTTP Live Streaming）是一种基于HTTP协议的流媒体传输协议，而M3U8则是一种基于文本的播放列表文件格式。在HLS中，媒体数据被划分成多个小文件进行传输，并使用M3U8文件作为索引来指向这些媒体数据文件。M3U8文件包含了所有的媒体数据文件的URL地址及其相关信息，如码率、分辨率、编码格式等。因此，当一个客户端请求播放一个HLS流时，它将下载对应的M3U8索引文件，并且根据其中包含的地址去下载其他的媒体数据文件。简单来说，HLS和M3U8是两个不同但紧密相连的概念，其中M3U8作为HLS协议中索引与定位资源的重要组成部分。</p>
</blockquote>
<p>问题来了：如何下载HLS流视频文件呢？<br />
<span id="more-13899"></span><br />
有多种方法，下面略举一二。</p>
<p><span style="background-color: rgb(0, 255, 0);">➤</span>&nbsp;使用Chrome插件：<span style="color:#0000ff;">Video DownloadHelper</span><br />
这个插件可以捕获视频地址，也可以直接下载。但是直接下载HLS流视频每天有次数限制（很久以前是这样，不知道现在是什么情况），所以用此插件直接下载不可取。<br />
那么我们可以用它获取视频地址，再用类似于 <a href="https://github.com/HeiSir2014/M3U8-Downloader" rel="noopener" target="_blank">M3U8-Downloader</a>&nbsp;这样的桌面软件去下载这个地址指向的视频。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="background-color: rgb(0, 255, 0);">➤</span>&nbsp;使用跨平台的HLS下载工具&nbsp;<span style="color:#0000ff;">N_m3u8DL-RE</span><br />
<a href="https://github.com/nilaoda/N_m3u8DL-RE" rel="noopener" target="_blank">N_m3u8DL-RE</a>&nbsp;是一款跨平台的DASH/HLS/MSS下载工具，功能很强大。<br />
以Ubuntu Linux系统为例，只需简单地下载其release包，解压出来得到一个可执行程序&nbsp;N_m3u8DL-RE，然后这样用就可以下载HLS流视频了：</p>
<blockquote>
<p>
		./N_m3u8DL-RE &lt;m3u8_url&gt;</p>
</blockquote>
<p>N_m3u8DL-RE&nbsp;支持的参数非常多，可以参考其文档。<br />
如果首次运行的时候提示没有安装 ffmpeg，可以用 apt install ffmpeg&nbsp;安装，再运行。</p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e4%b8%8b%e8%bd%bdhls%e6%b5%81%e8%a7%86%e9%a2%91%e6%96%87%e4%bb%b6/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 设置Emacs打开一个文件时的&quot;文件太大&quot;警告阈值</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%ae%be%e7%bd%aeemacs%e6%89%93%e5%bc%80%e4%b8%80%e4%b8%aa%e6%96%87%e4%bb%b6%e6%97%b6%e7%9a%84%e6%96%87%e4%bb%b6%e5%a4%aa%e5%a4%a7%e8%ad%a6%e5%91%8a%e9%98%88%e5%80%bc/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%ae%be%e7%bd%aeemacs%e6%89%93%e5%bc%80%e4%b8%80%e4%b8%aa%e6%96%87%e4%bb%b6%e6%97%b6%e7%9a%84%e6%96%87%e4%bb%b6%e5%a4%aa%e5%a4%a7%e8%ad%a6%e5%91%8a%e9%98%88%e5%80%bc/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 24 Apr 2023 03:56:36 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[large file warning]]></category>
		<category><![CDATA[文件太大警告]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13891</guid>

					<description><![CDATA[<div>
	每次用emacs打开一个比较大的文件时，它都提示：</div>
<blockquote>
<div>
		File xxx is large (XXXMB), really open? (y or n)</div>
</blockquote>
<div>
	此时必须要按 y 才能继续打开此文件。</div>
<div>
	有没有办法调整这个文件大小的阈值，从而让它不那么烦人？<br />
	<span id="more-13891"></span><br />
	方法是：修改 ~/.emacs 文件，在里面添加如下配置：
<blockquote>
<div>
			;; set large file warning&#160;threshold when opening it</div>
<div>
			(setq large-file-warning-threshold (* 1024 1024 1024))</div>
</blockquote>
<p>	这表示当文件&#62;1GB时才会提示&#8220;文件太大&#8221;的警告，不超过1GB的文件直接就打开了，不需要用户按 y 确认。</p>
<p>
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
		<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;版权声明&#160;<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;<br />
		转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u></p></div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%ae%be%e7%bd%aeemacs%e6%89%93%e5%bc%80%e4%b8%80%e4%b8%aa%e6%96%87%e4%bb%b6%e6%97%b6%e7%9a%84%e6%96%87%e4%bb%b6%e5%a4%aa%e5%a4%a7%e8%ad%a6%e5%91%8a%e9%98%88%e5%80%bc/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<div>
	每次用emacs打开一个比较大的文件时，它都提示：</div>
<blockquote>
<div>
		File xxx is large (XXXMB), really open? (y or n)</div>
</blockquote>
<div>
	此时必须要按 y 才能继续打开此文件。</div>
<div>
	有没有办法调整这个文件大小的阈值，从而让它不那么烦人？<br />
	<span id="more-13891"></span><br />
	方法是：修改 ~/.emacs 文件，在里面添加如下配置：</p>
<blockquote>
<div>
			;; set large file warning&nbsp;threshold when opening it</div>
<div>
			(setq large-file-warning-threshold (* 1024 1024 1024))</div>
</blockquote>
<p>	这表示当文件&gt;1GB时才会提示&ldquo;文件太大&rdquo;的警告，不超过1GB的文件直接就打开了，不需要用户按 y 确认。</p>
<p>
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
		<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
		转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
		感谢关注我的微信公众号（微信扫一扫）：<br />
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
		以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%ae%be%e7%bd%aeemacs%e6%89%93%e5%bc%80%e4%b8%80%e4%b8%aa%e6%96%87%e4%bb%b6%e6%97%b6%e7%9a%84%e6%96%87%e4%bb%b6%e5%a4%aa%e5%a4%a7%e8%ad%a6%e5%91%8a%e9%98%88%e5%80%bc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 用JAVA程序读取本地的Hadoop sequence file</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8java%e7%a8%8b%e5%ba%8f%e8%af%bb%e5%8f%96%e6%9c%ac%e5%9c%b0%e7%9a%84hadoop-sequence-file/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8java%e7%a8%8b%e5%ba%8f%e8%af%bb%e5%8f%96%e6%9c%ac%e5%9c%b0%e7%9a%84hadoop-sequence-file/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Thu, 20 Apr 2023 12:23:18 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[综合]]></category>
		<category><![CDATA[Hadoop sequence file]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[本地]]></category>
		<category><![CDATA[读取]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13885</guid>

					<description><![CDATA[<div>
	Hadoop SequenceFile是Hadoop用于存储二进制键值对的文件格式。它支持存储不同的键值对类型,如:IntWritable/Text, NullWritable/BytesWritable等。</div>
<div>
	假设我的sequence file的key是BooleanWritable类型，value是Text类型，怎么读取它呢？<br />
	<span id="more-13885"></span></div>
<p>话不多说，直接上代码：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="java language-java hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">&#160;&#160;&#160;&#160;Configuration&#160;conf&#160;=&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&#160;Configuration();
&#160;&#160;&#160;&#160;FileSystem&#160;fs&#160;=&#160;FileSystem.getLocal(conf);
&#160;&#160;&#160;&#160;Path&#160;seqFilePath&#160;=&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&#160;Path(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;/path/to/your/sequence-file&#34;</span>);

&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&#160;打印出sequence&#160;file的key和value的类型</span>
&#160;&#160;&#160;&#160;&#160;&#160;SequenceFile.Reader&#160;reader&#160;=&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&#160;SequenceFile.Reader(fs,&#160;seqFilePath,&#160;conf);
&#160;&#160;&#160;&#160;&#160;&#160;Writable&#160;key&#160;=&#160;(Writable)&#160;reader.getKeyClass().newInstance();
&#160;&#160;&#160;&#160;&#160;&#160;Writable&#160;value&#160;=&#160;(Writable)&#160;reader.getValueClass().newInstance();
&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">while</span>&#160;(reader.next(key,&#160;value))&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;System.out.println(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;Key&#160;type:&#160;&#34;</span>&#160;+&#160;key.getClass());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;System.out.println(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;Value&#160;type:&#160;&#34;</span>&#160;+&#160;value.getClass());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">break</span>;
&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;reader.close();
&#160;&#160;&#160;&#160;}

&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&#160;打印出sequence&#160;file的内容</span>
&#160;&#160;&#160;&#160;&#160;&#160;SequenceFile.Reader&#160;reader&#160;=&#160;</code></pre>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8java%e7%a8%8b%e5%ba%8f%e8%af%bb%e5%8f%96%e6%9c%ac%e5%9c%b0%e7%9a%84hadoop-sequence-file/" class="read-more">Read More </a></section>]]></description>
										<content:encoded><![CDATA[<div>
	Hadoop SequenceFile是Hadoop用于存储二进制键值对的文件格式。它支持存储不同的键值对类型,如:IntWritable/Text, NullWritable/BytesWritable等。</div>
<div>
	假设我的sequence file的key是BooleanWritable类型，value是Text类型，怎么读取它呢？<br />
	<span id="more-13885"></span></div>
<p>话不多说，直接上代码：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="java language-java hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">&nbsp;&nbsp;&nbsp;&nbsp;Configuration&nbsp;conf&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;Configuration();
&nbsp;&nbsp;&nbsp;&nbsp;FileSystem&nbsp;fs&nbsp;=&nbsp;FileSystem.getLocal(conf);
&nbsp;&nbsp;&nbsp;&nbsp;Path&nbsp;seqFilePath&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;Path(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;/path/to/your/sequence-file&quot;</span>);

&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&nbsp;打印出sequence&nbsp;file的key和value的类型</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SequenceFile.Reader&nbsp;reader&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;SequenceFile.Reader(fs,&nbsp;seqFilePath,&nbsp;conf);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Writable&nbsp;key&nbsp;=&nbsp;(Writable)&nbsp;reader.getKeyClass().newInstance();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Writable&nbsp;value&nbsp;=&nbsp;(Writable)&nbsp;reader.getValueClass().newInstance();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">while</span>&nbsp;(reader.next(key,&nbsp;value))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;Key&nbsp;type:&nbsp;&quot;</span>&nbsp;+&nbsp;key.getClass());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;Value&nbsp;type:&nbsp;&quot;</span>&nbsp;+&nbsp;value.getClass());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">break</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader.close();
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&nbsp;打印出sequence&nbsp;file的内容</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SequenceFile.Reader&nbsp;reader&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;SequenceFile.Reader(fs,&nbsp;seqFilePath),&nbsp;conf);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BooleanWritable&nbsp;keyObj&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;BooleanWritable();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text&nbsp;valueObj&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;Text();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">while</span>&nbsp;(reader.next(keyObj,&nbsp;valueObj))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(keyObj.get()&nbsp;+&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;:&nbsp;&quot;</span>&nbsp;+&nbsp;valueObj);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader.close();
&nbsp;&nbsp;&nbsp;&nbsp;}
</code></pre>
</section>
<p>
输出类似于：</p>
<blockquote>
<div>
		Key type: class org.apache.hadoop.io.BooleanWritable</div>
<div>
		Value type: class org.apache.hadoop.io.Text<br />
		（文件内容此处省略）</div>
</blockquote>
<p>Maven依赖取决于你使用的Hadoop版本，下面是一个例子：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependencies</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>org.apache.hadoop<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>hadoop-common<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>3.2.1<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>org.apache.hadoop<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>hadoop-client<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>3.2.1<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>org.apache.hadoop<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>hadoop-hdfs<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>3.2.1<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependencies</span>&gt;</span></code></pre>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;关注不迷路&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;</p>
<p>
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8java%e7%a8%8b%e5%ba%8f%e8%af%bb%e5%8f%96%e6%9c%ac%e5%9c%b0%e7%9a%84hadoop-sequence-file/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] Apache Pig 加载/解析/读取 XML数据</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig-%e5%8a%a0%e8%bd%bd-%e8%a7%a3%e6%9e%90-%e8%af%bb%e5%8f%96-xml%e6%95%b0%e6%8d%ae/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig-%e5%8a%a0%e8%bd%bd-%e8%a7%a3%e6%9e%90-%e8%af%bb%e5%8f%96-xml%e6%95%b0%e6%8d%ae/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Wed, 18 Jan 2023 03:42:19 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[apache pig]]></category>
		<category><![CDATA[piggybank]]></category>
		<category><![CDATA[XMLLoader]]></category>
		<category><![CDATA[解析XML]]></category>
		<category><![CDATA[读取XML]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13817</guid>

					<description><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="XML logo" src="https://www.codelast.com/wp-content/uploads/ckfinder/images/xml.png" style="width: 200px; height: 200px;" /></div>
<p>查看更多Apache Pig的教程请点击<a href="https://www.codelast.com/?p=4550" rel="noopener" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>用Apache Pig加载/解析/读取XML数据不是一个常见的需求，但有时为了方便我们又不得不用，其实Pig的UDF库piggybank已经帮大家做好了这个工作了：只需要使用其中的<a href="https://pig.apache.org/docs/r0.17.0/api/org/apache/pig/piggybank/storage/XMLLoader.html" rel="noopener" target="_blank"><span style="background-color:#ffa07a;">XMLLoader</span></a>，就可以方便地实现XML文件解析。<br />
<span id="more-13817"></span><br />
假设有如下XML文件：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">&#60;?xml&#160;version=&#34;1.0&#34;&#160;encoding=&#34;UTF-8&#34;?&#62;
</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">users</span>&#62;</span>
&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&#62;</span>http://www.codelast.com/user/profile/159.html<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&#62;</span>159<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&#62;</span>李四<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&#62;</span>
&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&#62;</span>
&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&#62;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&#62;</span>http://www.codelast.com/user/profile/220.html</code></pre>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig-%e5%8a%a0%e8%bd%bd-%e8%a7%a3%e6%9e%90-%e8%af%bb%e5%8f%96-xml%e6%95%b0%e6%8d%ae/" class="read-more">Read More </a></section>]]></description>
										<content:encoded><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="XML logo" src="https://www.codelast.com/wp-content/uploads/ckfinder/images/xml.png" style="width: 200px; height: 200px;" /></div>
<p>查看更多Apache Pig的教程请点击<a href="https://www.codelast.com/?p=4550" rel="noopener" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>用Apache Pig加载/解析/读取XML数据不是一个常见的需求，但有时为了方便我们又不得不用，其实Pig的UDF库piggybank已经帮大家做好了这个工作了：只需要使用其中的<a href="https://pig.apache.org/docs/r0.17.0/api/org/apache/pig/piggybank/storage/XMLLoader.html" rel="noopener" target="_blank"><span style="background-color:#ffa07a;">XMLLoader</span></a>，就可以方便地实现XML文件解析。<br />
<span id="more-13817"></span><br />
假设有如下XML文件：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">&lt;?xml&nbsp;version=&quot;1.0&quot;&nbsp;encoding=&quot;UTF-8&quot;?&gt;
</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">users</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>http://www.codelast.com/user/profile/159.html<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>159<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>李四<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>http://www.codelast.com/user/profile/220.html<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>220<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>王五<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;
</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">users</span>&gt;</span></code></pre>
</section>
<p>首先我们欣赏一下这个XML文件，它用于存储多个用户的信息，&lt;users&gt;&lt;/users&gt; 标签把所有用户信息包裹在里面，&lt;user&gt;&lt;/user&gt; 标签则对应一个用户的信息。在每一个用户信息中，不仅有 profileUrl 这种第一层的属性，还有 data/id，data/name 这种更深层的属性，我们在下面的代码中，会把这些字段全部提取出来。<br />
这个XML虽然结构简单，但层次分明，通过解析这个XML文件，我们可以引申出对复杂XML文件的读取方法。<br />
这里需要特别说明一下，通常情况下存储在磁盘上的大数据都不会是这种&ldquo;格式化过&rdquo;的数据格式（为了方便大家观看，我把XML格式化成了上面的样子），而是一种紧凑的格式，例如可能是下面这个样子：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">&lt;?xml&nbsp;version=&quot;1.0&quot;&nbsp;encoding=&quot;UTF-8&quot;?&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">users</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>http://www.codelast.com/user/profile/159.html<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>159<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>李四<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span>http://www.codelast.com/user/profile/220.html<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">profileUrl</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span>220<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">id</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span>王五<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">data</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">user</span>&gt;</span><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">users</span>&gt;</span></code></pre>
</section>
<p>但是对piggybank的XMLLoader来说，上面的各种格式并不会影响它对XML内容的解析，这一点很好。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
话不多说，直接上代码：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="sql language-sql hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">--&nbsp;注册piggybank的jar包，视实际情况修改此路径</span>
REGISTER&nbsp;/xxx/piggybank.jar;

DEFINE&nbsp;XPath&nbsp;org.apache.pig.piggybank.evaluation.xml.XPath();

A&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">LOAD</span>&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;users.xml&#39;</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">USING</span>&nbsp;org.apache.pig.piggybank.storage.XMLLoader(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;user&#39;</span>)&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">AS</span>&nbsp;(x:&nbsp;chararray);
B&nbsp;=&nbsp;FOREACH&nbsp;A&nbsp;GENERATE&nbsp;XPath(x,&nbsp;&#39;user/profileUrl&#39;)&nbsp;AS&nbsp;profileUrl,&nbsp;XPath(x,&nbsp;&#39;user/data/id&#39;)&nbsp;AS&nbsp;id,&nbsp;XPath(x,&nbsp;&#39;user/data/name&#39;)&nbsp;AS&nbsp;name;
DUMP&nbsp;B;
</code></pre>
</section>
<p>代码解读：<br />
➤ XMLLoader 的参数&quot;user&quot;，应该是你的XML文件中，有多个标签的那个名字，例如，在上面的XML中，含有多个 user，但是只有一个 users，所以我们这里填的应该是 user<br />
➤ AS (x: chararray) 中的 &quot;x&quot; 其实可以是任意名称，我们下面只用这个名字来解析其下的字段，所以这个名字不重要。<br />
➤ 在 XPath() 中我们可以通过XML的层级关系来取出指定的字段，一看就明白。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
上面的代码输出：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="java language-java hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">(http:<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//www.codelast.com/user/profile/159.html,159,李四)</span>
(http:<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//www.codelast.com/user/profile/220.html,220,王五)</span></code></pre>
</section>
<p>也就是我们提取的3个字段。</p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig-%e5%8a%a0%e8%bd%bd-%e8%a7%a3%e6%9e%90-%e8%af%bb%e5%8f%96-xml%e6%95%b0%e6%8d%ae/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 通过第三方工具/JAVA程序访问S3存储</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e7%ac%ac%e4%b8%89%e6%96%b9%e5%b7%a5%e5%85%b7-java%e7%a8%8b%e5%ba%8f%e8%ae%bf%e9%97%aes3%e5%ad%98%e5%82%a8/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e7%ac%ac%e4%b8%89%e6%96%b9%e5%b7%a5%e5%85%b7-java%e7%a8%8b%e5%ba%8f%e8%ae%bf%e9%97%aes3%e5%ad%98%e5%82%a8/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 14 Nov 2022 16:32:43 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[s3-command-line]]></category>
		<category><![CDATA[对象存储]]></category>
		<category><![CDATA[访问]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13652</guid>

					<description><![CDATA[<p>S3是亚马逊2006年推出的简单存储服务（Simple Storage Service），理论上是一个全球存储区域网络，你可以把它想像成一个超大的硬盘，可以在其中存储和检索数字资产，通过 S3 存储和检索的资产被称为对象，对象存储在存储段（bucket）中。<br />
很多公司都推出了自己的对象存储服务，例如阿里云对象存储服务OSS，可以使用S3 API进行访问。<br />
<span id="more-13652"></span><br />
话不多说，我们看看如何读写S3。<br />
<span style="color:#ff0000;">➤</span> 通过第三方工具<br />
这种工具很多，<a href="https://github.com/lpflpf/s3-command-line" rel="noopener" target="_blank">s3-command-line</a>&#160;就是一个。这是一个GoLang开发的命令行工具，编译出来只有13MB。它支持文件的上传、下载、删除、列表，已经满足了大多数使用场景需求。<br />
checkout它的源码，在安装有Go语言环境的服务器上执行 go build&#160;即可编译出可执行程序 s3-command-line，这个只需要做一次，最终运行 s3-command-line&#160;软件的服务器上并不需要安装GoLang环境。<br />
在使用 s3-command-line&#160;之前，我们需要创建一个配置文件 <span style="color:#0000ff;">config.json</span>，填入我们访问S3所需的密钥等信息：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="json language-json hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">{
&#160;&#160;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&#34;id&#34;</span>:&#160;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;...&#34;</span>,
&#160;&#160;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&#34;secret&#34;</span>:&#160;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;...&#34;</span>,
&#160;&#160;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&#34;endPoint&#34;</span>:&#160;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;http://...&#34;</span>,
&#160;&#160;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&#34;region&#34;</span>:&#160;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;...&#34;</span></code></pre>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e7%ac%ac%e4%b8%89%e6%96%b9%e5%b7%a5%e5%85%b7-java%e7%a8%8b%e5%ba%8f%e8%ae%bf%e9%97%aes3%e5%ad%98%e5%82%a8/" class="read-more">Read More </a></section>]]></description>
										<content:encoded><![CDATA[<p>S3是亚马逊2006年推出的简单存储服务（Simple Storage Service），理论上是一个全球存储区域网络，你可以把它想像成一个超大的硬盘，可以在其中存储和检索数字资产，通过 S3 存储和检索的资产被称为对象，对象存储在存储段（bucket）中。<br />
很多公司都推出了自己的对象存储服务，例如阿里云对象存储服务OSS，可以使用S3 API进行访问。<br />
<span id="more-13652"></span><br />
话不多说，我们看看如何读写S3。<br />
<span style="color:#ff0000;">➤</span> 通过第三方工具<br />
这种工具很多，<a href="https://github.com/lpflpf/s3-command-line" rel="noopener" target="_blank">s3-command-line</a>&nbsp;就是一个。这是一个GoLang开发的命令行工具，编译出来只有13MB。它支持文件的上传、下载、删除、列表，已经满足了大多数使用场景需求。<br />
checkout它的源码，在安装有Go语言环境的服务器上执行 go build&nbsp;即可编译出可执行程序 s3-command-line，这个只需要做一次，最终运行 s3-command-line&nbsp;软件的服务器上并不需要安装GoLang环境。<br />
在使用 s3-command-line&nbsp;之前，我们需要创建一个配置文件 <span style="color:#0000ff;">config.json</span>，填入我们访问S3所需的密钥等信息：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="json language-json hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">{
&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;id&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;...&quot;</span>,
&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;secret&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;...&quot;</span>,
&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;endPoint&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;http://...&quot;</span>,
&nbsp;&nbsp;<span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">&quot;region&quot;</span>:&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;...&quot;</span>
}
</code></pre>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
这些信息你可以在你使用的S3平台上找到。<br />
假设我们要读写的bucket名为 <span style="color:#0000ff;">my-bucket</span>，那么下面的命令会告诉你怎么使用 s3-command-line：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="bash language-bash hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">列出指定&nbsp;bucket&nbsp;里的文件：
./s3-command-line&nbsp;ls&nbsp;-c&nbsp;config.json&nbsp;my-bucket&nbsp;/

从指定的&nbsp;bucket&nbsp;删除文件&nbsp;1.txt：
./s3-command-line&nbsp;rm&nbsp;-c&nbsp;config.json&nbsp;my-bucket&nbsp;1.txt

上传本地文件&nbsp;1.txt&nbsp;到指定的&nbsp;bucket：
./s3-command-line&nbsp;put&nbsp;-c&nbsp;config.json&nbsp;my-bucket&nbsp;1.txt

从指定的&nbsp;bucket&nbsp;下载文件&nbsp;1.txt&nbsp;到本地：
./s3-command-line&nbsp;get&nbsp;-c&nbsp;config.json&nbsp;my-bucket&nbsp;1.txt
</code></pre>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
总结：简单好用，编译成可执行程序后没有对其他library的依赖，令人舒适。</p>
<p><span style="color: rgb(255, 0, 0);">➤</span>&nbsp;自己写JAVA程序<br />
JDK版本：1.8.0_221，Maven：3.6.3<br />
首先你需要在 pom.xml&nbsp;中添加相关依赖（参考<a href="https://github.com/aws/aws-sdk-java-v2/#using-the-sdk" rel="noopener" target="_blank">这里</a>）：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>software.amazon.awssdk<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>aws-sdk-java<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>
&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>2.18.16<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span></code></pre>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
然后就可以开始写代码了（测试可用）：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="java language-java hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">package</span>&nbsp;com.codelast;


<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;lombok.extern.slf4j.Slf4j;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;org.apache.commons.lang.StringUtils;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;org.kohsuke.args4j.CmdLineException;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;org.kohsuke.args4j.CmdLineParser;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;org.kohsuke.args4j.Option;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.core.sync.RequestBody;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.regions.Region;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.services.s3.S3Client;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.services.s3.model.PutObjectRequest;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.services.s3.model.PutObjectResponse;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;software.amazon.awssdk.services.s3.model.S3Exception;

<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;java.io.File;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;java.io.FileInputStream;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;java.io.IOException;
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">import</span>&nbsp;java.net.URI;

<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">/**
&nbsp;*&nbsp;S3存储操作类。
&nbsp;*&nbsp;参考：https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/s3/src/main/java/com/example/s3/PutObject.java
&nbsp;*
&nbsp;*&nbsp;<span class="hljs-doctag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">@author</span>&nbsp;DarranZhang@codelast.com
&nbsp;*&nbsp;<span class="hljs-doctag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">@version</span>&nbsp;2022-11-14
&nbsp;*/
</span>
<span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">@Slf</span>4j
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-class" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">class</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">S3Operator</span>&nbsp;</span>{
&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">final</span>&nbsp;String&nbsp;ACCESS_KEY&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;your_key&quot;</span>;
&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">final</span>&nbsp;String&nbsp;SECRET_KEY&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;your_secret&quot;</span>;
&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">final</span>&nbsp;String&nbsp;END_POINT&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;http://your_end_point_url&quot;</span>;
&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">final</span>&nbsp;String&nbsp;REGION&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;your_region&quot;</span>;
&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">final</span>&nbsp;String&nbsp;BUCKET_NAME&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;your_bucket_name&quot;</span>;

&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">private</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-class" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">class</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">Options</span>&nbsp;</span>{
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">@Option</span>(name&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;--localFile&quot;</span>,&nbsp;usage&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;the&nbsp;path&nbsp;of&nbsp;the&nbsp;local&nbsp;file&nbsp;to&nbsp;upload&nbsp;to&nbsp;S3&quot;</span>,&nbsp;required&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">true</span>)
&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;localFile;
&nbsp;&nbsp;}

&nbsp;&nbsp;<span class="hljs-function" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">void</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">main</span><span class="hljs-params" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(255, 152, 35); word-wrap: inherit !important; word-break: inherit !important;">(String[]&nbsp;args)</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">throws</span>&nbsp;Exception&nbsp;</span>{
&nbsp;&nbsp;&nbsp;&nbsp;Options&nbsp;opts&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;Options();
&nbsp;&nbsp;&nbsp;&nbsp;CmdLineParser&nbsp;parser&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;CmdLineParser(opts);
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">try</span>&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parser.parseArgument(args);
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">catch</span>&nbsp;(CmdLineException&nbsp;e)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.error(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;command&nbsp;parse&nbsp;fail&quot;</span>,&nbsp;e);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.exit(<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">1</span>);
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;S3Operator&nbsp;operator&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;S3Operator();
&nbsp;&nbsp;&nbsp;&nbsp;operator.upload(opts.localFile);
&nbsp;&nbsp;}

&nbsp;&nbsp;<span class="hljs-function" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">private</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">void</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">upload</span><span class="hljs-params" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(255, 152, 35); word-wrap: inherit !important; word-break: inherit !important;">(String&nbsp;localFile)</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">throws</span>&nbsp;Exception&nbsp;</span>{
&nbsp;&nbsp;&nbsp;&nbsp;AwsBasicCredentials&nbsp;credentials&nbsp;=&nbsp;AwsBasicCredentials.create(ACCESS_KEY,&nbsp;SECRET_KEY);
&nbsp;&nbsp;&nbsp;&nbsp;Region&nbsp;region&nbsp;=&nbsp;Region.of(REGION);
&nbsp;&nbsp;&nbsp;&nbsp;S3Client&nbsp;s3Client&nbsp;=&nbsp;S3Client.builder()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.endpointOverride(<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;URI(END_POINT))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.region(region)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.credentialsProvider(StaticCredentialsProvider.create(credentials))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.build();

&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;s3FileName&nbsp;=&nbsp;StringUtils.substringAfterLast(localFile,&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;/&quot;</span>);&nbsp;&nbsp;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&nbsp;上传到S3之后的文件名，不一定要和本地文件名一致，但为了直观，这里保持一致</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">if</span>&nbsp;(StringUtils.isEmpty(s3FileName))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;msg&nbsp;=&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;local&nbsp;file&nbsp;name&nbsp;is&nbsp;empty&quot;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.error(msg);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">throw</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;RuntimeException(msg);
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">//&nbsp;每次上传前，不用先删除再上传，因为最新上传的同名文件会覆盖之前的文件</span>
&nbsp;&nbsp;&nbsp;&nbsp;putObject(s3Client,&nbsp;BUCKET_NAME,&nbsp;s3FileName,&nbsp;localFile);
&nbsp;&nbsp;&nbsp;&nbsp;s3Client.close();
&nbsp;&nbsp;}

&nbsp;&nbsp;<span class="hljs-function" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">void</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">putObject</span><span class="hljs-params" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(255, 152, 35); word-wrap: inherit !important; word-break: inherit !important;">(S3Client&nbsp;s3Client,&nbsp;String&nbsp;bucketName,&nbsp;String&nbsp;objectKey,&nbsp;String&nbsp;objectPath)</span>&nbsp;</span>{
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">try</span>&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PutObjectRequest&nbsp;request&nbsp;=&nbsp;PutObjectRequest.builder().bucket(bucketName).key(objectKey).build();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PutObjectResponse&nbsp;response&nbsp;=&nbsp;s3Client.putObject(request,&nbsp;RequestBody.fromBytes(getObjectFile(objectPath)));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;successfully&nbsp;upload&nbsp;file&nbsp;[{}]&nbsp;to&nbsp;S3,&nbsp;entity&nbsp;tag:&nbsp;[{}]&quot;</span>,&nbsp;objectPath,&nbsp;response.eTag());
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">catch</span>&nbsp;(S3Exception&nbsp;e)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.error(String.format(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;failed&nbsp;to&nbsp;upload&nbsp;file&nbsp;[%s]&nbsp;to&nbsp;S3&quot;</span>,&nbsp;objectPath),&nbsp;e);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}

&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">private</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">byte</span>[]&nbsp;getObjectFile(String&nbsp;filePath)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;FileInputStream&nbsp;fileInputStream&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">null</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">byte</span>[]&nbsp;bytesArray&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">null</span>;

&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">try</span>&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File&nbsp;file&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;File(filePath);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bytesArray&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">byte</span>[(<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">int</span>)&nbsp;file.length()];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileInputStream&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;FileInputStream(file);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileInputStream.read(bytesArray);
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">catch</span>&nbsp;(IOException&nbsp;e)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">finally</span>&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">if</span>&nbsp;(fileInputStream&nbsp;!=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">null</span>)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">try</span>&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileInputStream.close();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">catch</span>&nbsp;(IOException&nbsp;e)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">return</span>&nbsp;bytesArray;
&nbsp;&nbsp;}

&nbsp;&nbsp;<span class="hljs-function" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">private</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">static</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; overflow-wrap: inherit !important; word-break: inherit !important;">void</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">deleteObject</span><span class="hljs-params" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(255, 152, 35); word-wrap: inherit !important; word-break: inherit !important;">(S3Client&nbsp;s3,&nbsp;String&nbsp;bucket,&nbsp;String&nbsp;s3FileName)</span>&nbsp;</span>{
&nbsp;&nbsp;&nbsp;&nbsp;DeleteObjectRequest&nbsp;request&nbsp;=&nbsp;DeleteObjectRequest.builder().bucket(bucket).key(s3FileName).build();
&nbsp;&nbsp;&nbsp;&nbsp;s3.deleteObject(request);
&nbsp;&nbsp;}
}
</code></pre>
</section>
<p> 这样我们就实现了用JAVA访问S3，不过，如果你仔细看会发现，当引入S3的依赖后，你的项目编译出的 fat jar&nbsp;体积剧增了400MB左右！这也太恶心了...<br />
当然，上面引入的 whole-SDK 依赖，是我为了省事引入了所有S3相关的模块，或许你有些用不到的模块，可以不用引入 whole-SDK，而是分别引入单独的模块，但我有空去想这些玩意的话，还不如使用 s3-command-line&nbsp;简单呢，不是吗？毕竟时间就是生命，别在这些无聊的事上浪费生命。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;总结<br />
如果你操作S3时只使用上传、下载、删除、列表功能，那么建议不要自己写代码，使用 s3-command-line&nbsp;更香。</p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e7%ac%ac%e4%b8%89%e6%96%b9%e5%b7%a5%e5%85%b7-java%e7%a8%8b%e5%ba%8f%e8%ae%bf%e9%97%aes3%e5%ad%98%e5%82%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] Apache Pig如何按数据分组保存到不同的子目录中(MultiStorage)</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig%e5%a6%82%e4%bd%95%e6%8c%89%e6%95%b0%e6%8d%ae%e5%88%86%e7%bb%84%e4%bf%9d%e5%ad%98%e5%88%b0%e4%b8%8d%e5%90%8c%e7%9a%84%e5%ad%90%e7%9b%ae%e5%bd%95%e4%b8%admultistorage/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig%e5%a6%82%e4%bd%95%e6%8c%89%e6%95%b0%e6%8d%ae%e5%88%86%e7%bb%84%e4%bf%9d%e5%ad%98%e5%88%b0%e4%b8%8d%e5%90%8c%e7%9a%84%e5%ad%90%e7%9b%ae%e5%bd%95%e4%b8%admultistorage/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sun, 06 Nov 2022 06:30:06 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[综合]]></category>
		<category><![CDATA[apache pig]]></category>
		<category><![CDATA[MultiStorage]]></category>
		<category><![CDATA[多目录]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13628</guid>

					<description><![CDATA[<p>查看更多Apache Pig的教程请点击<a href="https://www.codelast.com/?p=4550" rel="noopener" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>用Apache Pig进行数据处理的时候，我们通常会在最后把处理结果保存到一个HDFS目录下：</p>
<blockquote>
<p>
		STORE result INTO &#39;/my_output_dir&#39;;</p>
</blockquote>
<p>这是最常见的情况。<br />
但是，如果我们想根据某个字段，把数据分成多组，分别存储在多个目录下呢？举个可能不恰当的例子，就有点像我们先把数据按某个字段分组：</p>
<blockquote>
<p>
		GROUP data BY field;</p>
</blockquote>
<p>再把各个group的数据分别存储在不同的目录下一样。<br />
<span id="more-13628"></span><br />
现在来看一个实例。<br />
假设有如下数据（用 tab&#160;分隔的四列分别为：人员类型的id，人员类型的描述，姓名，爱好）：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<table style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; width: 100%;">
<thead style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				type</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				desc</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				name</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				hobby</th>
</tr>
</thead>
<tbody style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border: 0px;">
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				陈玉</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				篮球</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				3</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				老师</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				王强</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				足球</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				1</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				保安</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				许勤</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				下棋</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				范雨</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				跑步</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				李林</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				游泳</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				1</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				保安</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				涂欣</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				看书</td>
</tr>
</tbody>
</table>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig%e5%a6%82%e4%bd%95%e6%8c%89%e6%95%b0%e6%8d%ae%e5%88%86%e7%bb%84%e4%bf%9d%e5%ad%98%e5%88%b0%e4%b8%8d%e5%90%8c%e7%9a%84%e5%ad%90%e7%9b%ae%e5%bd%95%e4%b8%admultistorage/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>查看更多Apache Pig的教程请点击<a href="https://www.codelast.com/?p=4550" rel="noopener" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>用Apache Pig进行数据处理的时候，我们通常会在最后把处理结果保存到一个HDFS目录下：</p>
<blockquote>
<p>
		STORE result INTO &#39;/my_output_dir&#39;;</p>
</blockquote>
<p>这是最常见的情况。<br />
但是，如果我们想根据某个字段，把数据分成多组，分别存储在多个目录下呢？举个可能不恰当的例子，就有点像我们先把数据按某个字段分组：</p>
<blockquote>
<p>
		GROUP data BY field;</p>
</blockquote>
<p>再把各个group的数据分别存储在不同的目录下一样。<br />
<span id="more-13628"></span><br />
现在来看一个实例。<br />
假设有如下数据（用 tab&nbsp;分隔的四列分别为：人员类型的id，人员类型的描述，姓名，爱好）：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<table style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; width: 100%;">
<thead style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				type</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				desc</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				name</th>
<th style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em; text-align: left; background-color: rgb(240, 240, 240);">
				hobby</th>
</tr>
</thead>
<tbody style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border: 0px;">
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				陈玉</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				篮球</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				3</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				老师</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				王强</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				足球</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				1</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				保安</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				许勤</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				下棋</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				范雨</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				跑步</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				2</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				学生</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				李林</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				游泳</td>
</tr>
<tr style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(204, 204, 204); background-color: white;">
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				1</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				保安</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				涂欣</td>
<td style="color: inherit; line-height: inherit; margin: 0px; font-size: 1em; border-style: solid; border-color: rgb(204, 204, 204); padding: 0.5em 1em;">
				看书</td>
</tr>
</tbody>
</table>
</section>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
现在我们想按第1列 type，把这份数据处理之后分别存储到不同的目录下，即 type 2（学生）的数据保存到目录&quot;2&quot;里，type 3（老师）的数据保存到目录&quot;3&quot;里，依此类推。<br />
一个最简单也最笨的方法是： 在Pig中把数据 SPLIT(拆分) 成多份，再分别 STORE(存储) 到指定的目录下：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="sql language-sql hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">A&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">LOAD</span>&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;1.txt&#39;</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">AS</span>&nbsp;(<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">type</span>:&nbsp;<span class="hljs-built_in" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">int</span>,&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">desc</span>:&nbsp;chararray,&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>:&nbsp;chararray,&nbsp;hobby:&nbsp;chararray);
SPLIT&nbsp;A&nbsp;INTO&nbsp;A1&nbsp;IF&nbsp;(type&nbsp;==&nbsp;1),&nbsp;A2&nbsp;IF&nbsp;(type&nbsp;==&nbsp;2),&nbsp;A3&nbsp;IF&nbsp;(type&nbsp;==&nbsp;3);

STORE&nbsp;A1&nbsp;INTO&nbsp;&#39;/my_output_dir/1&#39;;
STORE&nbsp;A2&nbsp;INTO&nbsp;&#39;/my_output_dir/2&#39;;
STORE&nbsp;A3&nbsp;INTO&nbsp;&#39;/my_output_dir/3&#39;;
</code></pre>
</section>
<p>
代码很直观，但当 type 有太多种数值的时候，比如说type有100种数值，难道你打算写100个 STORE 语句吗？会疯。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
更好的办法是利用piggybank里的一个UDF <a href="https://pig.apache.org/docs/latest/api/org/apache/pig/piggybank/storage/MultiStorage.html" rel="noopener" target="_blank">MultiStorage</a>来实现同样的功能：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="sql language-sql hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">A&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">LOAD</span>&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;1.txt&#39;</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">AS</span>&nbsp;(<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">type</span>:&nbsp;<span class="hljs-built_in" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">int</span>,&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">desc</span>:&nbsp;chararray,&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">name</span>:&nbsp;chararray,&nbsp;hobby:&nbsp;chararray);
STORE&nbsp;A&nbsp;INTO&nbsp;&#39;/my_output_dir&#39;&nbsp;USING&nbsp;org.apache.pig.piggybank.storage.MultiStorage(&#39;/my_output_dir&#39;,&nbsp;&#39;0&#39;,&nbsp;&#39;none&#39;,&nbsp;&#39;\t&#39;,&nbsp;&#39;true&#39;);
</code></pre>
</section>
<p>看，只要一行代码就代替了无数的 SPLIT INTO&nbsp;以及 STORE INTO&nbsp;语句，多么优雅。<br />
MultiStorage的参数含义分别是：</p>
<blockquote>
<p>
		public MultiStorage(String <span style="color:#0000ff;">parentPathStr</span>, String <span style="color:#0000ff;">splitFieldIndex</span>, String <span style="color:#0000ff;">compression</span>, String <span style="color:#0000ff;">fieldDel</span>, String <span style="color:#0000ff;">isRemoveKeys</span>)</p>
</blockquote>
<p>parentPathStr：输出文件的父目录。事实上这个参数不起作用，真正起作用的输出路径是在 &quot;INTO&quot;&nbsp;关键字后面的那个路径里指定的，但开发团队为了向前兼容，保留了这个参数，因此，把这个参数里的路径，设置成和 &quot;INTO&quot;&nbsp;后面的路径一样即可。<br />
splitFieldIndex：使用数据里的第几个字段来拆分数据存储到不同的子目录下（从0开始）。我这里设置成0，是表示我使用数据里的 type&nbsp;字段来拆分数据。<br />
compression：输出数据的压缩方式，可以是&nbsp;&#39;bz2&#39;，&#39;bz&#39;，&#39;gz&#39;，&#39;none&#39;这几种取值，其中 none&nbsp;表示无压缩。<br />
fieldDel：输出数据多个字段的分隔符。<br />
isRemoveKeys：输出数据是否移除掉用于拆分数据的字段。我这里设置成 true&nbsp;表示在输出数据中不会包含 type，因为我只想拿 type&nbsp;用作输出子目录名，不想让它出现在输出数据中。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
最后我们看一下执行结果。生成了3个目录，每个 type&nbsp;一个目录：</p>
<blockquote>
<p>
		/my_output_dir/1<br />
		/my_output_dir/2<br />
		/my_output_dir/3<br />
		/my_output_dir/_SUCCESS</p>
</blockquote>
<p>再来看一下子目录&quot;1&quot;里的文件：</p>
<blockquote>
<p>
		/my_output_dir/1/1-0,000</p>
</blockquote>
<p>其文件内容是：</p>
<blockquote>
<p>
		保安&nbsp; &nbsp; 许勤&nbsp; &nbsp; 下棋<br />
		保安&nbsp; &nbsp; 涂欣&nbsp; &nbsp; 看书</p>
</blockquote>
<p>这里面全是 type 1&nbsp;的数据。可见 MultiStorage 确实把数据按照 type&nbsp;拆分并存储在了不同的子目录下。</p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-apache-pig%e5%a6%82%e4%bd%95%e6%8c%89%e6%95%b0%e6%8d%ae%e5%88%86%e7%bb%84%e4%bf%9d%e5%ad%98%e5%88%b0%e4%b8%8d%e5%90%8c%e7%9a%84%e5%ad%90%e7%9b%ae%e5%bd%95%e4%b8%admultistorage/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 用Charles Proxy来抓包Chrome浏览器的数据</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8charles-proxy%e6%9d%a5%e6%8a%93%e5%8c%85chrome%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9a%84%e6%95%b0%e6%8d%ae/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8charles-proxy%e6%9d%a5%e6%8a%93%e5%8c%85chrome%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9a%84%e6%95%b0%e6%8d%ae/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Fri, 18 Feb 2022 09:17:18 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Charles Proxy]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[抓包]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13530</guid>

					<description><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="charles proxy" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_proxy.png" style="width: 571px; height: 221px;" /></div>
<p>查看Charles Proxy文章合集，请点击<a href="https://www.codelast.com/?p=13742" target="_blank" rel="noopener">这里</a>。<br />
本文适用的操作系统：Ubuntu</p>
<blockquote>
<p>
		Charles Proxy是一个HTTP代理/HTTP监视器/反向代理，它使开发人员能够查看其计算机和Internet之间的所有HTTP和SSL/HTTPS流量。这包括请求、响应和HTTP headers（其中包含cookie和缓存信息）。</p>
</blockquote>
<p>在Chrome浏览器中把代理服务器设置成<a href="https://www.charlesproxy.com/" rel="noopener" target="_blank">Charles Proxy</a>在本地提供的代理，可以让Charles Proxy把Chrome的网络流量抓取下来。<br />
配置方法如下。<br />
<span id="more-13530"></span><br />
<span style="color:#0000ff;">➤</span> Charles Proxy端的配置<br />
<span style="color:#ff0000;">✔</span> Proxy&#8594;Proxy Settings：<br />
<img decoding="async" alt="charles proxy settings" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_proxy_settings.png" style="width: 500px; height: 492px;" /><br />
Charles Proxy软件打开后，会启动一个代理服务器，在这里你可以修改代理服务器的端口等信息，通常来说保持默认参数即可。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">✔</span>&#160;Proxy&#8594;SSL Proxying Settings：<br />
<img decoding="async" alt="charles ssl proxying settings" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_ssl_proxying_settings.png" style="width: 450px; height: 411px;" /><br />
勾选上&#8220;Enable SSL Proxying&#8221;，这样可以对https的流量进行抓包。<br />
并且在&#8220;Location&#8221;里设置你感兴趣的域名，注意：只有这些域名的流量会被抓包。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">✔</span>&#160;导出Charles Proxy的证书<br />
在Charles界面上点击菜单导出 .pem 证书：</p>
<blockquote>
<p>
		Help&#8594;SSL Proxying&#8594;Save Charles Root Certificate</p>
</blockquote>
<p>把文件保存到 ~/charles.pem&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8charles-proxy%e6%9d%a5%e6%8a%93%e5%8c%85chrome%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9a%84%e6%95%b0%e6%8d%ae/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<div style="text-align: center;">
	<img decoding="async" alt="charles proxy" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_proxy.png" style="width: 571px; height: 221px;" /></div>
<p>查看Charles Proxy文章合集，请点击<a href="https://www.codelast.com/?p=13742" target="_blank" rel="noopener">这里</a>。<br />
本文适用的操作系统：Ubuntu</p>
<blockquote>
<p>
		Charles Proxy是一个HTTP代理/HTTP监视器/反向代理，它使开发人员能够查看其计算机和Internet之间的所有HTTP和SSL/HTTPS流量。这包括请求、响应和HTTP headers（其中包含cookie和缓存信息）。</p>
</blockquote>
<p>在Chrome浏览器中把代理服务器设置成<a href="https://www.charlesproxy.com/" rel="noopener" target="_blank">Charles Proxy</a>在本地提供的代理，可以让Charles Proxy把Chrome的网络流量抓取下来。<br />
配置方法如下。<br />
<span id="more-13530"></span><br />
<span style="color:#0000ff;">➤</span> Charles Proxy端的配置<br />
<span style="color:#ff0000;"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span> Proxy&rarr;Proxy Settings：<br />
<img decoding="async" alt="charles proxy settings" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_proxy_settings.png" style="width: 500px; height: 492px;" /><br />
Charles Proxy软件打开后，会启动一个代理服务器，在这里你可以修改代理服务器的端口等信息，通常来说保持默认参数即可。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;Proxy&rarr;SSL Proxying Settings：<br />
<img decoding="async" alt="charles ssl proxying settings" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_ssl_proxying_settings.png" style="width: 450px; height: 411px;" /><br />
勾选上&ldquo;Enable SSL Proxying&rdquo;，这样可以对https的流量进行抓包。<br />
并且在&ldquo;Location&rdquo;里设置你感兴趣的域名，注意：只有这些域名的流量会被抓包。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;导出Charles Proxy的证书<br />
在Charles界面上点击菜单导出 .pem 证书：</p>
<blockquote>
<p>
		Help&rarr;SSL Proxying&rarr;Save Charles Root Certificate</p>
</blockquote>
<p>把文件保存到 ~/charles.pem<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(0, 0, 255);">➤</span>&nbsp;Chrome浏览器端的配置（以Ubuntu系统上的Chrome为例）<br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;把证书导入Chrome<br />
依次打开Chrome的如下页面：<br />
&ldquo;<span style="color: rgb(0, 0, 255);">设置</span>&rdquo;&rarr;&ldquo;<span style="color: rgb(0, 0, 255);">安全和隐私设置</span>&rdquo;&rarr;&ldquo;<span style="color: rgb(0, 0, 255);">安全</span>&rdquo;&rarr;&ldquo;<span style="color: rgb(255, 0, 0);">管理证书</span>&rdquo;&rarr;&ldquo;<span style="color: rgb(255, 0, 0);">授权机构</span>&rdquo;：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/import_charles_proxy_ca_1.png" style="width: 668px; height: 182px;" /><br />
点击&ldquo;<span style="color:#0000ff;">导入</span>&rdquo;按钮，选择刚才生成的 .pem 证书文件，会弹出下面的对话框：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/import_charles_proxy_ca_2.png" style="width: 507px; height: 297px;" /><br />
勾选第一项。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;配置Chrome的代理<br />
使用Chrome的SwitchyOmega插件，添加一个名为&ldquo;Charles Proxy&rdquo;的情景模式：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/charles_proxy_config_in_SwitchyOmega.png" style="width: 600px; height: 266px;" /><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(0, 0, 255);">➤</span>&nbsp;测试<br />
在Chrome的SwitchyOmega插件中选择刚配置好的Charles Proxy情景模式，再访问一个前面设置好的感兴趣的域名下的网页。<br />
在导入证书之前，会发现抓不了：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/before_trust_charles_proxy_ca.png" style="width: 600px; height: 74px;" /><br />
&mdash;&mdash;界面上全是红叉，以及 Failed。</p>
<p>在导入了证书之后，再试一次，会发现抓包可以成功完成：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/after_trust_charles_proxy_ca.png" style="width: 821px; height: 117px;" /><br />
&mdash;&mdash;状态码是200，以及Status是Complete，这说明一切正常。</p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：<br />
<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8charles-proxy%e6%9d%a5%e6%8a%93%e5%8c%85chrome%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9a%84%e6%95%b0%e6%8d%ae/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 使用Selenium Wire访问网站时提示&quot;您与此网站之间建立的连接不安全&quot;的解决办法</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8selenium-wire%e8%ae%bf%e9%97%ae%e7%bd%91%e7%ab%99%e6%97%b6%e6%8f%90%e7%a4%ba%e6%82%a8%e4%b8%8e%e6%ad%a4%e7%bd%91%e7%ab%99%e4%b9%8b%e9%97%b4%e5%bb%ba%e7%ab%8b/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8selenium-wire%e8%ae%bf%e9%97%ae%e7%bd%91%e7%ab%99%e6%97%b6%e6%8f%90%e7%a4%ba%e6%82%a8%e4%b8%8e%e6%ad%a4%e7%bd%91%e7%ab%99%e4%b9%8b%e9%97%b4%e5%bb%ba%e7%ab%8b/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Tue, 15 Feb 2022 12:46:31 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Selenium Wire]]></category>
		<category><![CDATA[信任]]></category>
		<category><![CDATA[安全]]></category>
		<category><![CDATA[证书]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13517</guid>

					<description><![CDATA[<p>本文针对的操作系统：Ubuntu / MacOS</p>
<p>这个问题是由于<span style="background-color: rgb(255, 255, 255); font-family: &#34;JetBrains Mono&#34;, &#34;Droid Sans Mono&#34;, &#34;monospace&#34;, monospace; font-size: 16px; white-space: pre;">Selenium Wire</span>使用了自己的证书来访问网站，而它的证书默认不受Chrome信任。<br />
在Chrome里查看证书可以看到：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/selenium_wire_ca_info.png" style="width: 263px; height: 107px;" /></a><br />
<span id="more-13517"></span><br />
解决办法：<br />
➤ 导出<span style="font-family: &#34;JetBrains Mono&#34;, &#34;Droid Sans Mono&#34;, &#34;monospace&#34;, monospace; font-size: 16px; white-space: pre; background-color: rgb(255, 255, 255);">Selenium Wire的</span>证书文件<br />
在安装<span style="font-family: &#34;JetBrains Mono&#34;, &#34;Droid Sans Mono&#34;, &#34;monospace&#34;, monospace; font-size: 16px; white-space: pre; background-color: rgb(255, 255, 255);">Selenium Wire的Python环境里执行：</span></p>
<blockquote>
<p>
		python -m seleniumwire extractcert</p>
</blockquote>
<p>成功的话，会在当前目录下生成 ca.crt 证书文件。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
➤ 把证书导入Chrome<br />
✔ 对Ubuntu系统（其他Linux发行版应该类似，我没有用过），依次打开Chrome的如下页面（以下操作过程都在Chrome浏览器内部完成，不会跳转到操作系统的任何设置对话框里）：<br />
&#8220;<span style="color:#0000ff;">设置</span>&#8221;&#8594;&#8220;<span style="color:#0000ff;">安全和隐私设置</span>&#8221;&#8594;&#8220;<span style="color:#0000ff;">安全</span>&#8221;&#8594;&#8220;<span style="color:#ff0000;">管理证书</span>&#8221;&#8594;&#8220;<span style="color:#ff0000;">授权机构</span>&#8221;<br />
点击&#8220;导入&#8221;按钮，选择刚才生成的证书文件，会弹出下面的对话框：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/chrome_ca_auth_center.png" style="width: 518px; height: 311px;" /><br />
只勾选红框的那一项再点击&#8220;确定&#8221;即可。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8selenium-wire%e8%ae%bf%e9%97%ae%e7%bd%91%e7%ab%99%e6%97%b6%e6%8f%90%e7%a4%ba%e6%82%a8%e4%b8%8e%e6%ad%a4%e7%bd%91%e7%ab%99%e4%b9%8b%e9%97%b4%e5%bb%ba%e7%ab%8b/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>本文针对的操作系统：Ubuntu / MacOS</p>
<p>这个问题是由于<span style="background-color: rgb(255, 255, 255); font-family: &quot;JetBrains Mono&quot;, &quot;Droid Sans Mono&quot;, &quot;monospace&quot;, monospace; font-size: 16px; white-space: pre;">Selenium Wire</span>使用了自己的证书来访问网站，而它的证书默认不受Chrome信任。<br />
在Chrome里查看证书可以看到：<br />
<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/selenium_wire_ca_info.png" style="width: 263px; height: 107px;" /></a><br />
<span id="more-13517"></span><br />
解决办法：<br />
➤ 导出<span style="font-family: &quot;JetBrains Mono&quot;, &quot;Droid Sans Mono&quot;, &quot;monospace&quot;, monospace; font-size: 16px; white-space: pre; background-color: rgb(255, 255, 255);">Selenium Wire的</span>证书文件<br />
在安装<span style="font-family: &quot;JetBrains Mono&quot;, &quot;Droid Sans Mono&quot;, &quot;monospace&quot;, monospace; font-size: 16px; white-space: pre; background-color: rgb(255, 255, 255);">Selenium Wire的Python环境里执行：</span></p>
<blockquote>
<p>
		python -m seleniumwire extractcert</p>
</blockquote>
<p>成功的话，会在当前目录下生成 ca.crt 证书文件。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
➤ 把证书导入Chrome<br />
<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 对Ubuntu系统（其他Linux发行版应该类似，我没有用过），依次打开Chrome的如下页面（以下操作过程都在Chrome浏览器内部完成，不会跳转到操作系统的任何设置对话框里）：<br />
&ldquo;<span style="color:#0000ff;">设置</span>&rdquo;&rarr;&ldquo;<span style="color:#0000ff;">安全和隐私设置</span>&rdquo;&rarr;&ldquo;<span style="color:#0000ff;">安全</span>&rdquo;&rarr;&ldquo;<span style="color:#ff0000;">管理证书</span>&rdquo;&rarr;&ldquo;<span style="color:#ff0000;">授权机构</span>&rdquo;<br />
点击&ldquo;导入&rdquo;按钮，选择刚才生成的证书文件，会弹出下面的对话框：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/chrome_ca_auth_center.png" style="width: 518px; height: 311px;" /><br />
只勾选红框的那一项再点击&ldquo;确定&rdquo;即可。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" />&nbsp;对MacOS，当你按照上面的步骤点击了&ldquo;<span style="color: rgb(255, 0, 0);">管理证书</span>&rdquo;时，会发现Mac自动打开了系统的&ldquo;钥匙串访问&rdquo;设置对话框，也就是说你不能像在Ubuntu系统里一样只在Chrome里就能设置好。<br />
此时，按照如下步骤去设置：<br />
把前面生成的 ca.crt&nbsp;文件拖入&ldquo;钥匙串访问&rdquo;对话框，会要你输入密码把Selenium Wire的证书导入，之后就会看到导入的证书不被信任：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/mac_selenium_ca_untrusted_1.png" style="width: 600px; height: 344px;" /></p>
<p>双击它也会进一步看到不被信任：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/mac_selenium_ca_untrusted_2.png" style="width: 500px; height: 361px;" /></p>
<p>展开&ldquo;信任&rdquo;前的箭头，把&ldquo;使用此证书时&rdquo;改成&ldquo;始终信任&rdquo;：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/mac_selenium_ca_trusted_1.png" style="width: 400px; height: 448px;" /></p>
<p>关闭对话框，会要求你输入密码确认，之后就会看到证书已被信任：<br />
<img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2022/02/mac_selenium_ca_trusted_2.png" style="width: 600px; height: 376px;" /></p>
<p>现在再试试，<span style="font-family: &quot;JetBrains Mono&quot;, &quot;Droid Sans Mono&quot;, &quot;monospace&quot;, monospace; font-size: 16px; white-space: pre; background-color: rgb(255, 255, 255);">Selenium Wire不会再出现之前的不安全提示啦。</span><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：<br />
<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8selenium-wire%e8%ae%bf%e9%97%ae%e7%bd%91%e7%ab%99%e6%97%b6%e6%8f%90%e7%a4%ba%e6%82%a8%e4%b8%8e%e6%ad%a4%e7%bd%91%e7%ab%99%e4%b9%8b%e9%97%b4%e5%bb%ba%e7%ab%8b/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 扩展VirtualBox虚拟机的磁盘空间(vdi文件)</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%89%a9%e5%b1%95virtualbox%e8%99%9a%e6%8b%9f%e6%9c%ba%e7%9a%84%e7%a3%81%e7%9b%98%e7%a9%ba%e9%97%b4vdi%e6%96%87%e4%bb%b6/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%89%a9%e5%b1%95virtualbox%e8%99%9a%e6%8b%9f%e6%9c%ba%e7%9a%84%e7%a3%81%e7%9b%98%e7%a9%ba%e9%97%b4vdi%e6%96%87%e4%bb%b6/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 18 Oct 2021 18:14:03 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[GParted]]></category>
		<category><![CDATA[vdi]]></category>
		<category><![CDATA[VirtualBox]]></category>
		<category><![CDATA[扩展空间]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13346</guid>

					<description><![CDATA[<p>宿主机：Ubuntu 16.04 LTS<br />
虚拟机：Windows 10</p>
<p>VirtualBox虚拟机文件有很多种格式，我的是vdi格式，对应的磁盘空间是37GB（Win10系统里只有一个C盘），由于虚拟机里的空间不够用了，想把它扩展成45GB，并且在数据不丢失的情况下仍然保持&#8220;只有一个C盘&#8221;的状态。<br />
下面是操作方法。<br />
<span id="more-13346"></span><br />
<span style="color:#ff0000;">➤</span> 扩大vdi空间<br />
在宿主机的命令行执行命令：</p>
<blockquote>
<div>
		[codelast@ win10.new]$ <span style="color:#0000ff;">sudo VBoxManage modifyhd win10.vdi --resize 46080</span></div>
<div>
		0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%</div>
</blockquote>
<div>
	其中，46080 的单位是MB。这样，vdi 文件对应的虚拟机的磁盘空间就被扩展成了 45GB，但是从 37GB&#160;&#8594; 45GB，多出来的 8GB <span style="color:#ff0000;">仍然是不可用的</span>。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	我们可以进入虚拟机的系统验证这一点。在虚拟机里用快捷键 Win+R 打开运行命令对话框，输入&#160;<span style="color:#0000ff;">diskmgmt.msc</span> 并回车，会打开Windows的&#8220;磁盘管理&#8221;软件，在里面我们会看到：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_01.png" style="width: 750px; height: 569px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	可见那8GB是&#8220;未分配&#8221;状态，如果要把它合并到原先的37GB里，并且不破坏已安装好的Win10的话，需要用GParted软件来合并扩展空间（如果你不需要合并在一起，只需要把新增的8GB创建成另一个分区，那么就简单得多，不需要用本文的方法）。
<p>	首先到<a href="https://gparted.org/" rel="noopener" target="_blank"><span style="background-color:#faebd7;">GParted官网</span></a>下载GParted ISO镜像文件（gparted-xxx.iso）。</p></div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%89%a9%e5%b1%95virtualbox%e8%99%9a%e6%8b%9f%e6%9c%ba%e7%9a%84%e7%a3%81%e7%9b%98%e7%a9%ba%e9%97%b4vdi%e6%96%87%e4%bb%b6/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<p>宿主机：Ubuntu 16.04 LTS<br />
虚拟机：Windows 10</p>
<p>VirtualBox虚拟机文件有很多种格式，我的是vdi格式，对应的磁盘空间是37GB（Win10系统里只有一个C盘），由于虚拟机里的空间不够用了，想把它扩展成45GB，并且在数据不丢失的情况下仍然保持&ldquo;只有一个C盘&rdquo;的状态。<br />
下面是操作方法。<br />
<span id="more-13346"></span><br />
<span style="color:#ff0000;">➤</span> 扩大vdi空间<br />
在宿主机的命令行执行命令：</p>
<blockquote>
<div>
		[codelast@ win10.new]$ <span style="color:#0000ff;">sudo VBoxManage modifyhd win10.vdi --resize 46080</span></div>
<div>
		0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%</div>
</blockquote>
<div>
	其中，46080 的单位是MB。这样，vdi 文件对应的虚拟机的磁盘空间就被扩展成了 45GB，但是从 37GB&nbsp;&rarr; 45GB，多出来的 8GB <span style="color:#ff0000;">仍然是不可用的</span>。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	我们可以进入虚拟机的系统验证这一点。在虚拟机里用快捷键 Win+R 打开运行命令对话框，输入&nbsp;<span style="color:#0000ff;">diskmgmt.msc</span> 并回车，会打开Windows的&ldquo;磁盘管理&rdquo;软件，在里面我们会看到：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_01.png" style="width: 750px; height: 569px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	可见那8GB是&ldquo;未分配&rdquo;状态，如果要把它合并到原先的37GB里，并且不破坏已安装好的Win10的话，需要用GParted软件来合并扩展空间（如果你不需要合并在一起，只需要把新增的8GB创建成另一个分区，那么就简单得多，不需要用本文的方法）。</p>
<p>	首先到<a href="https://gparted.org/" rel="noopener" target="_blank"><span style="background-color:#faebd7;">GParted官网</span></a>下载GParted ISO镜像文件（gparted-xxx.iso）。<br />
	<span style="color:#ff0000;">➤</span> 把GParted ISO以光盘的形式挂载到虚拟机系统上<br />
	打开VirtualBox，在该虚拟机的&ldquo;存储&rdquo;设置页面上，你会看到一个 *.vdi&nbsp;的虚拟机文件，对应的就是虚拟机里看到的磁盘：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_02.png" style="width: 670px; height: 573px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	点击&ldquo;控制器: SATA&rdquo;右侧的光盘加号按钮，弹出下面的对话框：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_03.png" style="width: 640px; height: 388px;" /></a><br />
	点击左上方的&ldquo;注册&rdquo;按钮选择本地磁盘上的GParted ISO文件，会像上图一样显示在列表中。<br />
	继续点击&ldquo;选择&rdquo;按钮，会看到ISO已经成功挂载了：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_04.png" style="width: 670px; height: 573px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;重启虚拟机进入GParted软件<br />
	在虚拟机的&ldquo;系统&rdquo;设置页面上，把&ldquo;光驱&rdquo;调整成启动顺序的第一项：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_05.png" style="width: 670px; height: 573px;" /></a><br />
	这样开机才能先打开GParted，而不是进入安装过的那个Windows系统。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	设置好后重启虚拟机，可以成功进入GParted：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_06.jpg" style="width: 670px; height: 573px;" /></a><br />
	回车进入列表的第一项。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;使用GParted调整分区大小<br />
	打开GParted，在其界面上可看到 8GB&nbsp;的未分配空间：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_07.png" style="width: 770px; height: 517px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	选中 /dev/sda1&nbsp;那个需要扩大的分区，点击工具栏的&ldquo;Resize/Move&rdquo;按钮，会弹出一个对话框：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_08.png" style="width: 773px; height: 518px;" /></a><br />
	你不需要输入具体的数值，只需要用鼠标拖拽绿色方框的右边，把它拉到最右，就可以把空间扩到最大。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	点击&ldquo;Resize/Move&rdquo;按钮会看到空间已经被扩大了：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_09.png" style="width: 772px; height: 517px;" /></a><br />
	但是注意：现在只是临时状态，必须要点击工具栏上的&ldquo;应用&rdquo;按钮，才能真正让扩大分区的操作开始执行：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_10.png" style="width: 771px; height: 517px;" /></a><br />
	待操作完成后，Windows C盘就成功地从37GB变成了45GB，并且C盘上原来的数据不会丢失。</p>
<p>	<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;验证结果<br />
	在虚拟机设置中，把光驱从启动项中移除（防止再次进入GParted），再重启虚拟机，查看Windows系统的C盘大小，就会发现成功了：<br />
	<a href="https://www.codelast.com/" rel="noopener" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2021/10/enlarge_virtualbox_vdi_space_11.png" style="width: 264px; height: 74px;" /></a><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
<p>
	&nbsp;</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%89%a9%e5%b1%95virtualbox%e8%99%9a%e6%8b%9f%e6%9c%ba%e7%9a%84%e7%a3%81%e7%9b%98%e7%a9%ba%e9%97%b4vdi%e6%96%87%e4%bb%b6/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] ssh连接Linux服务器时提示&quot;Too many authentication failures&quot;的解决办法</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-ssh%e8%bf%9e%e6%8e%a5linux%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%97%b6%e6%8f%90%e7%a4%batoo-many-authentication-failures%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-ssh%e8%bf%9e%e6%8e%a5linux%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%97%b6%e6%8f%90%e7%a4%batoo-many-authentication-failures%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sun, 08 Aug 2021 19:01:27 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[Too many authentication failures]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13327</guid>

					<description><![CDATA[<div>
	如果你用&#160;<span style="color:#0000ff;">用户名+密码</span> 的方式第一次ssh连接一台Linux服务器，连不上并且报以下错误：</div>
<blockquote>
<div>
		Received disconnect from xxx.xxx.xxx.xxx port 22:2: Too many authentication failures</div>
<div>
		Disconnected from xxx.xxx.xxx.xxx port 22</div>
</blockquote>
<div>
	如果你确定不是因为你输入了太多次错误密码，那么产生这个问题的一个可能原因是：<br />
	在发起连接的机器（<span style="color:#ff0000;">记为A</span>）的 ~/.ssh&#160;目录下放了太多密钥文件，当你连接一台新的服务器并且没有在 ~/.ssh/config&#160;文件中做过特殊的配置时，默认会挨个尝试所有密钥文件，而这些密钥文件，都不是适配那台新服务器的，所以会连接失败。<br />
	<span id="more-13327"></span><br />
	解决这个问题的办法有两种：<br />
	（1）仍然要使用&#160;用户名+密码&#160;的方式登录目标服务器，加&#8220;<span style="color:#0000ff;">PubkeyAuthentication=no</span>&#8221;参数来指定不使用密钥文件
<blockquote>
<p>
			ssh -o PubkeyAuthentication=no root@192.168.15.16</p>
</blockquote>
<p>
	（2）配置使用密钥文件、无密码登录目标服务器<br />
	*&#160;使用另一台机器先登录上目标服务器，按<a href="https://www.codelast.com/?p=10117" rel="noopener" target="_blank"><span style="background-color:#faebd7;">这篇</span></a>文章的做法，把它配置成可以无密码登录服务器。<br />
	*&#160;在A机器上，编辑 ~/.ssh/config&#160;文件，添加如下配置：</p>
<blockquote>
<div>
			Hostname xxx.xxx.xxx.xxx</div>
<div>
			User your_user_name</div>
<div>
			Port 22</div>
<div>
			IdentitiesOnly=yes</div>
<div>
			IdentityFile ~/.ssh/id_rsa_xxx</div></blockquote></div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-ssh%e8%bf%9e%e6%8e%a5linux%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%97%b6%e6%8f%90%e7%a4%batoo-many-authentication-failures%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<div>
	如果你用&nbsp;<span style="color:#0000ff;">用户名+密码</span> 的方式第一次ssh连接一台Linux服务器，连不上并且报以下错误：</div>
<blockquote>
<div>
		Received disconnect from xxx.xxx.xxx.xxx port 22:2: Too many authentication failures</div>
<div>
		Disconnected from xxx.xxx.xxx.xxx port 22</div>
</blockquote>
<div>
	如果你确定不是因为你输入了太多次错误密码，那么产生这个问题的一个可能原因是：<br />
	在发起连接的机器（<span style="color:#ff0000;">记为A</span>）的 ~/.ssh&nbsp;目录下放了太多密钥文件，当你连接一台新的服务器并且没有在 ~/.ssh/config&nbsp;文件中做过特殊的配置时，默认会挨个尝试所有密钥文件，而这些密钥文件，都不是适配那台新服务器的，所以会连接失败。<br />
	<span id="more-13327"></span><br />
	解决这个问题的办法有两种：<br />
	（1）仍然要使用&nbsp;用户名+密码&nbsp;的方式登录目标服务器，加&ldquo;<span style="color:#0000ff;">PubkeyAuthentication=no</span>&rdquo;参数来指定不使用密钥文件</p>
<blockquote>
<p>
			ssh -o PubkeyAuthentication=no root@192.168.15.16</p>
</blockquote>
<p>
	（2）配置使用密钥文件、无密码登录目标服务器<br />
	*&nbsp;使用另一台机器先登录上目标服务器，按<a href="https://www.codelast.com/?p=10117" rel="noopener" target="_blank"><span style="background-color:#faebd7;">这篇</span></a>文章的做法，把它配置成可以无密码登录服务器。<br />
	*&nbsp;在A机器上，编辑 ~/.ssh/config&nbsp;文件，添加如下配置：</p>
<blockquote>
<div>
			Hostname xxx.xxx.xxx.xxx</div>
<div>
			User your_user_name</div>
<div>
			Port 22</div>
<div>
			IdentitiesOnly=yes</div>
<div>
			IdentityFile ~/.ssh/id_rsa_xxx</div>
</blockquote>
<div>
		其中，xxx.xxx.xxx.xxx&nbsp;是目标服务器的IP地址，your_user_name&nbsp;是登录目标服务器的用户名，id_rsa_xxx&nbsp;是用于无密码登录目标服务器的密钥文件。<br />
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
		配置好之后，再连接目标服务器就不再出错了。</p>
<p>		<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
		转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
		感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
			<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
</p></div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-ssh%e8%bf%9e%e6%8e%a5linux%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%97%b6%e6%8f%90%e7%a4%batoo-many-authentication-failures%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 在腾讯云的轻量应用服务器Lighthouse上用Squid开启HTTP代理服务</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e8%85%be%e8%ae%af%e4%ba%91%e7%9a%84%e8%bd%bb%e9%87%8f%e5%ba%94%e7%94%a8%e6%9c%8d%e5%8a%a1%e5%99%a8lighthouse%e4%b8%8a%e7%94%a8squid%e5%bc%80%e5%90%afhttp%e4%bb%a3/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e8%85%be%e8%ae%af%e4%ba%91%e7%9a%84%e8%bd%bb%e9%87%8f%e5%ba%94%e7%94%a8%e6%9c%8d%e5%8a%a1%e5%99%a8lighthouse%e4%b8%8a%e7%94%a8squid%e5%bc%80%e5%90%afhttp%e4%bb%a3/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 15 Mar 2021 18:58:01 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[综合]]></category>
		<category><![CDATA[HTTP代理]]></category>
		<category><![CDATA[Lighthouse]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[腾讯云]]></category>
		<category><![CDATA[轻量应用服务器]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13272</guid>

					<description><![CDATA[<p>前段时间我看到腾讯云的促销广告，其&#8220;<a href="https://cloud.tencent.com/product/lighthouse" rel="noopener" target="_blank">轻量应用服务器</a>&#8221;首年的费用才85元（配置：1核CPU，2GB内存，50GB磁盘，带宽4Mbps，流量包500GB/月），可谓相当便宜，于是入手一台，安装了Ubuntu系统，用于一些简单的测试场景。</p>
<blockquote>
<p>
		轻量应用服务器（Lighthouse）是新一代面向中小企业和开发者的云服务器产品，具备轻运维、开箱即用的特点，适用于小型网站、博客、论坛、电商以及云端开发测试和学习环境等轻量级业务场景，相比传统云服务器更加简单易用，并通过一站式融合常用基础云服务帮助用户便捷高效的构建应用，是您使用腾讯云的最佳入门途径。&#160;</p>
</blockquote>
<p><span id="more-13272"></span><br />
入手后的第一个用途是用Squid搭建一个HTTP代理服务。</p>
<blockquote>
<p>
		Squid是一个高性能的代理缓存服务器，Squid支持FTP、gopher、HTTPS和HTTP协议。</p>
</blockquote>
<p>Squid非常流行，并且可以配置成：使用代理的时候，要输入用户名、密码才能连接。有的后起之秀代理服务器软件功能没有这么强大，不能支持账号访问模式，所以就不用去折腾了。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color:#ff0000;">✔</span> 安装Squid</p>
<blockquote>
<p>
		sudo apt install squid</p>
</blockquote>
<p>
<span style="color: rgb(255, 0, 0);">✔</span>&#160;配置Squid：代理服务的端口</p>
<blockquote>
<p>
		sudo vim /etc/squid/squid.conf</p>
</blockquote>
<p>该配置文件的&#8220;http_port 3128&#8221;定义了默认的服务端口为3128，你可以改成你想要的端口。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">✔</span>&#160;创建密码<br />
为了通过用户名、密码来访问代理服务器，需要先安装软件包：</p>
<blockquote>
<p>
		sudo apt install apache2-utils</p>
</blockquote>
<p>这个软件包有创建密码所需的&#160;htpasswd&#160;软件。<br />
然后就可以创建密码文件了：</p>
<blockquote>
<p>
		sudo htpasswd -c -d /etc/squid/passwd &#60;username&#62;</p>
</blockquote>
<p>这里表示的是：生成一个密码文件&#160;/etc/squid/passwd，访问代理的用户名是 &#60;username&#62;，你自己看情况设置。<br />
注意：<br />
（1）为了避免麻烦，密码应设置成8位字符。据说不是8位的话会有warning，并且会有验证问题。<br />
（2）你会发现，/etc/squid/passwd 这个密码文件里的密码内容，并不是你前面输入的密码！在客户端使用Squid代理的时候，使用的是你输入的密码，而不是&#160;/etc/squid/passwd&#160;文件里的密码！<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e8%85%be%e8%ae%af%e4%ba%91%e7%9a%84%e8%bd%bb%e9%87%8f%e5%ba%94%e7%94%a8%e6%9c%8d%e5%8a%a1%e5%99%a8lighthouse%e4%b8%8a%e7%94%a8squid%e5%bc%80%e5%90%afhttp%e4%bb%a3/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>前段时间我看到腾讯云的促销广告，其&ldquo;<a href="https://cloud.tencent.com/product/lighthouse" rel="noopener" target="_blank">轻量应用服务器</a>&rdquo;首年的费用才85元（配置：1核CPU，2GB内存，50GB磁盘，带宽4Mbps，流量包500GB/月），可谓相当便宜，于是入手一台，安装了Ubuntu系统，用于一些简单的测试场景。</p>
<blockquote>
<p>
		轻量应用服务器（Lighthouse）是新一代面向中小企业和开发者的云服务器产品，具备轻运维、开箱即用的特点，适用于小型网站、博客、论坛、电商以及云端开发测试和学习环境等轻量级业务场景，相比传统云服务器更加简单易用，并通过一站式融合常用基础云服务帮助用户便捷高效的构建应用，是您使用腾讯云的最佳入门途径。&nbsp;</p>
</blockquote>
<p><span id="more-13272"></span><br />
入手后的第一个用途是用Squid搭建一个HTTP代理服务。</p>
<blockquote>
<p>
		Squid是一个高性能的代理缓存服务器，Squid支持FTP、gopher、HTTPS和HTTP协议。</p>
</blockquote>
<p>Squid非常流行，并且可以配置成：使用代理的时候，要输入用户名、密码才能连接。有的后起之秀代理服务器软件功能没有这么强大，不能支持账号访问模式，所以就不用去折腾了。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color:#ff0000;"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span> 安装Squid</p>
<blockquote>
<p>
		sudo apt install squid</p>
</blockquote>
<p>
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;配置Squid：代理服务的端口</p>
<blockquote>
<p>
		sudo vim /etc/squid/squid.conf</p>
</blockquote>
<p>该配置文件的&ldquo;http_port 3128&rdquo;定义了默认的服务端口为3128，你可以改成你想要的端口。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;创建密码<br />
为了通过用户名、密码来访问代理服务器，需要先安装软件包：</p>
<blockquote>
<p>
		sudo apt install apache2-utils</p>
</blockquote>
<p>这个软件包有创建密码所需的&nbsp;htpasswd&nbsp;软件。<br />
然后就可以创建密码文件了：</p>
<blockquote>
<p>
		sudo htpasswd -c -d /etc/squid/passwd &lt;username&gt;</p>
</blockquote>
<p>这里表示的是：生成一个密码文件&nbsp;/etc/squid/passwd，访问代理的用户名是 &lt;username&gt;，你自己看情况设置。<br />
注意：<br />
（1）为了避免麻烦，密码应设置成8位字符。据说不是8位的话会有warning，并且会有验证问题。<br />
（2）你会发现，/etc/squid/passwd 这个密码文件里的密码内容，并不是你前面输入的密码！在客户端使用Squid代理的时候，使用的是你输入的密码，而不是&nbsp;/etc/squid/passwd&nbsp;文件里的密码！<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;配置Squid：设置使用密码文件定义的账号</p>
<blockquote>
<p>
		sudo vim /etc/squid/squid.conf</p>
</blockquote>
<div>
	在 <span style="color:#0000ff;"># INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS</span>&nbsp;这句话下添加：</div>
<blockquote>
<div>
		auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd</div>
<div>
		acl auth_user proxy_auth REQUIRED</div>
<div>
		http_access allow auth_user</div>
</blockquote>
<div>
	并确保后面的两句是没有被注释掉的：</div>
<blockquote>
<div>
		http_access allow localhost<br />
		http_access deny all</div>
</blockquote>
<div>
	第一句是允许在云服务器本地访问代理服务，第二句是禁止其他一切流量对该代理服务器的访问，也就是说：只有使用前面在密码文件中定义的账号，才能访问该代理服务器。</div>
<div>
	<br />
	<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;启动代理服务</div>
<blockquote>
<div>
		service squid start</div>
</blockquote>
<div>
	<br />
	<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;查看Squid日志<br />
	首先在Squid配置文件中打开日志记录，取消注释下面这行：</div>
<blockquote>
<div>
		access_log daemon:/var/log/squid/access.log squid</div>
</blockquote>
<div>
	再重启Squid服务（service squid restart），然后即可查看：</div>
<blockquote>
<div>
		tail -f /var/log/squid/access.log</div>
</blockquote>
<div>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;命令行测试代理服务器是否work</p>
<blockquote>
<div>
			curl -x &quot;http://用户名:密码@IP:port&quot; https://www.baidu.com</div>
</blockquote>
<div>
		其中，<span style="color:#ff0000;">IP</span> 是Squid所在的服务器的IP，<span style="color:#ff0000;">port</span> 是前面设置的代理服务端口，<span style="color:#ff0000;">用户名</span> 是前面设置的代理账号的用户名，<span style="color:#ff0000;">密码</span> 则为代理账号的密码。<br />
		能打印出网页内容即说明代理可用。</p>
<p>		<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;开放代理服务的端口给外网<br />
		这是最重要的一步！如果你没有意识到这个问题，那会浪费你非常多时间调试。<br />
		经过上面的配置，你只能在服务器上用命令行来访问代理服务，在外网仍然是不通的。此时，需要在腾讯云轻量应用服务器的&ldquo;防火墙&rdquo;设置页面，添加一条自定义的规则，开放你的代理端口：<br />
		<img decoding="async" alt="tencent cloud firewall setting" src="https://www.codelast.com/wp-content/uploads/2021/03/tencent_cloud_firewall_setting.png" style="width: 600px; height: 297px;" /><br />
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
		<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;在其他机器上使用浏览器访问代理服务<br />
		假设你使用的是Chrome，那么访问代理可以用&nbsp;SwitchyOmega&nbsp;插件，新建一个情景模式，按下面的样子，把IP地址换成Squid服务所在的服务器IP，端口换成你设置的代理服务端口：<br />
		<img decoding="async" alt="switchy omega setting" src="https://www.codelast.com/wp-content/uploads/2021/03/tencent_cloud_proxy_switchy_omega_setting.png" style="width: 600px; height: 201px;" /><br />
		在使用这个情景模式的情况下，第一次用浏览器访问任何网页会弹出账号输入框，如果输对了就能通过代理来访问网络啦（可以看Squid的日志验证这一点）。<br />
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
		<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
		转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
		感谢关注我的微信公众号（微信扫一扫）：<br />
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
		以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
			<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
</p></div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e8%85%be%e8%ae%af%e4%ba%91%e7%9a%84%e8%bd%bb%e9%87%8f%e5%ba%94%e7%94%a8%e6%9c%8d%e5%8a%a1%e5%99%a8lighthouse%e4%b8%8a%e7%94%a8squid%e5%bc%80%e5%90%afhttp%e4%bb%a3/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 使用Apache DataFu中的Coalesce()简化Apache Pig的三元运算符</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8apache-datafu%e4%b8%ad%e7%9a%84coalesce%e7%ae%80%e5%8c%96apache-pig%e7%9a%84%e4%b8%89%e5%85%83%e8%bf%90%e7%ae%97%e7%ac%a6/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8apache-datafu%e4%b8%ad%e7%9a%84coalesce%e7%ae%80%e5%8c%96apache-pig%e7%9a%84%e4%b8%89%e5%85%83%e8%bf%90%e7%ae%97%e7%ac%a6/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Fri, 04 Dec 2020 03:15:31 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[综合]]></category>
		<category><![CDATA[Apache DataFu]]></category>
		<category><![CDATA[apache pig]]></category>
		<category><![CDATA[Coalesce]]></category>
		<category><![CDATA[UDF]]></category>
		<category><![CDATA[三元运算符]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13139</guid>

					<description><![CDATA[<p>查看更多Apache Pig的教程请点击<a href="https://www.codelast.com/?p=4550" rel="noopener" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>来看这个例子。有数据文件 1.txt，内容为：</p>
<blockquote>
<div>
		a<span style="color:#ff0000;">[\t]</span><span style="color: rgb(255, 0, 0);">[\t]</span>c</div>
<div>
		<span style="color: rgb(255, 0, 0);">[\t]</span>f<span style="color: rgb(255, 0, 0);">[\t]</span>g</div>
<div>
		h<span style="color: rgb(255, 0, 0);">[\t]</span>k<span style="color: rgb(255, 0, 0);">[\t]</span><br />
		<span style="color: rgb(255, 0, 0);">[\t]</span><span style="color: rgb(255, 0, 0);">[\t]</span><span style="color: rgb(255, 0, 0);">[\t]</span></div>
</blockquote>
<div>
	其中 <span style="color:#ff0000;">[\t]</span>&#160;表示制表符(tab)，并不是真的在文件中写了&#160;<span style="color: rgb(255, 0, 0);">[\t]</span>。<br />
	在Pig命令行交互模式下加载这个文件，并把其中为空（NULL）的列替换成一些数字：
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="sql language-sql hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">A&#160;=&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">LOAD</span>&#160;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;1.txt&#39;</span>&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">AS</span>&#160;(col1:&#160;chararray,&#160;col2:&#160;chararray,&#160;col3:&#160;chararray);
B&#160;=&#160;FOREACH&#160;A&#160;GENERATE&#160;(col1&#160;IS&#160;NOT&#160;NULL&#160;?&#160;col1&#160;:&#160;&#39;1&#39;)&#160;AS&#160;col1,&#160;(col2&#160;IS&#160;NOT&#160;NULL&#160;?&#160;col2&#160;:&#160;&#39;2&#39;)&#160;AS&#160;col2,&#160;(col3&#160;IS&#160;NOT&#160;NULL&#160;?&#160;col3&#160;:&#160;&#39;3&#39;)&#160;AS&#160;col3;
DUMP&#160;B;
</code></pre>
</section>
<p>输出：</p>
<blockquote>
<div>
			(a,2,c)</div>
<div>
			(1,f,g)</div>
<div>
			(h,k,3)</div>
<div>
			(1,2,3)</div>
</blockquote>
<p>	代码非常简单：如果第一列col1为空则替换为1，如果第二列为空则替换为2，如果第三列为空则替换为3。<br />
	这里使用了三元运算符 <span style="color:#0000ff;">?</span></p></div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8apache-datafu%e4%b8%ad%e7%9a%84coalesce%e7%ae%80%e5%8c%96apache-pig%e7%9a%84%e4%b8%89%e5%85%83%e8%bf%90%e7%ae%97%e7%ac%a6/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<p>查看更多Apache Pig的教程请点击<a href="https://www.codelast.com/?p=4550" rel="noopener" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>来看这个例子。有数据文件 1.txt，内容为：</p>
<blockquote>
<div>
		a<span style="color:#ff0000;">[\t]</span><span style="color: rgb(255, 0, 0);">[\t]</span>c</div>
<div>
		<span style="color: rgb(255, 0, 0);">[\t]</span>f<span style="color: rgb(255, 0, 0);">[\t]</span>g</div>
<div>
		h<span style="color: rgb(255, 0, 0);">[\t]</span>k<span style="color: rgb(255, 0, 0);">[\t]</span><br />
		<span style="color: rgb(255, 0, 0);">[\t]</span><span style="color: rgb(255, 0, 0);">[\t]</span><span style="color: rgb(255, 0, 0);">[\t]</span></div>
</blockquote>
<div>
	其中 <span style="color:#ff0000;">[\t]</span>&nbsp;表示制表符(tab)，并不是真的在文件中写了&nbsp;<span style="color: rgb(255, 0, 0);">[\t]</span>。<br />
	在Pig命令行交互模式下加载这个文件，并把其中为空（NULL）的列替换成一些数字：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="sql language-sql hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">A&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">LOAD</span>&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;1.txt&#39;</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">AS</span>&nbsp;(col1:&nbsp;chararray,&nbsp;col2:&nbsp;chararray,&nbsp;col3:&nbsp;chararray);
B&nbsp;=&nbsp;FOREACH&nbsp;A&nbsp;GENERATE&nbsp;(col1&nbsp;IS&nbsp;NOT&nbsp;NULL&nbsp;?&nbsp;col1&nbsp;:&nbsp;&#39;1&#39;)&nbsp;AS&nbsp;col1,&nbsp;(col2&nbsp;IS&nbsp;NOT&nbsp;NULL&nbsp;?&nbsp;col2&nbsp;:&nbsp;&#39;2&#39;)&nbsp;AS&nbsp;col2,&nbsp;(col3&nbsp;IS&nbsp;NOT&nbsp;NULL&nbsp;?&nbsp;col3&nbsp;:&nbsp;&#39;3&#39;)&nbsp;AS&nbsp;col3;
DUMP&nbsp;B;
</code></pre>
</section>
<p>输出：</p>
<blockquote>
<div>
			(a,2,c)</div>
<div>
			(1,f,g)</div>
<div>
			(h,k,3)</div>
<div>
			(1,2,3)</div>
</blockquote>
<p>	代码非常简单：如果第一列col1为空则替换为1，如果第二列为空则替换为2，如果第三列为空则替换为3。<br />
	这里使用了三元运算符 <span style="color:#0000ff;">? :</span> 来做这个判断，写法非常丑陋。<br />
	<span id="more-13139"></span><br />
	如果要实现更麻烦的逻辑，&ldquo;取第一列、第二列、第三列中，第1个不为空的列作为结果，如果全为空则取888&rdquo;：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="sql language-sql hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">A&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">LOAD</span>&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;1.txt&#39;</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">AS</span>&nbsp;(col1:&nbsp;chararray,&nbsp;col2:&nbsp;chararray,&nbsp;col3:&nbsp;chararray);
B&nbsp;=&nbsp;FOREACH&nbsp;A&nbsp;GENERATE&nbsp;(col1&nbsp;IS&nbsp;NOT&nbsp;NULL&nbsp;?&nbsp;col1&nbsp;:&nbsp;(col2&nbsp;IS&nbsp;NOT&nbsp;NULL&nbsp;?&nbsp;col2&nbsp;:&nbsp;(col3&nbsp;IS&nbsp;NOT&nbsp;NULL&nbsp;?&nbsp;col3&nbsp;:&nbsp;&#39;888&#39;)))&nbsp;AS&nbsp;col;
DUMP&nbsp;B;
</code></pre>
</section>
<p>输出：</p>
<blockquote>
<div>
			(a)</div>
<div>
			(f)</div>
<div>
			(h)</div>
<div>
			(888)</div>
</blockquote>
<p>	这代码是真&bull;丑出天际。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	这时，我们就可以使用<a href="https://datafu.apache.org/" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">Apache DataFu</span></a>中的&nbsp;<a href="https://github.com/apache/datafu/blob/master/datafu-pig/src/main/java/datafu/pig/util/Coalesce.java" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">Coalesce()</span></a>&nbsp;函数来简化代码。</div>
<blockquote>
<div>
		Apache DataFu&trade;是用于在Hadoop中处理大规模数据的库的集合。</div>
</blockquote>
<div>
	Coalesce()的功能：</div>
<blockquote>
<div>
		返回一个元组(tuple)的第一个非空值，就像SQL中的Coalesce一样。</div>
</blockquote>
<div>
	简化上面的第一段代码：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="sql language-sql hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">DEFINE&nbsp;Coalesce&nbsp;datafu.pig.util.Coalesce();

A&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">LOAD</span>&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;1.txt&#39;</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">AS</span>&nbsp;(col1:&nbsp;chararray,&nbsp;col2:&nbsp;chararray,&nbsp;col3:&nbsp;chararray);
B&nbsp;=&nbsp;FOREACH&nbsp;A&nbsp;GENERATE&nbsp;Coalesce(col1,&nbsp;&#39;1&#39;)&nbsp;AS&nbsp;col1,&nbsp;Coalesce(col2,&nbsp;&#39;2&#39;)&nbsp;AS&nbsp;col2,&nbsp;Coalesce(col3,&nbsp;&#39;3&#39;)&nbsp;AS&nbsp;col3;
DUMP&nbsp;B;
</code></pre>
</section>
<p>输出结果完全一样。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	简化上面的第二段代码：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="sql language-sql hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">DEFINE&nbsp;Coalesce&nbsp;datafu.pig.util.Coalesce();

A&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">LOAD</span>&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#39;1.txt&#39;</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">AS</span>&nbsp;(col1:&nbsp;chararray,&nbsp;col2:&nbsp;chararray,&nbsp;col3:&nbsp;chararray);
B&nbsp;=&nbsp;FOREACH&nbsp;A&nbsp;GENERATE&nbsp;Coalesce(col1,&nbsp;col2,&nbsp;col3,&nbsp;&#39;888&#39;)&nbsp;AS&nbsp;col;
DUMP&nbsp;B;
</code></pre>
</section>
<p>三元运算符嵌套的层数越多，使用Coalesce能简化得就越多。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
</div>
<div>
	&nbsp;</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e4%bd%bf%e7%94%a8apache-datafu%e4%b8%ad%e7%9a%84coalesce%e7%ae%80%e5%8c%96apache-pig%e7%9a%84%e4%b8%89%e5%85%83%e8%bf%90%e7%ae%97%e7%ac%a6/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
