一、配置说明
1. 硬件环境
2. 软件环境
二、修改主机名和hosts文件
1. 修改主机名(三台主机都执行)
-
vim /etc/hostname # 该命令需要重启后生效
-
# 还有另外一种方式,执行该命令后立即生效,只不过需要重启Xshell连接
-
hostnamectl set-hostname node1.ambari.com
2. 修改hosts文件
-
vim /etc/hosts
注:主机名修改后需要重启机器才可彻底生效。如果用户不想重启,可使用命令 hostnamectlset-hostname node1.ambari.com来修改主机名,可使用命令 hostname来检验主机名是否修改成功。这种修改方式只是暂时的,待机器重启后就恢复原样 localhost了。
三、关闭防火墙和selinux
1. 防火墙设置
-
# 查看防火墙状态
-
systemctl status firewalld
-
# 查看开机是否启动防火墙服务
-
systemctl is-enabled firewalld
-
# 关闭防火墙
-
systemctl stop firewalld
-
systemctl disable firewalld
-
# 再次查看防火墙状态和开机防火墙是否启动
-
systemctl status firewalld
-
systemctl is-enabled firewalld
2. 禁用selinux
-
# 永久性关闭selinux(重启服务器生效)
-
sed -i 's/SELINUX=enforcing/SELINUX =disabled/' /etc/selinux/config
-
# 临时关闭selinux(立即生效,重启服务器失效)
-
setenforce 0
-
# 查看selinux状态
-
getenforce
-
# disabled为永久关闭,permissive为临时关闭,enforcing为开启
四、免密登陆
各个主机均执行以下操作:
-
## 生成密钥对
-
ssh-keygen -t rsa ## 一路回车即可
-
## 进入.ssh目录,如果目录不存在则创建
-
cd ~/.ssh
-
## 将公钥导入至authorized_keys
-
cat id_rsa.pub >> authorized_keys
-
## 修改文件权限
-
chmod 700 ~/.ssh
-
chmod 600 authorized_keys
在node1.ambari.com上执行:
-
## 配置主从互相免密登陆
-
[root@node1 ~]# cat ~/.ssh/id_rsa.pub | ssh root@node2.ambari.com 'cat - >> ~/.ssh/authorized_keys'
-
[root@node1 ~]# cat ~/.ssh/id_rsa.pub | ssh root@node3.ambari.com 'cat - >> ~/.ssh/authorized_keys'
-
ssh node2.ambari.com
-
ssh node3.ambari.com # 验证主机点是否可以免密登陆从节点,执行exit命令退出即可。
备注:要想实现多主机互相免密,可参考文章:Linux多台主机互相免密登陆
五、安装JDK
下载链接: https://pan.baidu.com/s/1rlqZejpZZqio9RPzgnGOEg 提取码: j47n ;内有 jdk-8u151-linux-x64.tar.gz和 mysql-connector-java.jar文件。
-
mkdir /usr/java;将下载的压缩包上传到java文件夹内
-
解压压缩包:tar zxvf jdk-8u151-linux-x64.tar.gz
-
配置jdk环境变量:
-
# 编辑/etc/profile,文末插入以下内容:
-
# set java
-
export JAVA_HOME=/usr/java/jdk1.8.0_151
-
export PATH=$JAVA_HOME/bin:$PATH
-
使环境变量生效:source /etc/profile
-
安装验证:java -version
六、安装mysql
mysql5.7 centos7:
https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
mysql5.7 centos6:
https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
mysql5.6 centos7:
https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
mysql5.6 centos6:
https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
1. 检查本地资源库中是否有mysql的rpm包
-
rpm -qa | grep mysql
-
# 删除相关rpm包
-
rpm -ev <rpm包名> --nodeps
2. 搭建mysql5.7的yum源
-
# 下载mysql5.7的rpm包
-
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
-
# 安装第一步下载的rpm文件,安装成功后/etc/yum.repos.d/目录下会增加两个文件
-
yum -y install mysql57-community-release-el7-11.noarch.rpm
-
# 查看mysql57的安装源是否可用,如不可用请自行修改配置文件(/etc/yum.repos.d/mysql-community.repo)使mysql57下面的enable=1
-
# 若有mysql其它版本的安装源可用,也请自行修改配置文件使其enable=0
-
yum repolist enabled | grep mysql
3. 安装mysql
-
yum install mysql-community-server
4. 设置mysql
-
# 启动mysql服务
-
service mysqld start
-
# 查看root密码
-
grep "password" /var/log/mysqld.log
-
# 登陆mysql
-
mysql -u root -p
-
Enter password:
-
# 为了可以设置简单密码
-
set global validate_password_policy=0;
-
set global validate_password_length=4;
-
# 立即修改密码,执行其他操作报错:
-
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
-
# 我们创建密码为root123
5. 新增ambari用户并增加权限
-
mysql -uroot -proot123
-
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'@'node1.ambari.com' IDENTIFIED BY 'ambari';
-
GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'node1.ambari.com'; //本地主机名
-
FLUSH PRIVILEGES;
注:删除用户命令:
-
Delete FROM user Where User='your_user' and Host='your_host';
-
FLUSH PRIVILEGES;
6. 使用ambari用户登陆并创建数据库
-
mysql -uambari -pambari
-
CREATE DATABASE ambari;
-
exit;
七、设置时钟同步
自己写了一个脚本,前提条件是获取 /etc/hosts文件内的主机ip
脚本如下:
-
#!/usr/bin/env bash
-
host_list=$(sed -n '3,$p' /etc/hosts | awk '{print $1}')
-
master_hostip=$(sed -n 3p /etc/hosts | awk '{print $1}')
-
ips_no_host=$(sed -n '4,$p' /etc/hosts | awk '{print $1}')
-
-
# 遍历所有节点
-
for host in $host_list
-
do
-
# 设置时区
-
ssh $host ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
-
# 同步硬件时间
-
ssh $host hwclock --systohc
-
# 开机自启动
-
ssh $host echo service ntpd restart >> /etc/rc.d/rc.local
-
ssh $host echo "hwclock --systohc" >> /etc/rc.d/rc.local
-
ssh $host chmod +x /etc/rc.d/rc.local
-
# 安装ntp服务
-
ssh $host yum install -y -q ntp
-
done
-
# 主节点操作,修改配置文件
-
sed -i -e '21 s/^/# /' -i -e '22 s/^/# /' -i -e '23 s/^/# /' -i -e '24 s/^/# /' /etc/ntp.conf
-
echo server 127.127.1.0 >> /etc/ntp.conf
-
echo fudge 127.127.1.0 stratum 10 >> /etc/ntp.conf
-
service ntpd start
-
# 从节点操作,开启ntp服务,使用ntpdate命令进行时钟同步
-
for slave in $ips_no_host
-
do
-
ssh $slave service ntpd start
-
ssh $slave ntpdate -u $master_hostip
-
done
八、搭建yum本地源
1. 安装httpd和wget服务
-
# 安装httpd
-
yum -y install httpd.x86_64
-
systemctl enable httpd.service
-
systemctl start httpd.service
-
# 安装wget
-
yum -y install wget
2. 下载ambari和hdp包
-
# 将tar包下载到/var/www/html
-
cd /var/www/html
-
wget http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.7.1.0/ambari-2.7.1.0-centos7.tar.gz
-
wget http://public-repo-1.hortonworks.com/HDP/centos7/3.x/updates/3.0.1.0/HDP-3.0.1.0-centos7-rpm.tar.gz
-
wget http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.22/repos/centos7/HDP-UTILS-1.1.0.22-centos7.tar.gz
-
# 解压上面三个包
-
tar zxvf ambari-2.7.1.0-centos7.tar.gz
-
tar zxvf HDP-3.0.1.0-centos7-rpm.tar.gz
-
tar zxvf HDP-UTILS-1.1.0.22-centos7.tar.gz
3. 新建repo文件
-
新建ambari.repo文件
-
[ambari]
-
name=ambari
-
baseurl=http://node1.ambari.com/CentOS-7/ambari-2.6.0.0
-
enabled=1
-
gpgcheck=0
-
新建HDP.repo文件
-
[HDP]
-
name=HDP
-
baseurl=http://node1.ambari.com/CentOS-7/HDP
-
path=/
-
enabled=1
-
gpgcheck=0
-
新建HDP-UTILS.repo文件
-
[HDP-UTILS]
-
name=HDP-UTILS
-
baseurl=http://liuyzh1.xdata/CentOS-7/HDP-UTILS
-
path=/
-
enabled=1
-
gpgcheck=0
将以上文件放入 /etc/yum.repos.d/目录下。
九、在主节点安装ambari-server
1. 安装
-
yum -y install ambari-server
2. 将mysql-connector-java.jar拷贝到/usr/share/java目录下
3. 修改配置文件
-
echo server.jdbc.driver.path=/usr/share/java/mysql-connector-java.jar >> /etc/ambari-server/conf/ambari.properties
4. 安装ambari-server
-
ambari-server setup
5. 初始化数据库
-
mysql -uambari -pambari
-
use ambari;
-
source /var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql
6. 启动ambari-server
-
ambari-server start
登陆浏览器访问: http://192.168.162.41:8080/,利用界面部署集群。
默认登陆账号/密码为:admin/admin。