shaung
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    2
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: Apache Hadoop 實作紀錄 tags: Apache, Hadoop description: Apache Hadoop 實作紀錄 --- # Apache hadoop 實作紀錄 hadoop 是一個 base on 分散式系統的大型資料儲存系統,由一到多個 cluster 所組成,由一到多台的 server 所組成,而資料在 cluster 中採取 HDFS 分散式檔案系統 (Hadoop Distributed File System),在資料處理使用 MapReduce 平行運算架構加速處理巨量數據的速度。 ## 使用 docker 環境來架設 hadoop 這裡使用 ubuntu18.04 的 docker 環境來 demo ,此須準備一台 master 主機(主機叫作master)和三台 slave 主機(分別叫作 slave01、slave02、slave03) ![](https://i.imgur.com/bFKzJf3.png) 先建立 docker 內 bridge 網段 ``` $ docker network create hadoop ``` 啟動並進入 ubuntu18.04 container ``` $ docker run -it --net hadoop --name master ubuntu:18.04 bash ``` **master 和 slave 機器裡須做以下** 下載 java8 ``` $ apt-get update $ sudo apt-get install openjdk-8-jdk $ java -version ``` 下載 openssh-server,並且下載 docker sudo 權限 ``` $ apt-get install openssh-server $ service ssh start $ apt-get -y install sudo ``` 新增使用者,後續操作都會在使用者端進行 ``` $ useradd -m hadoop -s /bin/bash $ passwd hadoop $ adduser hadoop sudo $ su hadoop ``` 下載 hadoop,解壓縮到 /usr/local/,並設定權限 ``` $ cd ~ $ sudo apt install wget $ sudo wget https://dlcdn.apache.org/hadoop/common/hadoop-2.10.1/hadoop-2.10.1.tar.gz $ sudo tar -zxvf ./hadoop-2.10.1.tar.gz -C /usr/local $ cd /usr/local/ $ sudo mv ./hadoop-2.10.1/ ./hadoop $ sudo chown -R hadoop:hadoop ./hadoop ``` 修改 bashrc 文件 ``` $ sudo nano ~/.bashrc ``` 在最上面加入 ``` # set JAVA_HOME export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 ``` 儲存後應用 bashrc ``` $ source ~/.bashrc ``` **master 機器裡須做以下** SSH 無密碼登入,從 master 登入 slave 要可以使用無密碼登入 ``` $ suo apt-get install ssh $ mkdir ~/.ssh $ cd ~/.ssh $ ssh-keygen -t rsa $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys $ scp ~/.ssh/id_rsa.pub hadoop@slave01:/home/hadoop/ $ scp ~/.ssh/id_rsa.pub hadoop@slave02:/home/hadoop/ $ scp ~/.ssh/id_rsa.pub hadoop@slave03:/home/hadoop/ ``` 測試是否可以使用 shh 無密碼登入 ``` $ ssh slave01 $ ssh slave02 $ ssh slave03 ``` ## 配置 Config 檔 **配置 core-site.xml 檔** ``` $ sudo nano /usr/local/hadoop/etc/hadoop/core-site.xml ``` 在 <configuration> 中新增以下內容 ``` <configuration> <property> <name>fs.defaultFS</name> <value>hdfs://master:9000</value> </property> <property> <name>hadoop.tmp.dir</name> <value>file:/usr/local/hadoop/tmp</value> <description>Abase for other temporary directories.</description> </property> </configuration> ``` **配置 hdfs-site.xml 檔** ``` $ sudo nano /usr/local/hadoop/etc/hadoop/hdfs-site.xml ``` 在 <configuration> 中新增以下內容 ``` <configuration> <property> <name>dfs.namenode.secondary.http-address</name> <value>master:50090</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:/usr/local/hadoop/tmp/dfs/name</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:/usr/local/hadoop/tmp/dfs/data</value> </property> <property> <name>dfs.replication</name> <value>3</value> </property> </configuration> ``` **配置 mapred-site.xml 檔** 默認情況下,/usr/local/hadoop/etc/hadoop/ 文件夾下有 mapred.xml.template 文件,我們要復制該文件,並命名為 mapred.xml,該文件用於指定 MapReduce 使用的框架。 ``` $ sudo nano /usr/local/hadoop/etc/hadoop/mapred-site.xml ``` 在 <configuration> 中新增以下內容 ``` <configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>mapreduce.jobhistory.address</name> <value>master:10020</value> <description>MapReduce JobHistory Server IPC host:port</description> </property> <property> <name>mapreduce.jobhistory.webapp.address</name> <value>master:19888</value> <description>MapReduce JobHistory Server Web UI host:port</description> </property> </configuration> ``` **配置 yarn-site.xml 檔** ``` $ sudo nano /usr/local/hadoop/etc/hadoop/yarn-site.xml ``` 在 <configuration> 中新增以下內容 ``` <configuration> <!-- Site specific YARN configuration properties --> <property> <name>yarn.resourcemanager.hostname</name> <value>master</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.resourcemanager.webapp.address</name> <value>master:8088</value> <description>The http address of the RM web application. If only a host is provided as the value, the webapp will be served on a random port.</description> </property> <property> <name>yarn.resourcemanager.scheduler.address</name> <value>master:8030</value> <description>The Kerberos principal for the resource manager.</description> </property> <property> <name>yarn.resourcemanager.address</name> <value>master:8032</value> <description>The address of the applications manager interface in the RM.</description> </property> <property> <name>yarn.resourcemanager.resource-tracker.address</name> <value>master:8031</value> </property> <property> <name>yarn.resourcemanager.admin.address</name> <value>master:8033</value> <description>The address of the RM admin interface.</description> </property> </configuration> ``` 為了要讓 hadoop 可以認得目前所有的 data node,因此需要修改 /usr/local/hadoop/etc/hadoop/slaves 檔案,在裡面加入 data node 的連結資訊 ``` $ sudo nano /usr/local/hadoop/etc/hadoop/slaves ``` 在裡面移除原本的 localhost ,並且新增 data node 位置(一台一行) ``` master slave01 slave02 slave03 ``` 接下來,我們要將 master 上面的 hadoop 資料夾打包,傳輸給所有 slave 主機: ``` $ cd /usr/local $ rm -r ./hadoop/tmp $ sudo tar -zcf ./hadoop.tar.gz ./hadoop $ scp ./hadoop.tar.gz slave01:/home/hadoop $ scp ./hadoop.tar.gz slave02:/home/hadoop $ scp ./hadoop.tar.gz slave03:/home/hadoop ``` 傳輸完畢,我們分別到 slave01、slave02、slave03 主機裡,進行操作: ``` $ sudo tar -zxf ~/hadoop.tar.gz -C /usr/local $ sudo chown -R hadoop:hadoop /usr/local/hadoop ``` 第一次執行 Hadoop 時,需要先格式化 name node,這步驟需要到 master 中 hadoop 所在的資料夾下執行 ``` $ cd /usr/local/hadoop $ bin/hdfs namenode -format ``` 接著啟動 Hadoop ``` $ sbin/start-all.sh ``` 如果沒有出現其他錯誤訊息,可以使用 jps 查看目前已經啟動的服務有哪些 ``` $ jps ``` ![](https://i.imgur.com/MaFxiju.png) 查看 node資訊 ``` $ hdfs dfsadmin -report ``` ![](https://i.imgur.com/Jmz9dhS.png) 停止所有服務 ``` $ sbin/stop-all.sh ``` --- ## 參考 * https://medium.com/@sleo1104/hadoop-3-2-0-%E5%AE%89%E8%A3%9D%E6%95%99%E5%AD%B8%E8%88%87%E4%BB%8B%E7%B4%B9-22aa183be33a * https://www.cc.ntu.edu.tw/chinese/epaper/0036/20160321_3609.html * https://hadoop.apache.org/docs/r2.10.1/hadoop-project-dist/hadoop-common/CredentialProviderAPI.html ## Thank you! :dash: You can find me on - GitHub: https://github.com/shaung08 - Email: a2369875@gmail.com

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully