类型 | zookeeper | Hbase | |
---|---|---|---|
master | NameNode | 是 | HMaster |
slave1 | DataNode | 是 | HRegionServer |
slave2 | DataNode | 是 | HRegionServer |
slave3 | DataNode | 是 | HRegionServer |
hosts
文件(这里用的DHCP
)IP | hostname |
---|---|
10.108.21.X | master |
10.108.22.X | slave1 |
10.108.22.X | slave2 |
10.108.21.X | slave3 |
hadoop
安装vim /etc/hostname
将内容全删除后修改为:master(slave1\slave2\slave3同样操作
vi /etc/hosts
修改为上述hosts文件,将ip和hostname作映射
关闭防火墙
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service
关闭selinux
vi /etc/selinux/config
将SELinux status参数设定为关闭状态
SELinux status: disabled
需要重启,需要重启,需要重启
useradd -m hadoop
passwd hadoop #123456(忽略警告)
usermod -a -G hadoop hadoop # 将hadoop用户移进hadoop用户组
cat /etc/group #查看用户组
$ visudo
##在行 root ALL=(ALL) ALL下添加
%hadoop ALL=(ALL) ALL
hadoop ALL=(ALL) ALL
并切换到hadoop用户:$ su hadoop
先对每个主机都生成rsa密钥,如生成master的rsa密钥
ssh-keygen -t rsa
后面都可以在master操作,将生成的rsa追加写入授权文件
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
给授权文件权限
chmod 600 ~/.ssh/authorized_keys
对本机ssh测试(第一次需要密码)
ssh master
将master上的authorized_keys传到slave1
sudo scp ~/.ssh/id_rsa.pub hadoop@slave1:~/
登陆连接到slave1进行操作:
ssh slave1
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
#修改权限
chmod 600 ~/.ssh/authorized_keys
#退出slave1
exit
进行免密测试
ssh slave1
其他主机同理
这里安装的版本为:jdk-8u211-linux-x64.tar.gz
编辑环境变量
vi ~/.bashrc
将java目录添加进环境
#java 1.8
JAVA_HOME=/usr/local/java/jdk1.8.0_211
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
查看JAVA环境变量
echo $JAVA_HOME
下载3.1.2版本
使用命令将解压放至home/hadoop 下,我的解压完后目录为:
/home/hadoop/hadoop-3.1.2
vi hadoop/hadoop-3.1.2/etc/hadoop/hadoop-env.sh
把JAVA_HOME添加进去
export JAVA_HOME=/usr/local/java/jdk1.8.0_211
<configuration>
<property>
<name>fs.defaultFSname>
<value>hdfs://master:9000/value>
property>
<property>
<name>hadoop.tmp.dirname>
<value>/home/hadoop/hadoop-3.1.2/tmpvalue>
property>
<property>
<name>ha.zookeeper.quorumname>
<value>slave1:2181,slave2:2181,slave3:2181value>
property>
configuration>
<configuration>
<property>
<name>dfs.namenode.name.dirname>
<value>/home/hadoop/hadoop-3.1.2/namenodevalue>
property>
<property>
<name>dfs.datanode.data.dirname>
<value>/home/hadoop/hadoop-3.1.2/datanodevalue>
property>
<property>
<name>dfs.replicationname>
<value>1value>
property>
configuration>
<configuration>
<property>
<name>mapreduce.framework.namename>
<value>yarnvalue>
property>
<property>
<name>yarn.app.mapreduce.am.envname>
<value>HADOOP_MAPRED_HOME=/home/hadoop/hadoop-3.1.2value>
property>
<property>
<name>mapreduce.map.envname>
<value>HADOOP_MAPRED_HOME=/home/hadoop/hadoop-3.1.2value>
property>
<property>
<name>mapreduce.reduce.envname>
<value>HADOOP_MAPRED_HOME=/home/hadoop/hadoop-3.1.2value>
property>
configuration>
<configuration>
<property>
<name>yarn.resourcemanager.hostnamename>
<value>mastervalue>
property>
<property>
<name>yarn.nodemanager.aux-servicesname>
<value>mapreduce_shufflevalue>
property>
<property>
<name>yarn.resourcemanager.zk-addressname>
<value>slave1:2181,slave2:2181,slave3:2181value>
property>
configuration>
$ vi workers
# 添加如下内容
slave1
slave2
slave3
这两个文件在/usr/local/hadoop/hadoop-3.1.2/sbin/
中,分别在 start-dfs.sh
和 stop-dfs.sh
中添加如下内容
HDFS_JOURNALNODE_USER=root
HDFS_ZKFC_USER=hadoop
HDFS_DATANODE_USER=hadoop
HDFS_DATANODE_SECURE_USER=hdfs
HDFS_NAMENODE_USER=hadoop
HDFS_SECONDARYNAMENODE_USER=hadoop
这两个文件在 /usr/local/hadoop/hadoop-3.1.2/sbin/
中,分别在 start-yarn.sh
和 stop-yarn.sh
中添加如下内容
YARN_RESOURCEMANAGER_USER=hadoop
HADOOP_SECURE_DN_USER=yarn
YARN_NODEMANAGER_USER=hadoop
$ vi ~/.bashrc
export HADOOP_HOME=/home/hadoop/hadoop-3.1.2
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
更新环境变量:source ~/.bashrc
上面的操作要在每一个节点上都同步,但是一个一个的去编辑太麻烦了,可以用scp
命令,在 master
节点编辑好之后,直接发送给 slave
节点
scp -r /home/hadoop/hadoop-3.1.2 hadoop@slave1:/home/hadoop
scp -r ~/.bashrc hadoop@salve1:~/
后分别到其他节点更新环境变量source ~/.bashrc
即可。到这,可以启动hadoop,但我们到后面全安好后再启动。
下载的版本为稳定版3.5.5解压至zookeeper文件夹
tar -zxvf apache-zookeeper-3.5.5-bin.tar.gz -C /home/hadoop/zookeeper
编辑环境变量:vi ~/.bashrc
,添加下面的内容
#java 1.8
JAVA_HOME=/usr/local/java/jdk1.8.0_211
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
export HADOOP_HOME=/home/hadoop/hadoop-3.1.2
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
#新加
export ZOOKEEPER_HOME=/home/hadoop/zookeeper/apache-zookeeper-3.5.5
export PATH=.:$HADOOP_HOME/bin:$ZOOKEEPER_HOME/bin:$JAVA_HOME/bin:$PATH
更新环境变量:source ~/.bashrc
需要将 需要将 $ZOOKEEPER_HOME/conf
目录下的zoo_sample.cfg
重命名为 zoo.cfg
cp $ZOOKEEPER_HOME/conf/zoo_sample.cfg $ZOOKEEPER_HOME/conf/zoo.cfg
默认为:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
tickTime: ZooKeeper 中使用的基本时间单元, 以毫秒为单位, 默认值是 2000。它用来调节心跳和超时。例如, 默认的会话超时时间是两倍的 tickTime。
initLimit: 默认值是 10, 即 tickTime 属性值的 10 倍。它用于配置允许 followers 连接并同步到 leader 的最大时间。如果 ZooKeeper 管理的数据量很大的话可以增加这个值。
syncLimit: 默认值是 5, 即 tickTime 属性值的 5 倍。它用于配置leader 和 followers 间进行心跳检测的最大延迟时间。如果在设置的时间内 followers 无法与 leader 进行通信, 那么 followers 将会被丢弃。
dataDir: ZooKeeper 用来存储内存数据库快照的目录, 并且除非指定其它目录, 否则数据库更新的事务日志也将会存储在该目录下。建议配置 dataLogDir 参数来指定 ZooKeeper 事务日志的存储目录。
clientPort: 服务器监听客户端连接的端口, 也即客户端尝试连接的端口, 默认值是 2181。
maxClientCnxns: 在 socket 级别限制单个客户端与单台服务器之前的并发连接数量, 可以通过 IP 地址来区分不同的客户端。它用来防止某种类型的 DoS 攻击, 包括文件描述符耗尽。默认值是 60。将其设置为 0 将完全移除并发连接数的限制。
autopurge.snapRetainCount: 配置 ZooKeeper 在自动清理的时候需要保留的数据文件快照的数量和对应的事务日志文件, 默认值是 3
autopurge.purgeInterval: 和参数 autopurge.snapRetainCount 配套使用, 用于配置 ZooKeeper 自动清理文件的频率, 默认值是 1, 即默认开启自动清理功能, 设置为 0 则表示禁用自动清理功能。
修改为:
ticketTime=2000
clientPort=2181
dataDir=/home/hadoop/zookeeper/apache-zookeeper-3.5.5/data
dataLogDir=/home/hadoop/zookeeper/apache-zookeeper-3.5.5/logs
initLimit=10
syncLimit=5
server.1=slave1:2888:3888
server.2=slave2:2888:3888
server.3=slave3:2888:3888
scp .bashrc hadoop@slave2:~
scp -r /home/hadoop/zookeeper hadoop@slave2:/home/hadoop/
分别:source ~/.bashrc
mkdir data
cd data
echo "1" > myid
# 在slave2中则:echo "2" > myid
可以启动,但等hbase安装完再一次启动
下载版本:hbase2.0.5
tar -zvxf hbase-2.0.5-bin.tar.gz -C /home/hadoop
vi ~/.bashrc
# 添加
export HBASE_HOME=/home/hadoop/hbase-2.0.5
export PATH=$HBASE_HOME/bin:$PATH
#更新变量
source ~/.bashrc
hbase-2.0.1/conf
目录下的hbase-env.sh
文件export JAVA_HOME=/opt/jdk1.8.0_161
export HBASE_MANAGES_ZK=false
其中HBASE_MANAGES_ZK=false
表示我们使用自己安装zookeeper
集群而不是hbase
自带的zookeeper
集群
hbase-2.0.1/conf
目录下的hbase-site.xml
文件<configuration>
<property>
<name>hbase.rootdirname>
<value>hdfs://master:9000/hbasevalue>
property>
<property>
<name>hbase.cluster.distributedname>
<value>truevalue>
property>
<property>
<name>hbase.zookeeper.quorumname>
<value>slave1,slave2,slave3value>
property>
<property>
<name>hbase.zookeeper.property.dataDirname>
<value>/home/hadoop/zookeeper/apache-zookeeper-3.5.5/datavalue>
property>
<property>
<name>hbase.unsafe.stream.capability.enforcename>
<value>falsevalue>
property>
configuration>
hbase-2.0.1/conf
目录下的regionservers
vi regionservers
# 将localhost删除,修改为附节点(注意一个节点占一行)
slave1
slave2
slave3
scp ~/.bashrc hadoop@slave2:~
scp -r /home/hadoop/hbase-2.0.5 hadoop@slave1:/home/hadoop
分别更新:source ~/.bashrc
cd /hadoop-3.1.2/bin
hdfs namenode -format
启动:journalnode
hadoop-daemon.sh start journalnode
hadoop
:start-all.sh
# master上的进程
[hadoop@master ryan]$ jps
5505 SecondaryNameNode
6373 Jps
5782 ResourceManager
5942 NodeManager
5083 NameNode
# slave上的
[hadoop@slave1 ~]$ jps
3718 DataNode
3853 NodeManager
4095 Jps
zookeeper
:zkServer.sh start
[hadoop@slave1 ~]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/hadoop/zookeeper/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hadoop@slave1 ~]$ jps
4192 Jps
3718 DataNode
4150 QuorumPeerMain
3853 NodeManager
[hadoop@slave3 ~]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/hadoop/zookeeper/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[hadoop@master ryan]$ start-hbase.sh
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/hbase-2.0.5/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop-3.1.2/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
running master, logging to /home/hadoop/hbase-2.0.5/logs/hbase-hadoop-master-master.out
slave1: running regionserver, logging to /home/hadoop/hbase-2.0.5/logs/hbase-hadoop-regionserver-slave1.out
slave3: running regionserver, logging to /home/hadoop/hbase-2.0.5/logs/hbase-hadoop-regionserver-slave3.out
slave2: running regionserver, logging to /home/hadoop/hbase-2.0.5/logs/hbase-hadoop-regionserver-slave2.out
[hadoop@master ryan]$ jps
5505 SecondaryNameNode
6931 Jps
5782 ResourceManager
5942 NodeManager
5083 NameNode
6651 HMaster
[hadoop@slave1 ~]$ jps
4608 Jps
3718 DataNode
4150 QuorumPeerMain
3853 NodeManager
4303 HRegionServer
http://master:9870/
http://master:16010
在新节点上启动datanode
$HADOOP_HOME/bin/hdfs --daemon start datanode
在新节点上启动nodemanager
$HADOOP_HOME/bin/yarn --daemon start nodemanager
查看hdfs各节点状态
$HADOOP_HOME/bin/hdfs dfsadmin -report
查看yarn各节点状态
$HADOOP_HOME/bin/yarn node -list
查看日志,发现是clusterid不一致导致的(重新格式化namenode过,导致clusterid发生变化):
2019-06-25 16:23:24,276 WARN org.apache.hadoop.hdfs.server.common.Storage: Failed to add storage directory [DISK]file:/home/hadoop/hadoop-3.1.2/datanode
java.io.IOException: Incompatible clusterIDs in /home/hadoop/hadoop-3.1.2/datanode: namenode clusterID = CID-97afc142-0916-411a-bf29-ef6e07819c2b; datanode clusterID = CID-21311f72-47dc-4949-b740-077ead1e4ba9
查看clusterid
cat /home/hadoop/hadoop-3.1.2/datanode/current/VERSION
cat /home/hadoop/hadoop-3.1.2/namenode/current/VERSION
#Wed Jun 05 15:36:39 CST 2019
storageID=DS-0c9cc045-55a0-496d-ad1a-a21e80d03b77
clusterID=CID-21311f72-47dc-4949-b740-077ead1e4ba9
cTime=0
datanodeUuid=c7437eac-3009-4938-afe0-5db675e60a11
storageType=DATA_NODE
layoutVersion=-57
查看slave2的,发现和namedode的clusterid不一样,修改clusterID,与namenode的一致,修改后可以查看节点
[hadoop@slave2 current]$ cat VERSION
#Wed Jun 05 16:17:01 CST 2019
storageID=DS-c0f1af27-a2ae-4977-aa32-7b319cc76760
clusterID=CID-59aaa59c-e67a-4dee-99ff-d47361c52a52
cTime=0
datanodeUuid=a34dd4a0-3ac5-472e-ab75-fcac8f90a885
storageType=DATA_NODE
layoutVersion=-57
直接启动:start-all.sh
查看:http://master:9870
启动正常
slave1/2/3 启动zookeeper
zkServer.sh start
(3台都启动后)
使用:zkServer.sh status
会有节点是follower,有的是leader
此时,再查看:
查看:http://master:9870
保持正常
start-hbase.sh(master)
查看:http://master:16010
,无法打开网页
使用jps查看进程:
master上HMaster开启失败,slave上的HRegionServer开启成功
查看日志:
java.lang.IllegalStateException:
The procedure WAL relies on the ability to hsync for proper
operation during component failures, but the underlying filesystem does not support doing so.
Please check the config value of 'hbase.procedure.store.wal.use.hsync' to set the desired level
of robustness and ensure the config value of 'hbase.wal.dir' points to a FileSystem mount that
can provide it.
在master上修改:
hbase-site.xml
增加配置
<property>
<name>hbase.unsafe.stream.capability.enforcename>
<value>falsevalue>
property>
再次启动:
start-hbase.sh
,查看jps
存在HMaster进程,网页登陆:http://master:16010
,成功启动,问题解决,多查看日志