Ambari系列(一):在离线环境中自动化安装Hadoop集群

来源:互联网 发布:几个程序员去吃饭 编辑:程序博客网 时间:2024/06/16 18:36

机器部署:

cluster-01 : yum server

cluster-02MySQL serverambari server

 

安装思路:

在生产环境中,应该是没有外网链接的环境,或者做了外网隔离,因此在离线环境下搭建集群很有价值。在内网集群中搭建yum服务器,安装ambari和集群,是一种比较好的解决思路。

 

安装步骤:

  1. 搭建Yum源服务器
  2. 安装MySQL服务
  3. 安装Ambari服务

 

安装过程:

(一)搭建Yum源服务器

 

1)安装http server

cluster-01上安装apaceh http服务。

检查是否已经安装apache http服务

[root@cluster-01 ~]$ which httpd

如果没有出现目录信息,则说明没有安装。

 

[root@cluster-01 ~]$ sudo yum install httpd

安装成功之后,apache工作目录默认在/var/www/html

配置

检查端口是否占用,apache http服务使用80端口

[root@cluster-01 ~]$ netstat -nltp | grep 80

如果有占用情况,安装完毕之后需要修改apache http服务的端口号:

[root@cluster-01 ~]$ sudo vi /etc/httpd/conf/httpd.conf

修改监听端口,Listen 80为其他端口。


 

启动

[root@cluster-01 ~]$ sudo service httpd start

可以在浏览器中查看http://cluster-01 看到apache server的一些页面信息,表示启动成功。

 

2)添加rpm包到repository

添加HDP 相关rpm

下载HDP2.2.0的包

http://public-repo-1.hortonworks.com/HDP/centos6/HDP-2.2.0.0-centos6-rpm.tar.gz

 

http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/centos6/HDP-UTILS-1.1.0.20-centos6.tar.gz

解压之后,会有HDPHDP-UTILS-1.1.0.17的目录生成。

下载ambari的包

此处我们使用自己编译好的

ambari-server-1.6.1.1.noarch.rpm

ambari-agent-1.6.1.1.noarch.rpm

 

注意:如果不使用己编译好的rpm包,也可以使用官网下载的

http://public-repo-1.hortonworks.com/ambari/centos6/ambari-1.6.1-centos6.tar.gz

 

 

将这些包复制到/var/www/html/centos-6/

[root@cluster-01 html]# ll /var/www/html/


 

 

说明:

ambari目录:包含ambari-serverambari-agentambari-log4jrpm

HDP目录:包含Hadoop的生态圈的组件,比如hdfsHiveHbasemahout

HDP-UTILS-1.1.0.17目录:包含HDP平台所包含的工具组件等,比如nagiosgangliapuppet

 

3)创建Yum repository

在本地安装createrepo软件。

检查是否已经安装:

[root@cluster-01 ~]$ which createrepo

如果出现在具体的目录,则说明已经安装

 

安装:

[root@cluster-01 ~]$ sudo yum install createrepo

创建repository

[root@cluster-01 ~]$ sudo createrepo /var/www/html/centos-6/

修改客户端Yum源配置

 

ambari安装的节点做如下操作:

/etc/yum.repos.d下的所有repo做备份,然后删除,创建一个ambari.repo,写入以下内容:

[root@cluster-01 ~]# vi /etc/yum.repos.d/ambari.repo

 

 

[ambari-1.x]

name=Ambari 1.x

baseurl=http://public-repo-1.hortonworks.com/ambari/centos6/1.x/GA

gpgcheck=1

gpgkey=http://public-repo-1.hortonworks.com/ambari/centos6/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins

enabled=0   (注意,不启用)

priority=1

 

[Updates-ambari-1.6.1]

name=ambari-1.6.1 - Updates

baseurl=http://cluster-01/ambari/centos6/1.x/updates/1.6.1

enabled=1

priority=1

 

 

注意:

baseurl=http://<your server IP>/ambari/centos6/1.x/updates/1.6.1

ambari/centos6/1.x/updates/1.6.1yum repository地址相对应。可以在浏览器中,

查看这个地址http://cluster-01/ambari/centos6/1.x/updates/1.6.1

 

清除缓存:

[root@cluster-01 ~]$ sudo yum clean all

测试下:

[root@cluster-01 ~]$ sudo yum repolist

如果出现仓库的名称等输出,则说明配置成功。


如图所示,出现对应的repository即可。

 

(二)安装mysql服务

1)安装

通过yum安装mysql

[root@cluster-02 ~]$ sudo yum install mysql-server

启动mysql服务

[root@cluster-02 ~]$ sudo service mysqld start

 

安装MySQL JDBC Connector

[root@cluster-02 root]$ sudo yum install mysql-connector-Java

 

2)配置

1)启动mysql服务

[root@cluster-02 ~]# service mysqld start

 

2)为root用户设置新密码等初始化工作

[root@cluster-01 ~]$ sudo /usr/bin/mysql_secure_installation


 

3)为ambari创建数据库,配置相应用户和权限

 

[root@cluster-02 ~]# mysql -u root –p

 

mysql> create database ambari;

Query OK, 1 row affected (0.00 sec)

 

mysql> use ambari;

Database changed

 

mysql>

CREATE USER 'ambari'@'%' IDENTIFIED BY 'ambari';

GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'%';

CREATE USER 'ambari'@'localhost' IDENTIFIED BY 'ambari';

GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'localhost';

CREATE USER 'ambari'@'cluster-02' IDENTIFIED BY 'ambari';

GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'cluster-02';

FLUSH PRIVILEGES;

 

3)启动

mysql设置为开机自启动

[root@cluster-05 root]$ sudo chkconfig mysqld on

[root@cluster-05 root]$ sudo chkconfig –list

mysqld             0:off      1:off      2:on      3:on      4:on      5:on      6:off

 

 

(三)安装Ambari-server

1)安装

yum安装,所有依赖yum自动下载,只需要执行命令即可。

[root@cluster-02 root]# yum install ambari-server

出现Complete! 则可

 

2)配置

[root@cluster-02 root]# ambari-server setup

 

Daemon运行的账号设置

Customize user account for ambari-server daemon [y/n] (n)?

输入:y

 

Enter user account for ambari-server daemon (root):

输入:root

 

检查防火墙是否关闭

Adjusting ambari-server permissions and ownership...

Checking firewall...

WARNING: iptables is running. Confirm the necessary Ambari ports are accessible. Refer to the Ambari documentation for more details on ports.

OK to continue [y/n] (y)?

输入:y

 

检查JDK

Checking JDK...

[1] - Oracle JDK 1.7 + Java Cryptography Extension (JCE) Policy Files 7

[2] - oracle JDK 1.6 + java Cryptography Extension (JCE) Policy Files 6

[3] - Custom JDK

==============================================================================

Enter choice (1):

输入:3

输入:/usr/local/jdk1.7.0_51/  jdkhome,根据情况输入

 

Choose one of the following options:

[1] - PostgreSQL (Embedded)

[2] - Oracle

[3] - MySQL

[4] - PostgreSQL

==============================================================================

Enter choice (1):

输入:3

 

Hostname (localhost):

Port (3306):

Database Name (ambari):

Username (ambari):

输入:(什么也不输入,直接“回车”)

 

Enter Database Password (cluster):

Re-enter password:

输入:ambari

 

WARNING: Before starting Ambari Server, you must run the following DDL against the database to create the schema: /var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql

Proceed with configuring remote database connection properties [y/n] (y)?

输入:y

 

注意,此刻需要切换到mysql中执行相应脚本操作。

需要登录到mysql数据库,执行以下脚本Ambari-DDL-MySQL-CREATE.sql

[root@cluster-02 ~]# mysql -u root –p

 

mysql> use ambari;

Database changed

 

mysql> source /var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sq

执行脚本,成功。

 

验证脚本是否初始化成功,出现以下table列表。

mysql> show tables;

+-------------------------------+

| Tables_in_ambari              |

+-------------------------------+

| ClusterHostMapping            |

| QRTZ_BLOB_TRIGGERS            |

| QRTZ_CALENDARS                |

| QRTZ_CRON_TRIGGERS            |

| QRTZ_FIRED_TRIGGERS           |

| QRTZ_JOB_DETAILS              |

| QRTZ_LOCKS                    |

 

 

3)启动

[root@cluster-02 root]# ambari-server start

Using Python  /usr/bin/python2.6

Starting ambari-server

Ambari Server running with 'root' privileges.

Organizing resource files at /var/lib/ambari-server/resources...

Server PID at: /var/run/ambari-server/ambari-server.pid

Server out at: /var/log/ambari-server/ambari-server.out

Server log at: /var/log/ambari-server/ambari-server.log

Waiting for server start....................

Ambari Server 'start' completed successfully.

启动成功。

登录 http://<Your Server IP>:8080


 

 

 

四、磁盘扩容

问题引入:后续进行MR Job执行时,会报类似“磁盘空间不够”的错误,原因是Ambari安装所在目录的磁盘容量不够导致。

解决方案:由于Ambari安装后,会创建一个LVM的逻辑卷,供Hadoop运行产生的临时文件存储用,如下:

wps9ED7.tmp

所以,我们只需要对vg_hadoop01进行扩容。操作如下:

1) 1表示第一块分区的信息,该分区已经被Hadoop占满;2表示第二块分区的信息,也就是我们需要将它扩容到vg_hadoop01上的分区。如下:

wps9EE8.tmp

2) 现将/dev/sdb5分区块(注意这里Id必须是8e,System必须是Linux LVM)分配给vg_hadoop01.

① 8e和Linux LVM的设置命令:

fdisk /dev/sdb
,接着按m,根据提示设置。

wps9EE9.tmp

② 输入命令:partprobe,让分区表生效。

wps9EEA.tmp

③ 由于LVM所在的文件类型是ext4,所以新的分区必须格式化为ext4.

wps9EFB.tmp

格式化命令:

mkfs –t ext4 /dev/sdb5
.

④ 创建PV(物理卷),命令:

pvcreate /dev/sdb5
,利用:pvdisplay查看:

wps9EFC.tmp

⑤ 扩容LVM,命令:

vgextend vg_hadoop01 /dev/sdb5
,利用:vgdisplay查看:

wps9EFD.tmp

⑥ 将LVM中的容量扩展到LV(逻辑卷),命令:

lvextend –L 100G /dev/vg_hadoop01/lv_root
,将分区/dev/vg_hadoop01/lv_root的容量扩充到100G.利用lvdisplay查看:

wps9F0D.tmp

3) 执行该重设大小,对于当前正在使用的/dev/vg_hadoop01/lv_root有效.命令:

resize2fs /dev/vg_hadoop01/lv_root
,查看扩容后的挂载情况:df -lhT.

wps9F0E.tmp

参考资料:

Ambari安装文档

https://cwiki.apache.org/confluence/display/AMBARI/Installation+Guide+for+Ambari+1.6.1

 

Hortonworks公司(Ambari发挥到极致)

http://zh.hortonworks.com

原创粉丝点击