软件环境
一个master 节点两个slave节点
jdk1.7.0_71
hadoop-2.6.2
hbase-0.98.9
zookeeper-3.4.5
配置主机名
vi /etc/hosts
vi /etc/sysconfig/network
hostname master
hostname
配置网络
setup
service network restart
ifconfig
关防火墙
service iptables stop
chkconfig iptables off
service iptables status
安装jdk,zookeeper,hadoop,Hbase,配置环境变量
vi /etc/profile
export ZOOKEEPER_HOME=/home/wyz/zookeeper-3.4.5
export JAVA_HOME=/home/wyz/jdk1.7.0_71
export HADOOP_HOME=/home/wyz/hadoop-2.6.2
export PATH=$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZOOKEEPER_HOME/bin:$PATH
验证是否生效
source /etc/profile
java -version
hadoop version
互信
ssh-keygen -t rsa
ssh-copy-id -i hadoop@slave01
ssh slave01
修改配置文件$HADOOP_HOME/etc/hadoop
第一个:hadoop-env.sh
vim hadoop-env.sh
–$JAVA_HOME=/usr/java/jdk1.8.0_65
yarn-env.sh
vim yarn-env.sh
–$JAVA_HOME
第二个:core-site.xml
vim core-site.xml
<configuration>
<property>
<name> fs.defaultFS </name>
<value>hdfs://主机名(或IP):9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>(hadoop绝对路径)/tmp</value>
</property>
</configuration>
第三个:hdfs-site.xml
vim hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:///usr/hadoop/hadoop-2.6.2/hdfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:///usr/hadoop/hadoop-2.6.2/hdfs/data</value>
</property>
</configuration>
第四个:mapred-site.xml
vim mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
第五个:yarn-site.xml
vim yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>master</value>
</property>
</configuration>
第六个:slave(单机测试不修改slave即可,成功后在修改)
在上面创建的路径下创建hdfs文件夹
mkdir hdfs
因为每台机器上的hadoop的配置文件以及jdk都是一样的,直接复制
scp -r hadoop-2.6.2 slave01:/home/wyz
scp -r jdk slave01:/home/wyz
在master节点上格式化hdfs,启动hadoop
hadoop namenode -format
start-all.sh
查看节点启动情况,通过浏览器50070端口查看
jps
ip:50070
此时hadoop全分布式安装完成
配置zookeeper
/home/wyz/zookeeper-3.4.5/conf
[wyz@slave02 conf]$ cat 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=/home/wyz/zookeeper/data
dataLogDir=/home/wyz/zookeeper/logs
# the port at which the clients will connect
clientPort=2181
#zookeeper cluster
server.1=master:2881:3881
server.2=slave01:2881:3881
server.3=slave02:2881:3881
#
# 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
[wyz@slave02 conf]$
创建myid文件,data文件夹,logs文件夹,zookeeper文件夹,目录结构为
mkdir zookeeper
mkdir /home/wyz/zookeeper/data
mkdri /home/wyz/zookeeper/logs
cd data
touch myid
vi myid
在master上的myid文件内容只写1(与server.1对应)
在slave01上的myid文件内容只写2(与server.2对应)
在slave02上的myid文件内容只写3(与server.3对应)
scp -r zookeeper文件夹 slave01:/home/wyz
scp -r zookeeper文件夹 slave02:/home/wyz
启动zookeeper集群(依次启动3台),查看状态
bin/zkServer.sh start
bin/zkServer.sh status
连接zookeeper集群中的一台slave02的客户端,通过2181端口访问
bin/zkCli.sh -server slave02:2181
输入help
zookeeper已经安装成功
配置Hbase文件/home/wyz/hbase-0.98.9/conf
vi hbase-env.sh(在分别的四行里面)
export JAVA_HOME=/home/wyz/jdk1.7.0_71/
export HBASE_CLASSPATH=/home/wyz/hadoop-2.6.2/etc/hadoop:/home/wyz/zookeeper-3.4.5/conf
export HBASE_OPTS="-XX:+UseConcMarkSweepGC"
export HBASE_MANAGES_ZK=false (false表示使用外部zookeeper集群)
vi hbase-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.rootdir</name>
<value>hdfs://master:9000/hbase</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>master,slave01,slave02</value>
</property>
</configuration>
vi regionservers
slave01
slave02
复制文件到另外两台机器
scp -r zookeeper文件夹 slave01:/home/wyz
scp -r zookeeper文件夹 slave02:/home/wyz
启动并验证HBase
cd /home/wyz/hbase文件夹
bin/start-hbase.sh
通过浏览器60010端口访问
ip:60010
启动hbase服务之前,需要先启动zookeeper服务,再启动hadoop服务
HBase Shell 的简单操作命令(前提:Hbase集群正常启动,且可以正常运行)
进入客户端
cd /home/wyz/hbase文件夹
bin/hbase shell
查看列表
list
创建testbasebase
create 'testbasebase', {NAME => 'cf1', VERSIONS => 5}
再次查看列表对比
list
插入数据
put 'testbasebase','aid001','cf1:uid','001'
扫描查询数据
scan 'testbasebase'
单条查询数据
get 'testbasebase','aid001'
查看表结构
describe 'testbasebase'
修改表
disabel 'testbasebase'
alter 'testbasebase',NAME => 'cf1',VERSIONS => 3
enable 'testbasebase'
再次查看表结构对比
describe 'testbasebase'
清空表
truncate 'testbasebase'
扫描表
scan 'testbasebase'
删除表
disable 'testbasebase'
drop 'testbasebase'
list
创建新表uid_cnt
create 'uid_cnt',{NAME => 'cf1', VERSIONS => 5}
ps:在linux的vim脚本里
:$ 跳到文件最后一行
:0或:1 跳到文件第一行
$跳到行末尾
dd删除整行
gg 跳到文件第一行
Shift + g 跳到文件最后一行
HBase Shell命令行里
执行删除操作时,需要使用组合键:Ctrl+Back Space同时按下