學習日志---7

1.復習Linux hadoop hdfs MapReduce基礎知識

?

1,列舉linux常用命令
shutdown now
reboot
mkdir
mkdir -p
touch filename
rm -r filename
rm -rf filename
vi filename
i--->可編輯狀態
esc --> : --->wq 保存退出
q!
wq!
cat
grep
find
ifconfig
ping
useradd
chmod 777 filename
more
cp srcfile destfile
mv
tar -zxvf filename -C destpath
ls
ls -a
pwd 查看當前目錄的絕對路徑
filewall:
service iptables start/stop/status/restart
centos7 : systemctl stop frewalld.service
systemctl -cmd --state
修改網絡配置文件:
/etc/sysconfig/network-scripts/ifcfg-eth1
配置環境變量
/etc/profile
~/.bash_profile
/etc/profild.d/x.sh
JAVA
export JAVA_HOME=/root/app/jdk1.8.0_161
export PATH=$JAVA_HOME/bin:$PATH
配置文件生效:
source ~/.bash_priofile
查看java安裝目錄
echo $JAVA_HOME
2,hash函數特點是什么
代碼論道
字符串----->固定位數的Hash值。
1,確定性
str1--->hash1值
str2---->hash1值
2,單向性
str----hash()----->hash值
3,防篡改
str1--->bit--->hash()--->hash值
4,防碰撞
str1 ---> hash1
str2---->hash1
mapreduce分區默認實現:
hash(key)%reduce task
Hash實現:
SHA
MD5
區塊鏈:不可篡改
鏈表+hash(key)
3,hdfs如何實現文件的存儲
NameNode:
處理客戶端的請求
操作元數據(修改文件名\打開文件、關閉文件、DataNode
info)
DataNode
存儲文件數據block,blocksize=128MB
發送心跳信息,將自身所有存儲的block信息,健康狀況發
送給 NameNode。
SecondNameNode:hadoop2.x可有可無
130MB--> 128MB block + 2MB block
4,hdfs副本存放機制?
block 默認3份。
5,hdfs主要進程、yarn的主要進程分別是?
NameNode
DataNode
SecondNameNode
yarn:資源調度框架
ResourceManager
NodeManager
6,簡述mapreduce計算流程
7,搭建偽分布式步驟
cents6.5
1,前置準備
java
tar -zxvf
配置環境變量
ssh
1,安裝ssh服務器
openserver-ssh
2, ssh-keygen -t rsa
cd ~/.ssh
id_rsa id_rsa.pub
cp id_rsa.pub authorized_keys
3,ssh-copy-id
2,安裝hadoop
2.1解壓hadoop tar -zxvf hadoop-xx.tar.gz
2.2 配置文件
$HADOOP_HOME/etc/hadoop
hadoop-env.sh
JAVA_HOME
core-site.xml
<property>
<name>fs.defaultFS</name>
<value>hdfs://Master:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/root/hadoop/app/tmp</value>
</property>
hdfs-site.xml
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
HDFS Shell操作:
1,查看Hdfs上的文件
hdfs dfs -ls /
hadoop fs -ls /
2,將本地文件上傳到hdfs
hdfs dfs -put hello.txt /
3,查看hdfs文件內容
hdfs dfs -cat /hello.txt
hdfs dfs -text /hello.txt
4,在hdfs創建目錄
hdfs dfs -mkdir /hello
5,hdfs遞歸創建目錄
hdfs dfs -mkdir -p /test/a/b
6,遞歸查詢目錄
hdfs dfs -ls -p /test
7,將hdfs上的文件下載到本地
hdfs dfs -get /hello.txt
8,將本地文件拷貝到hdfs上 /test/a/b
hdfs dfs -copyFromLocal hello.txt /test/a/b/h.txt
9,刪除hdfs上目錄
hdfs dfs -rm -R /hello
10,刪除hdfs上的文件
hdfs dfs -rm /hello.txt

?

2.java操作HDFS文件

  1 import java.io.BufferedReader;
  2 import java.io.IOException;
  3 import java.io.InputStreamReader;
  4 
  5 import org.apache.hadoop.conf.Configuration;
  6 import org.apache.hadoop.fs.FSDataInputStream;
  7 import org.apache.hadoop.fs.FSDataOutputStream;
  8 import org.apache.hadoop.fs.FileSystem;
  9 import org.apache.hadoop.fs.Path;
 10 
 11 public class HDFSTest {
 12 
 13     public static void main(String[] args) {
 14         // TODO 自動生成的方法存根
 15         System.setProperty("hadoop.home.dir", "E:\\hadoop");
 16         
 17         String str="";
 18         //createDir("/new/abc.txt");
 19         //delete("/new");
 20         //createFile("/new/abc.txt");
 21         //write(str);
 22         append(str);
 23         read();
 24 
 25     }
 26     
 27     //向文件中寫入
 28     public static void write(String str){
 29         if(str==null||str.equals("")){
 30             str="Hello World!\n";
 31         }
 32         Configuration conf=new Configuration();
 33         conf.set("fs.default.name", "hdfs://192.168.137.11:9000");
 34         try {
 35             FileSystem fs=FileSystem.get(conf);
 36             FSDataOutputStream outpustream = fs.create(new Path("/hadoop/a.txt"));
 37             outpustream.writeBytes(str);
 38             outpustream.close();
 39         } catch (IOException e) {
 40             // TODO Auto-generated catch block
 41             System.out.println(e.getMessage());
 42         }
 43     }
 44     //向文件中添加
 45     public static void append(String str){
 46         if(str==null||str.equals("")){
 47             str="Hello World!\n";
 48         }
 49         Configuration conf=new Configuration();
 50         conf.set("fs.default.name", "hdfs://192.168.137.11:9000");
 51         conf.set("dfs.support.append", "true");
 52         conf.set("dfs.client.block.write.replace-datanode-on-failure.policy", "NEVER");
 53         conf.set("dfs.client.block.write.replace-datanode-on-failure.enable", "true");
 54         try {
 55             FileSystem fs=FileSystem.get(conf);
 56             FSDataOutputStream outpustream = fs.append(new Path("/hadoop/a.txt"));
 57             outpustream.writeBytes(str);
 58             outpustream.close();
 59         } catch (IOException e) {
 60             // TODO Auto-generated catch block
 61             System.out.println(e.getMessage());
 62         }
 63     }
 64     //讀取文件,并打印在控制臺
 65     public static void read(){
 66         Configuration conf=new Configuration();
 67         conf.set("fs.default.name", "hdfs://192.168.137.11:9000");
 68         try {
 69             FileSystem fs=FileSystem.get(conf);
 70             //創建輸入流
 71             FSDataInputStream inputstream = fs.open(new Path("/hadoop/a.txt"));
 72             InputStreamReader isr=new InputStreamReader(inputstream);
 73             BufferedReader br=new BufferedReader(isr);
 74             String str=br.readLine();
 75             
 76             while(str!=null){
 77                 System.out.println(str);
 78                 str=br.readLine();
 79             }
 80             br.close();
 81             isr.close();
 82             inputstream.close();
 83             
 84         } catch (IOException e) {
 85             // TODO 自動生成的 catch 塊
 86             e.printStackTrace();
 87         }
 88         
 89     }
 90     //創建目錄
 91     public static void createDir(String path) {
 92         Configuration configuration=new Configuration();
 93         configuration.set("fs.default.name", "hdfs://192.168.137.11:9000");
 94         try {
 95             FileSystem fs=FileSystem.newInstance(configuration);
 96             fs.mkdirs(new Path(path));
 97         } catch (IOException e) {
 98             // TODO 自動生成的 catch 塊
 99             e.printStackTrace();
100         }
101         
102     }
103     //刪除文件
104     public static void delete(String path) {
105         Configuration configuration=new Configuration();
106         configuration.set("fs.default.name", "hdfs://192.168.137.11:9000");
107         try {
108             FileSystem fs=FileSystem.newInstance(configuration);
109             fs.delete(new Path(path),true);
110         } catch (IOException e) {
111             // TODO 自動生成的 catch 塊
112             e.printStackTrace();
113         }
114     }
115     
116     //創建文件
117     public static void createFile(String path) {
118         Configuration configuration=new Configuration();
119         configuration.set("fs.default.name", "hdfs://192.168.137.11:9000");
120         try {
121             FileSystem fileSystem=FileSystem.newInstance(configuration);
122             fileSystem.createNewFile(new Path(path));
123         } catch (IOException e) {
124             // TODO 自動生成的 catch 塊
125             e.printStackTrace();
126         }
127         
128     }
129 }

?

轉載于:https://www.cnblogs.com/yifengyifeng/p/9319099.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/251241.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/251241.shtml
英文地址,請注明出處:http://en.pswp.cn/news/251241.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

javascript --- 屬性描述符

從ES5開始,所有的屬性都具備了屬性描述符 var myObject {a: 2 };Object.getOwnPropertyDescriptor(myObject, "a"); //{ // value:2, // writable: true, // 可寫 // enumerable: true, // 可枚舉 // configurble: true // 可配置 //}定義屬性…

看了嗎網址鏈接

sklearn實戰-乳腺癌細胞數據挖掘&#xff08;博主親自錄制視頻&#xff09; https://study.163.com/course/introduction.htm?courseId1005269003&utm_campaigncommission&utm_sourcecp-400000000398149&utm_mediumshare # -*- coding: utf-8 -*- ""&qu…

JMeter 性能測試進階實戰

課程簡介 本課程制作的主要目的是為了讓大家快速上手 JMeter&#xff0c;期間穿插了大量主流項目中用到的技術&#xff0c;以及結合當今主流微服務技術提供了測試 Dubbo 接口、Java 工程技術具體實施方案&#xff0c;注重實踐、注意引導測試思維、拒絕枯燥的知識點羅列、善于用…

javascript --- 混入

顯示混入: function mixin(sourceObj, targetObj){for(var key in sourceObj){ // 遍歷source中的所有屬性if(!(key in targetObj)) { // 找到targetz中沒有的屬性targetObj[key] sourceObj[key];}}return targetObj; }var Vehicle {engines: 1,iginition: function() {c…

php源碼代目錄

ext :存放動態和內建模塊的目錄&#xff0c;在這里可以找到所有的php官方虧站,并且也可以在這里編寫擴展&#xff1b; main:包含php的主要宏定義; pear: PHP擴展與應用庫; sapi:包含不同服務器抽象層的代碼; TSRM&#xff1a;Zend和PHP的"線程安全資源管理器"目錄; Z…

bzoj1231 [Usaco2008 Nov]mixup2 混亂的奶牛——狀壓DP

題目&#xff1a;https://www.lydsy.com/JudgeOnline/problem.php?id1231 小型狀壓DP&#xff1b; f[i][j] 表示狀態為 j &#xff0c;最后一個奶牛是 i 的方案數&#xff1b; 所以下一個只能是和它相差大于 k 而且不在狀態中的奶牛。 代碼如下&#xff1a; #include<iostr…

JavaScript高級程序設計閱讀筆記

2020-11-15 通過初始化指定變量類型 數字-1 對象null和null的比較&#xff08;不理解&#xff09;使用局部變量將屬性查找替換為值查找&#xff08;算法復雜度&#xff09;循環的減值迭代&#xff0c;降低了計算終止條件的復雜度switch快多個變量聲明逗號隔開使用數組和對象字面…

jquery --- 監聽input框失效

使用juery監聽Input輸入的變化,并且封裝起來,如下: // html <input type"text" id‘myinput1’ /> // js function formOnById(id){let dom # id;$(dom).bind(input propertychange,()>{let item $(dom).val;console.log(item);} } formOnById(myinp…

windows任務計劃程序 坑

轉載于:https://www.cnblogs.com/kaibindirver/p/8109041.html

第三篇:函數之嵌套

1 #函數的嵌套調用&#xff1a;在調用一個函數的時&#xff0c;其內部的代碼又調用其他的函數2 # def bar():3 # print(from bar)4 #5 # def foo():6 # print(from foo)7 # bar()8 #9 # foo() 10 11 12 # def max2(x,y): 13 # if x > y: 14 # ret…

vue路由權限(結合服務端koa2)

gitee地址 一、項目初始化 vue create manager-admin // 創建vue項目// 管理員權限安裝 cnpm i -S koa2 // 下載koa2依賴 cnpm install --global koa-generator // 下載框架 koa-generator koa2 manager-server // 創建項目 cd manager-server // 進入項目 npm install // 安…

javascript --- 類、class、事件委托的編程風格

類風格: // 父類 function Widget(width, height) {this.width width || 50;this.height height || 50;this.$elem null; } Widget.prototype.render function($where) {if(this.$elem) {this.$elem.css({width: this.width "px",height: this.height "p…

在線獲取UUID

http://fir.im/udid轉載于:https://www.cnblogs.com/mtjbz/p/8116576.html

堆和堆排序

堆和優先隊列 普通隊列&#xff1a;FIFO&#xff0c;LILO 優先隊列&#xff1a;出隊順序和入隊順序無關&#xff0c;和優先級相關。一個典型應用就是操作系統中。動態選擇優先級高的任務執行 堆的實現 最典型的堆就是二叉堆&#xff0c;就像是一顆二叉樹。這個堆的特點&#xf…

ES5-1 發展史、ECMA、編程語言、變量、JS值

1. 5大主流瀏覽器及內核&#xff08;自主研發&#xff09; 瀏覽器內核IEtridentChromewebkit blinkSafariwebkitFirefoxgeckoOperapresto 2. 瀏覽器的歷史 和 JS誕生 1989-1991 WorldWideWeb&#xff08;后來為了避免與萬維網混淆而改名為Nexus&#xff09;是世界上第一個網頁…

javascript --- 使用對象關聯簡化整體設計

在某個場景中,我們有兩個控制器對象: 1.用來操作網頁中的登錄表單; 2.用來與服務器進行通信. 類設計模式 // 把基礎的函數定義在名為Controller的類中,然后派生兩個子類LoginController和AuthController. // 父類 function Controller() {this.errors []; } Controller.prot…

javascript --- polyfill中幾個常用方法

ES6中,新增了許多有用的方法,下面分享幾個ES6之前得版本寫的polyfill Number.EPSILON: // 機器精度,并判斷2個數是否相等 if(!Number.EPSILON){Number.EPSILON math.pow(2, -52); }function numberCloseEnoughToEqual(n1, n2) {return Math.abs(n1 - n2 ) < Number.EPSIL…

[Usaco2010 Nov]Visiting Cows

題目描述 經過了幾周的辛苦工作,貝茜終于迎來了一個假期.作為奶牛群中最會社交的牛,她希望去拜訪N(1<N<50000)個朋友.這些朋友被標號為1..N.這些奶牛有一個不同尋常的交通系統,里面有N-1條路,每條路連接了一對編號為C1和C2的奶牛(1 < C1 < N; 1 < C2 < N; C1…

ES5-2 語法、規范、錯誤、運算符、判斷分支、注釋

1. 錯誤 MDN錯誤列表 Uncaught SyntaxError: Unexpected token ) // 語法錯誤 Uncaught ReferenceError: a is not defined // 引用錯誤等類型 Uncaught TypeError: Cannot read property toString of null出現一個語法錯誤&#xff0c;則一行代碼都不會執行&#xff08;檢查…

新單詞 part 4

part 41.veto 英[?vi:t??]美[?vi:to?]n. 行使否決權; 否決權&#xff0c;否認權; 否決理由;vt. 否決&#xff0c;不同意; 不批準&#xff0c;禁止;vi. 否決; 禁止;2.acoustics 英[??ku:st?ks]美[??kust?ks]n. 聲學; &#xff08;傳聲系統的&#xff09; 音響效果; 聲…