Hadoop Hbase Pseudo-Distributed Local Install 安裝記錄
今天部署了一下hadoop和hbase,期間踩了不少坑。寫此文以幫助hadoop、hbase的新手避坑。
不要選擇最新的軟件
不要選擇最新的軟件
不要選擇最新的軟件
重要的事情說三遍
安裝包下載
jdk:
- 版本:jdk-8u191-linux-x64.tar.gz
- 網址:wget http://upyun.qubianzhong.cn/file/java/jdk-8u191-linux-x64.tar.gz
- 來自:https://cloud.tencent.com/developer/article/1371521
hadoop:
- 版本:hadoop-2.9.2.tar.gz
- 網址:https://hadoop.apache.org/releases.html
hbase:
- 版本:hbase-1.4.9-bin.tar.gz
- 網址:http://hbase.apache.org/downloads.html
百度雲:
- 鏈接: https://pan.baidu.com/s/1z8iX9IxTiYgDNNYp_f5vrA
- 提取碼: 81iu
jdk
將壓縮包解壓放置於你喜歡的目錄,並進入該目錄,筆者放在了/home/bruce/Software。
編輯/etc/profile文件,添加環境變量
export JAVA_HOME=/home/bruce/Software/jdk1.8.0_191
export JAR_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JAR_HOME/lib:$CLASSPATH
export PATH=$PATH:$JAVA_HOME/bin:$JAR_HOME/bin
Hadoop
安裝依賴
首先安裝以下軟件:
$ sudo apt-get install ssh
$ sudo apt-get install rsync
下載Hadoop:
將壓縮包解壓放置於你喜歡的目錄,並進入該目錄,筆者放在了/home/bruce/Software。
cd hadoop-2.9.2/
可以在/etc/profile中爲hadoop添加環境變量:
export Hadoop=/home/bruce/Software/hadoop-2.9.2/bin
export PATH=$PATH:$JAVA_HOME/bin:$JAR_HOME/bin:$Hadoop
修改配置:
etc/hadoop/core-site.xml:
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
etc/hadoop/hdfs-site.xml:
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
修改 etc/hadoop/hadoop-env.sh 文件:
在文件末尾加入
export JAVA_HOME=/home/bruce/Software/jdk1.8.0_191
配置無密碼ssh登錄
確認是否可以無密碼登錄:
ssh localhost
若不可以則執行以下操作:
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
本地運行一個 MapReduce job
- 格式化文件系統
bin/hdfs namenode -format
- Start NameNode daemon and DataNode daemon:
sbin/start-dfs.sh
運行完後應該可以訪問http://localhost:50070/
3. Make the HDFS directories required to execute MapReduce jobs:
bin/hdfs dfs -mkdir /user
bin/hdfs dfs -mkdir /user/<username>
- Copy the input files into the distributed filesystem:
bin/hdfs dfs -put etc/hadoop input
- Run some of the examples provided:
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.9.2.jar grep input output 'dfs[a-z.]+'
執行 jps 可以看到以下進程:
$ jps
15975 Jps
15017 NameNode
15389 SecondaryNameNode
15182 DataNode
- Examine the output files: Copy the output files from the distributed filesystem to the local filesystem and examine them:
bin/hdfs dfs -get output output
cat output/*
成功的話會得到如下輸出:
6 dfs.audit.logger
4 dfs.class
3 dfs.logger
3 dfs.server.namenode.
2 dfs.audit.log.maxbackupindex
2 dfs.period
2 dfs.audit.log.maxfilesize
1 dfs.log
1 dfs.file
1 dfs.servers
1 dfsadmin
1 dfsmetrics.log
1 dfs.replication
or
View the output files on the distributed filesystem:
bin/hdfs dfs -cat output/*
會得到一樣的輸出
Hbase
下載Hbase:
將壓縮包解壓放置於你喜歡的目錄,並進入該目錄,筆者放在了/home/bruce/Software。
cd hbase-1.4.9/
可以在/etc/profile中爲hbase添加環境變量:
export Hbase=/home/bruce/Software/hbase-1.4.9/bin
export PATH=$PATH:$JAVA_HOME/bin:$JAR_HOME/bin:$Hadoop:$Hbase
修改配置
- 編輯 conf/hbase-site.xml 文件
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://localhost:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/hadoop/zookeeper</value>
</property>
</configuration>
- 編輯 conf/hbase-env.sh 文件
在文件末尾加入:
export JAVA_HOME=/home/bruce/Software/jdk1.8.0_191
- 啓動hbase
bin/start-hbase.sh
若啓動成功,執行jps會看到一下進程:
$ jps
16503 HMaster
16951 Jps
15017 NameNode
16426 HQuorumPeer
15389 SecondaryNameNode
15182 DataNode
16639 HRegionServer
- hdfs會自動生成hbase目錄
$ ./bin/hadoop fs -ls /hbase
Found 8 items
drwxr-xr-x - hadoop supergroup 0 2019-04-23 23:33 /hbase/.tmp
drwxr-xr-x - hadoop supergroup 0 2019-04-23 23:33 /hbase/MasterProcWALs
drwxr-xr-x - hadoop supergroup 0 2019-04-23 23:33 /hbase/WALs
drwxr-xr-x - hadoop supergroup 0 2019-04-23 23:33 /hbase/data
drwxr-xr-x - hadoop supergroup 0 2019-04-23 23:33 /hbase/hbase
-rw-r--r-- 1 hadoop supergroup 42 2019-04-23 23:32 /hbase/hbase.id
-rw-r--r-- 1 hadoop supergroup 7 2019-04-23 23:32 /hbase/hbase.version
drwxr-xr-x - hadoop supergroup 0 2019-04-23 23:34 /hbase/oldWALs
權限問題
以上操作可以使用root用戶進行操作。也可以使用普通用戶,若遇到權限問題,可以添加一個hadoop用戶
#添加用戶
sudo addgroup hadoop
sudo adduser -g hadoop hadoop
#爲新用戶添加root權限
sudo vim /etc/sudoers
#在文件中添加
hadoop ALL=(ALL:ALL) ALL
#改變目錄所有權
chown -R hadoop:hadoop hadoop-2.9.2/
chmod -R 755 hadhbase-1.4.9/
chown -R hadoop:hadoop hbase-1.4.9/
chmod -R 755 hbase-1.4.9/