search
HomeDatabaseMysql Tutorial分布式集群环境hadoop、hbase、zookeeper搭建(全)

1、环境说明 集群环境至少需要3个节点(也就是3台服务器设备):1个Master,2个Slave,节点之间局域网连接,可以相互ping通,下面举例说明,配置节点IP分配如下: Hostname IP 新建用户 新建用户密码 Master 10.10.10.213 hadoop 123456 Slave1 10.10.10.214

1、环境说明

集群环境至少需要3个节点(也就是3台服务器设备):1个Master,2个Slave,节点之间局域网连接,可以相互ping通,下面举例说明,配置节点IP分配如下:

Hostname IP 新建用户 新建用户密码
Master 10.10.10.213 hadoop 123456
Slave1 10.10.10.214 hadoop 123456
Slave2 10.10.10.215 hadoop 123456

三个节点均使用centos?6.3系统,为了便于维护,集群环境配置项最好使用相同用户名、用户密码、相同hadoop、hbase、zookeeper目录结构。

2、准备工作

2.1、修改Hostname

为了集群能够正常稳定的运行,我们需要将每个节点的hostname分别配置为对应的Master、Slave1、Slave2。

(1)在Master服务器中执行以下命令:

hostname Master	//当前有效
vi /etc/sysconfig/network	//重启后生效
HOSTNAME=Master

(2)在Slave1服务器中执行以下命令:

hostname Slave1	//当前有效
vi /etc/sysconfig/network	//重启后生效
HOSTNAME=Slave1

(3)在Slave2服务器中执行以下命令:

hostname Slave2	//当前有效
vi /etc/sysconfig/network	//重启后生效
HOSTNAME=Slave2

2.2、添加Hosts映射关系

分别在三个节点下通过如下命令修改hosts映射关系:

vi /etc/hosts

添加内容如下:

Master	10.10.10.213
Slave1	10.10.10.214
Slave2	10.10.10.215

2.3、配置JDK环境

Hadoop集群必须依赖JDK环境,所以这里我们首先需要配置好JDK环境,同样为了管理,我们建议服务器中的节点JDK安装环境均在相同路径下。

2.3.1、解压安装包

拷贝jdk文件jdk-6u25-linux-x64.bin到/usr/lib/java文件目录(该目录可自行定义)下,解压安装包,如果文件权限被限制,可通过如下命令进行赋权限操作:

chmod u+w jdk-6u25-linux-x64.bin

2.3.2、修改环境配置信息

vi /etc/profile

在最后加上:

export JAVA_HOME=/usr/lib/java/jdk1.6.0_25
export PATH=$PATH:$JAVA_HOME/bin 
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/rt.jar

通过注销或者以下命令使修改生效:

source /etc/profile

2.3.3、检查当前JDK版本信息

java -version

2.3.4、补充(可选)

如果查看当前的JDK版本不是刚才设置的JDK版本,则可以进行默认JDK版本设置操作:

sudo update-alternatives --install /usr/bin/java java /usr/lib/java/jdk1.6.0_25/bin/java 300   
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/java/jdk1.6.0_25/bin/javac 300   
sudo update-alternatives --config java(选择jdk1.6.0_25版本的序号就行)

2.4、安装SSH

Centos系统安装时默认可以选择安装SSH,ubuntu下可以通过如下命令进行安装(前提是必须联网):

sudo apt-get install ssh
sudo apt-get install rsync

2.5、新建用户

为了hadoop集群的安全与方便管理,我们要另外新建用户,并设置密码,命令如下:

sudo adduser hadoop
sudo passwd hadoop

上述命令中,第一行命令新建了一个user为hadoop的用户,第二行命令是为这个hadoop用户设置密码,同样最好服务器之间均保持一致。

2.6、配置集群之间SSH无密码登陆

集群环境的使用必须通过ssh无密码登陆来执行,本机登陆本机必须无密码登陆,主机与从机之间必须可以双向无密码登陆,从机与从机之间无限制。以本次为例,比如Master与Slave1之间的无密码登陆设置步骤如下:

(1)进入Master服务器,进行无密码自登陆设置

ssh hadoop@Master	//登陆Master
ssh-keygen  -t  rsa  -P  ''  -f  ~/.ssh/id_rsa
cat  ~/.ssh/id_rsa.pub  >>  ~/.ssh/authorized_keys	//生成密钥
chmod 700 ~/.ssh && chmod 600 ~/.ssh/*	//设置权限

如果不知道是否配置成功,可通过如下命令进行验证:

ssh localhost
如果上述命令不需要输入密码则表示配置成功。

进入Slave1服务器,进行无密码自登陆设置,操作同上,只需将对应的Master改为Slave1即可,此处省略。

(2)进入Master服务器,设置Master->Slave1的无密码登陆

ssh hadoop@Master	//登陆Master
cat ~/.ssh/id_rsa.pub | ssh hadoop@Slave1 'cat - >> ~/.ssh/authorized_keys'
ssh hadoop@Slave1	//若此处不需要输入密码则配置成功

(3)进入Slave1服务器,设置Slave1->Master的无密码登陆

ssh hadoop@Slave1	//登陆Slave1
cat ~/.ssh/id_rsa.pub | ssh hadoop@Master 'cat - >> ~/.ssh/authorized_keys'
ssh hadoop@Master	//若此处不需要输入密码则成功

以上便是Master与Slave1之间的双向无密码登陆配置。Master与Slave2之间的配置原理同上述基本一样,所以不再赘述。

3、Hadoop集群安装配置

3.1、修改hadoop配置文件

在centos系统下解压hadoop安装包hadoop-1.0.3.tar.gz,修改conf目录下的6个文件:

(1)core-site.xml
		fs.default.name
		hdfs://Master:9000
(2)hadoop-env.sh

在该文件中加上如下一行代码:

export JAVA_HOME=(你配置的jdk路径,比如:/usr/java/jdk1.6.0_25)

(3)hdfs-site.xml

	
		dfs.name.dir
		/home/hadoop/temp/hadoop
		dfs.data.dir
		/home/hadoop/temp/hadoop
		dfs.replication
		1
		dfs.support.append
		true

(4)mapred-site.xml

		mapred.job.tracker
		Master:9001
		mapred.acls.enabled
		false

(5)Masters

Master

(6)Slaves

Slave1
Slave2

3.2、同步安装包

将解压修改后的hadoop-1.0.3文件夹分别拷贝到Master、Slave1、Slave2的相同hadoop安装路径下。

3.3、启动Hadoop集群

进入Master的hadoop-1.0.3目录,执行以下操作:

bin/hadoop namenode -format	//格式化namenode,第一次启动服务前执行的操作,以后不需要执行
bin/start-all.sh	 //启动hadoop
jps	//用jps命令能看到除jps外有5个进程

至此,hadoop集群配置过程结束。可通过浏览器地址http://10.10.10.213:50070?查看节点启用状态验证配置是否成功。

4、Zookeeper集群安装配置

4.1、修改zookeeper配置文件zoo.cfg

在centos系统下解压zookeeper安装包zookeeper-3.4.3.tar.gz?,进入到conf目录,将zoo_sample.cfg拷贝一份命名为zoo.cfg(Zookeeper?在启动时会找这个文件作为默认配置文件),打开该文件进行修改为以下格式(注意权限问题,如果最后配置有问题请检查过程中权限是否正确)。

dataDir=/home/hadoop/temp/zookeeper/data
server.0=10.10.10.213:2888:3888
server.1=10.10.10.214:2888:3888
server.2=10.10.10.215:2888:3888

4.2、新建目录、新建并编辑myid文件

(本次配置myid文件放在/home/hadoop/temp/zookeeper/data目录下)

mkdir /home/hadoop/temp/zookeeper/data	//dataDir目录
vi /home/hadoop/temp/zookeeper/data/myid

注意myid文件中的内容为:Master中为0,Slave1中为1,Slave2中为2,分别与zoo.cfg中对应起来。

4.3、同步安装包

将解压修改后的zookeeper-3.4.3文件夹分别拷贝到Master、Slave1、Slave2的相同zookeeper安装路径下。注意:myid文件的内容不是一样的,各服务器中分别是对应zoo.cfg中的设置。

4.4、启动zookeeper

Zookeeper的启动与hadoop不一样,需要每个节点都执行,分别进入3个节点的zookeeper-3.4.3目录,启动zookeeper:

bin/zkServer.sh start
注意:此时如果报错先不理会,继续在另两台服务器中执行相同操作。

4.5、检查zookeeper是否配置成功

待3台服务器均启动后,如果过程正确的话zookeeper应该已经自动选好leader,进入每台服务器的zookeeper-3.4.3目录,执行以下操作查看zookeeper启动状态:

bin/zkServer.sh status

如果出现以下代码表示安装成功了。

[java] view plaincopy
JMX enabled by default  
Using config: /home/hadoop/zookeeper-3.4.3/bin/../conf/zoo.cfg  
Mode: follower	//或者有且只有一个leader

5、HBase集群安装配置

5.1、修改hbase配置文件

在centos系统下解压hadoop安装包hadoop-1.0.3.tar.gz,修改conf目录下的3个文件:

(1)hbase-env.sh

export JAVA_HOME=/usr/lib/java/jdk1.6.0_25	//JDK的安装目录
export HBASE_CLASSPATH=/home/hadoop/hadoop-1.0.3/conf	//hadoop的安装目录
export HBASE_MANAGES_ZK=true

(2)hbase-site.xml

		hbase.rootdir
		hdfs://Master:9000/hbase
		hbase.cluster.distributed
		true
		hbase.zookeeper.property.clientPort
		2181
		hbase.zookeeper.quorum
		Master
		hbase.zookeeper.property.dataDir
		/home/hadoop/temp/zookeeper
		dfs.support.append
		true

(3)regionservers

Slave1
Slave2

5.2、同步安装包

将解压修改后的hbase-0.94.1-security文件夹分别拷贝到Master、Slave1、Slave2的相同hbase安装路径下。

5.3、启动HBase

进入Master的hbase-0.94.1-security目录,执行以下操作:

bin/start-hbase.sh	//之后用jps查看是否所有进程都已启动

至此,hbase服务配置过程结束。可通过浏览器地址http://10.10.10.213:60010?查看hbase是否可用。

也可以执行以下命令,进入hbase?shell进行验证。

6、结语

关于hadoop、zookeeper、hbase的启动与关闭顺序:启动时hadoop和zookeeper随意先后,但是hbase必须最后启动,关闭时hbase必须首先关闭,然后随意先后关闭hadoop、zookeeper。否则,会出现异常。

关于各软件的安装包可以去官网下载,不同版本的安装配置可能会有少许的变动,而且版本搭配如果不一样的话也可能出现问题,有问题就针对性地去查,这样学习才有进步。

作者:jinnchang 发表于2013-5-8 16:29:30 原文链接

阅读:44 评论:0 查看评论

分布式集群环境hadoop、hbase、zookeeper搭建(全)

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool