current position:Home>Ubuntu18.04 install Hadoop
Ubuntu18.04 install Hadoop
2023-01-25 11:29:55【nickdlk】
课程需要 安装Hadoop
安装Ubuntu
清华源镜像:
Index of /ubuntu-releases/18.04/ | 清华大学开源软件镜像站 | Tsinghua Open Source
Mirror https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/18.04/
Network mode is used after installationNAT
配置SSH无密码登录
安装:sudo apt-get install openssh-server
cd ~/.ssh/ # 若没有该目录,请先执行一次ssh localhost
ssh-keygen -t rsa # 会有提示,都按回车就可以
cat ./id_rsa.pub >> ./authorized_keys # 加入授权
登录:ssh localhost
安装Hadoop
sudo useradd -m hadoop -s /bin/bash # 创建hadoop用户
sudo passwd hadoop # 修改密码
sudo adduser hadoop sudo # 增加管理员权限
注销并使用 Hadoop 用户登录
sudo apt-get update # 更新apt
sudo apt-get install vim # 安装vim
sudo apt-get install openssh-server
cd ~
mkdir .ssh # 可能该文件已存在,不影响
cd ~/.ssh/
ssh-keygen -t rsa # 会有提示,都按回车就可以
cat id_rsa.pub >> authorized_keys # 加入授权
JDK
离线安装:
jdk-8u162-linux-x64.tar.gz
https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html
需要登录
cd /usr/lib
sudo mkdir jvm #创建/usr/lib/jvm目录用来存放JDK文件
sudo tar -zxvf ./jdk-8u162-linux-x64.tar.gz -C /usr/lib/jvm #把JDK文件解压到/usr/lib/jvm目录下
echo "export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_162" >> ~/.bashrc
echo "export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH" >> ~/.bashrc
或者使用VIM编辑.
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_162
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
使环境变量生效:source ~/.bashrc
在线安装:
sudo apt-get install openjdk-7-jre openjdk-7-jdk
添加环境变量:
echo "export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64" >> ~/.bashrc
使环境变量生效:source ~/.bashrc
java -version
java version “1.8.0_162”
Java SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot 64-Bit Server VM (build 25.162-b12, mixed mode)
安装hadoop3.1.3
离线安装:
下载hadoop3.1.3
sudo tar -zxf ~/下载/hadoop-3.1.3.tar.gz -C /usr/local # 解压到/usr/local中
cd /usr/local/
sudo mv ./hadoop-3.1.3/ ./hadoop # 将文件夹名改为hadoop
sudo chown -R hadoop ./hadoop
sudo tar -zxf hadoop-3.1.3.tar.gz -C /usr/local # 解压到/usr/local中
cd /usr/local/
sudo mv ./hadoop-3.1.3/ ./hadoop # 将文件夹名改为hadoop
sudo chown -R hadoop ./hadoop
cd /usr/local/hadoop
./bin/hadoop version
添加环境变量:
echo "export HADOOP_HOME=/usr/local/hadoop export PATH=.:${HADOOP_HOME}/bin:$PATH" >> ~/.bashrc
单机配置(非分布式)
测试
Hadoop 默认模式为非分布式模式(本地模式),无需进行其他配置即可运行.非分布式即单 Java 进程,方便进行调试.
现在我们可以执行例子来感受下 Hadoop 的运行.Hadoop 附带了丰富的例子(运行 ./bin/hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar 可以看到所有例子),包括 wordcount、terasort、join、grep 等.
在此我们选择运行 grep 例子,我们将 input 文件夹中的所有文件作为输入,筛选当中符合正则表达式 dfs[a-z.]+ 的单词并统计出现的次数,最后输出结果到 output 文件夹中.
cd /usr/local/hadoop
mkdir ./input
cp ./etc/hadoop/*.xml ./input # 将配置文件作为输入文件
./bin/hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar grep ./input ./output 'dfs[a-z.]+'
cat ./output/* # 查看运行结果
删除运行结果rm -r ./output
伪分布式配置
Hadoop 可以在单节点上以伪分布式的方式运行,Hadoop 进程以分离的 Java 进程来运行,节点既作为 NameNode 也作为 DataNode,同时,读取的是 HDFS 中的文件.
Hadoop 的配置文件位于 /usr/local/hadoop/etc/hadoop/ 中,伪分布式需要修改2个配置文件 core-site.xml 和 hdfs-site.xml .Hadoop的配置文件是 xml 格式,每个配置以声明 property 的 name 和 value 的方式来实现.
修改配置文件
配置在/usr/local/hadoop/etc/hadoopgedit ./etc/hadoop/core-site.xml
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/usr/local/hadoop/tmp</value>
<description>Abase for other temporary directories.</description>
</property>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
注:这里的IPCan be changed to a virtual machineIP 在后面使用IDEAconnect without error
gedit ./etc/hadoop/hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</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>
</configuration>
配置完成后,执行 NameNode 的格式化:
cd /usr/local/hadoop
./bin/hdfs namenode -format
接着开启 NameNode 和 DataNode 守护进程.
cd /usr/local/hadoop
./sbin/start-dfs.sh #start-dfs.sh是个完整的可执行文件,中间没有空格
jps查看是否启动了datanode
如果没启动:
# 针对 DataNode 没法启动的解决方法
cd /usr/local/hadoop
./sbin/stop-dfs.sh # 关闭
rm -r ./tmp # 删除 tmp 文件,注意这会删除 HDFS 中原有的所有数据
./bin/hdfs namenode -format # 重新格式化 NameNode
./sbin/start-dfs.sh # 重启
错误
1.没有配置好SSH
2.没有配置好环境变量
If the environment variable configuration is correct,修改:
hadoop的安装目录修改配置文件“/usr/local/hadoop/etc/hadoop/hadoop-env.sh”,在里面找到“export JAVA_HOME=${JAVA_HOME}”这行,然后,把它修改成JAVA安装路径的具体地址,比如,“export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_162”,然后,再次启动Hadoop.
启动成功
使用JPS命令查看是否启动成功
若成功启动则会列出如下进程: “NameNode”、”DataNode” 和 “SecondaryNameNode”(如果 SecondaryNameNode 没有启动,请运行 sbin/stop-dfs.sh 关闭进程,然后再次尝试启动尝试).如果没有 NameNode 或 DataNode ,那就是配置不成功,请仔细检查之前步骤,或通过查看启动日志排查原因.
ifconfig
查看IP
3.1.3 访问 IP:9870
2.1.7 访问 IP:50070
运行Hadoop伪分布式实例
./bin/hdfs dfs -mkdir -p /user/hadoop
复制文件
./bin/hdfs dfs -mkdir input
./bin/hdfs dfs -put ./etc/hadoop/*.xml input
查看文件列表:./bin/hdfs dfs -ls input
伪分布式运行 MapReduce 作业的方式跟单机模式相同,区别在于伪分布式读取的是HDFS中的文件(可以将单机步骤中创建的本地 input 文件夹,输出结果 output 文件夹都删掉来验证这一点).
运行:
./bin/hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar grep input output 'dfs[a-z.]+'
查看结果:./bin/hdfs dfs -cat output/*
关闭hadoop:./sbin/stop-dfs.sh
将运行结果取回到本地:
rm -r ./output # 先删除本地的 output 文件夹(如果存在)
./bin/hdfs dfs -get output ./output # 将 HDFS 上的 output 文件夹拷贝到本机
cat ./output/*
删除 output 文件夹:./bin/hdfs dfs -rm -r output
集群安装
网络配置
完整克隆虚拟机,修改网络配置为桥接模式.
copyright notice
author[nickdlk],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2023/025/202301251105496039.html
The sidebar is recommended
- Based on VirtualBox centos7 virtual machine installation
- JVM process cache - Caffeine
- Code Caprice No24 | Backtracking Algorithm Theoretical Basis, 77. Combination
- The Road to Algorithm Practice——[String] Leetcode 824 Goat Latin
- Git summary - Prompt to submit or temporarily store changes when switching to a branch
- Productivity tools - [gitlab configuration] One-time configuration of GitLab account
- Echo+Vue+ElementUI management background source code
- Revel+Vue+ElementUI framework use and build tutorial
- Basic practice tutorial of Revel+Vue+ElementUI framework
- Go Web Development Revel+Vue+ElementUI Framework Practical Tutorial
guess what you like
Construction and deployment tutorial of Revel+Vue+ElementUI framework
8. Java loop advanced comprehensive exercises - infinite loop and jump control statement, every seven passes, square root, judging whether it is a prime number, guessing number games
Control statement + exception handling perfect lucky draw applet-java basics
9. Java Array Knowledge Encyclopedia
Lucky draw applet-java basics
Java basic implementation calculator applet
The front end of actual combat: copy write millet's official website on the first day
1. Linux application programming and network programming---file IO notes in Linux system
7. Linux application programming and network programming --- thread full solution Notes
[Front-end notes - CSS] 10. Cascading and inheritance + selector
Random recommended
- 8. Linux application programming and network programming---Linux network programming notes
- [Java|golang] 1828. Count the number of points in a circle
- Add environment variables under Linux system and will not overwrite the previous method of adding environment variables
- 2 · Linux application programming and network programming - file attributes notes
- Redis interview questions (classic 7 questions)
- [Front-end notes——CSS] 11. Box model + background and border
- C + + large Numbers together, according to a combined
- 3. Linux application programming and network programming --- get system information notes
- The use and principle of Kafka message queue
- 5. Linux application programming and network programming---signal notes in Linux
- 6 · Linux application programming and system programming - senior IO notes
- Java collection common interview questions (4)
- 072-JAVA project training: Imitation QQ instant messaging software series lecture 7 (explaining the realization of the chat interface and functions)
- Coordination center performance comparison: how zookeeper solves the load balancing problem
- 070-JAVA project training: imitation QQ instant messaging software series lecture five (explain user registration function)
- Ubuntu installation and configuration (brief)
- 073-JAVA project training: imitation QQ instant messaging software series lecture eight (explain query and add friend function)
- SQL injection classification and error injection EXP
- All basic commands in linux fail, showing that the command cannot be found
- 4. Linux application programming and network programming---Linux process full solution notes (difference between process and program)
- Linux system - basic IO
- Hanlp's understanding of user-defined dictionaries (java version)
- Brief description and configuration of Maven
- 071-JAVA project training: imitation QQ instant messaging software series lecture six (explaining the function of QQ main interface)
- 【Maximum LeetCode】January Algorithm Training (12) Linked List
- 【Max LeetCode】January Algorithm Training (13) Doubly Linked List
- [Big Data Management] Java implements Bloom filter
- [Maximum LeetCode] Algorithm training in January (14) stack
- [Machine Learning] Adaboost Integrated Algorithm
- [Big Data Management] Java implements cuckoo filter (CF)
- Chaozhou Xiangqiao: "Charming Ancient City, Cultural Sharing" Spring Festival Intangible Cultural Heritage Market Opens
- [Big data management] Java realizes the dictionary tree TireTree
- [Max LeetCode] January Algorithm Training (11) Matrix
- New Express (Web framework based on HTTP module encapsulation NodeJS)
- JavaScript error-prone questions (stack processing, call function, prototype chain questions)
- Space "travel", lion and crane dance, intangible cultural heritage experience...During the Spring Festival, Zhuhai Jinwan is so fun!
- Wine 8.0 official release: better support for running Windows applications on Linux and other systems
- Zhongke Sugon: Sugon's new computer "participates in" "The Wandering Earth 2"
- Linux actual combat notes finishing (1.24)
- Automatically execute the specified sql when the springBoot project starts