CDH6.2离线安装
作者:互联网
# CDH6.2离线安装
## 1.概述
本人最近对大数据进行了部分研究,绝大部分都是将各种组件先讲一遍,然后再讲集成工具。但是这种讲述的方式并不太友好。在我们系统组经过沟通,现在采用的组件时CDH,这个工具用起来比较方便。下面对其进行安装部署。本文采用4个节点,其中一个节点是manager节点。
CDH,全称Cloudera's Distribution, including Apache Hadoop。是Hadoop众多分支中对应中的一种,由Cloudera维护,基于稳定版本的Apache Hadoop构建,提供了Hadoop的核心(可扩展存储、分布式计算),最为重要的是提供基于web的用户界面。
CDH的优点:版本划分清晰,更新速度快,支持Kerberos安全认证,支持多种安装方式(如Yum、rpm等)。
CDH分为Cloudera Manager管理平台和CDH parcel(parcel包含各种组件的安装包)。这里采用CDH6.2.0。
下面是用到的安装包:
链接: https://pan.baidu.com/s/1Dm5Elf9uQqn14BUbgU3AFQ 提取码: mws3
## 2.安装步骤
### 2.1 环境准备
#### 2.1.1. 准备虚拟机(根据自己的系统资源分配虚拟机资源)
![image.png](http://www.icode9.com/i/li/?n=2&i=images/20210630/1625060450874160.png?,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
### 2.1.2. 静态IP设置(每个节点)
vim /etc/sysconfig/network-scripts/ifcfg-ens37
service network restart 重启网络生效
yum install -y net-tools ifconfig查看设置
### 2.1.3 编辑/etc/hosts文件(每个节点)
```
#cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.10.161 hadoop01
10.10.10.162 hadoop02
10.10.10.163 hadoop03
10.10.10.160 manager
```
### 2.1.4. 关闭防火墙、禁止防火墙开机自启(每个节点)
systemctl stop firewalld 关闭防火墙
systemctl disable firewalld 禁止防火墙开机自启
vim /etc/selinux/config —> SELINUX=disabled (修改)
### 2.1.5. ssh无密码登录
采用配置脚本,在manager节点上执行,我们设置root密码是redhat
脚本如下:
```
[root@manager ~]# cat auto_auth.sh
DEST_USER=$1
PASSWORD=$2
HOSTS_FILE=$3
if [ $# -ne 3 ]; then
echo "Usage:"
echo "$0 remoteUser remotePassword hostsFile"
exit 1
fi
SSH_DIR=~/.ssh
SCRIPT_PREFIX=./tmp
echo ===========================
# 1. prepare directory .ssh
mkdir $SSH_DIR
chmod 700 $SSH_DIR
# 2. generat ssh key
TMP_SCRIPT=$SCRIPT_PREFIX.sh
echo "#!/usr/bin/expect">$TMP_SCRIPT
echo "spawn ssh-keygen -b 1024 -t rsa">>$TMP_SCRIPT
echo "expect *key*">>$TMP_SCRIPT
echo "send \r">>$TMP_SCRIPT
if [ -f $SSH_DIR/id_rsa ]; then
echo "expect *verwrite*">>$TMP_SCRIPT
echo "send y\r">>$TMP_SCRIPT
fi
echo "expect *passphrase*">>$TMP_SCRIPT
echo "send \r">>$TMP_SCRIPT
echo "expect *again:">>$TMP_SCRIPT
echo "send \r">>$TMP_SCRIPT
echo "interact">>$TMP_SCRIPT
chmod +x $TMP_SCRIPT
/usr/bin/expect $TMP_SCRIPT
rm $TMP_SCRIPT
# 3. generat file authorized_keys
cat $SSH_DIR/id_rsa.pub>>$SSH_DIR/authorized_keys
# 4. chmod 600 for file authorized_keys
chmod 600 $SSH_DIR/authorized_keys
echo ===========================
# 5. copy all files to other hosts
for ip in $(cat $HOSTS_FILE)
do
if [ "x$ip" != "x" ]; then
echo -------------------------
TMP_SCRIPT=${SCRIPT_PREFIX}.$ip.sh
# check known_hosts
val=`ssh-keygen -F $ip`
if [ "x$val" == "x" ]; then
echo "$ip not in $SSH_DIR/known_hosts, need to add"
val=`ssh-keyscan $ip 2>/dev/null`
if [ "x$val" == "x" ]; then
echo "ssh-keyscan $ip failed!"
else
echo $val>>$SSH_DIR/known_hosts
fi
fi
echo "copy $SSH_DIR to $ip"
echo "#!/usr/bin/expect">$TMP_SCRIPT
echo "spawn scp -r $SSH_DIR $DEST_USER@$ip:~/">>$TMP_SCRIPT
echo "expect *assword*">>$TMP_SCRIPT
echo "send $PASSWORD\r">>$TMP_SCRIPT
echo "interact">>$TMP_SCRIPT
chmod +x $TMP_SCRIPT
#echo "/usr/bin/expect $TMP_SCRIPT" >$TMP_SCRIPT.do
#sh $TMP_SCRIPT.do&
/usr/bin/expect $TMP_SCRIPT
rm $TMP_SCRIPT
echo "copy done."
fi
done
echo done.
[root@manager ~]# cat host
manager
hadoop01
hadoop02
hadoop03
执行以下命令就可以配置互信:
[root@manager ~]# sh auto_auth.sh root redhat host
验证是否配置互信成功:(所有节点)
#ssh hadoop01 date;ssh hadoop02 date;ssh hadoop03 date; ssh manager date;
```
### 2.1.6. 配置NTP服务(所有节点)
修改时区(改为中国标准时区)
```
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
```
安装ntp
```
yum -y install ntp
ntp主机配置 vim /etc/ntp.conf
注意,生产环境都有自己的NTP服务器,本次为了简单,采用网络的NTP服务器。
```
manager节点:
```
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 10.10.10.101 ##需要注销掉的原有配置
server ntp.aliyun.com ##添加的新的配置
```
其他节点:
```
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 10.10.10.101 #注销掉的原有配置
server manager # 指向现在配置的manager服务器
```
配置完毕后执行如下操作:
```
重新启动 ntp 服务:service ntpd restart
设置开机自启:systemctl enable ntpd.service
ntpdc -c loopinfo #查看与时间同步服务器的时间偏差
ntpq -p #查看当前同步的时间服务器
ntpstat #查看状态
配置成功状态(服务开启后前面出现*说明成功):
```
### 2.1.7. 修改Linux swappiness参数(所有节点)
为了避免服务器使用swap功能而影响服务器性能,一般都会把vm.swappiness修改为0(cloudera建议10以下)
```
echo 0> /proc/sys/vm/swappiness
编辑vim /etc/sysctl.conf
在最后添加 vm.swappiness=0
上述方法rhel6有效,rhel7.2中:tuned服务会动态调整系统参数
查找tuned中配置,直接修改配置
cd /usr/lib/tuned/
grep “vm.swappiness” * -R 查询出后依次修改
[root@hadoop01 ~]# cd /usr/lib/tuned
[root@hadoop01 tuned]# grep "vm.swappiness" * -R
latency-performance/tuned.conf:vm.swappiness=10
throughput-performance/tuned.conf:vm.swappiness=10
virtual-guest/tuned.conf:vm.swappiness = 30
[root@hadoop01 tuned]# vim virtual-guest/tuned.conf
[root@hadoop01 tuned]# grep "vm.swappiness" * -R
latency-performance/tuned.conf:vm.swappiness=10
throughput-performance/tuned.conf:vm.swappiness=10
virtual-guest/tuned.conf:vm.swappiness = 0
[root@hadoop01 tuned]#
```
### 2.1.8. 禁用透明页(所有节点)
```
echo never > /sys/kernel/mm/transparent_hugepage/defrag
echo never > /sys/kernel/mm/transparent_hugepage/enabled
永久生效 在/etc/rc.local 添加上面命令
给可执行权限
chmod +x /etc/rc.local
```
### 2.1.9. JDK安装(所有节点)
```
rpm -qa | grep java # 查询已安装的java
yum remove java* # 卸载
rpm -ivh oracle-j2sdk1.8-1.8.0+update181-1.x86_64.rpm
vi /etc/profile 末尾添加
export JAVA_HOME=/usr/java/jdk1.8.0_181-cloudera
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin
然后执行
#source /etc/profile
java -version验证
[root@manager ~]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
```
### 2.1.10. 创建/usr/share/java目录,将mysql-jdbc包放过去(所有节点)
```
mkdir -p /usr/share/java
上传mysql-connector-java-5.1.34.jar 到 /usr/share/java/
mysql-connector-java-5.1.34.jar 一定要命名为mysql-connector-java.jar
```
### 2.1.11. 为保证防火墙、虚拟机参数修改后生效,各节点机器需要重启 reboot
### 2.1.12. Mysql安装(在manager上安装)
卸载原生的mariadb,安装mysql:
```
rpm -qa|grep mariadb
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
cd /opt/mysql/
tar -xvf ./mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar
```
由于是测试,所以简略安装安装mysql:
```
# tar -xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
# rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
# rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
# rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
# rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
# rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
# rpm -ivh mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm
```
mysql配置如下:
```
mysqld --initialize --user=mysql # 初始化mysql使mysql目录的拥有者为mysql用户
cat /var/log/mysqld.log # 最后一行将会有随机生成的密码
systemctl start mysqld.service # 设置mysql服务自启
mysql -uroot –p 如果不能登陆
systemctl restart mysqld
#登录并修改mysql的管理者密码
$>mysql -u root
mysql>use mysql;
mysql>set password = PASSWORD('root');
mysql>exit;
```
创建库,为后续安装服务做准备:
```
create database cmserver default charset utf8 collate utf8_general_ci;
grant all on cmserver.* to 'cmserveruser'@'%' identified by 'root';
create database metastore default charset utf8 collate utf8_general_ci;
grant all on metastore.* to 'hiveuser'@'%' identified by 'root';
create database amon default charset utf8 collate utf8_general_ci;
grant all on amon.* to 'amonuser'@'%' identified by 'root';
create database rman default charset utf8 collate utf8_general_ci;
grant all on rman.* to 'rmanuser'@'%' identified by 'root';
create database oozie default charset utf8 collate utf8_general_ci;
grant all on oozie.* to 'oozieuser'@'%' identified by 'root';
create database hue default charset utf8 collate utf8_general_ci;
grant all on hue.* to 'hueuser'@'%' identified by 'root';
```
### 2.1.13. 安装Httpd服务(manager)
安装httpd 配置yum源:
```
yum install httpd
systemctl start httpd
systemctl enable httpd.service 设置httpd服务开机自启
```
### 2.1.14. 配置Cloudera Manager包yum源(manager节点)
```
mkdir -p /var/www/html/cloudera-repos/
将下载的cm包文件移到此目录下:
mv cm6 /var/www/html/cloudera-repos/
cd /var/www/html/cloudera-repos/cm6/
创建repodata: createrepo .
注意:createrepo . 执行了以后,就会生成一个repodata目录
[root@manager cm6]# ll
total 1368756
-rw-r--r-- 1 root root 14041 Jun 30 00:23 allkeys.asc
-rw-r--r-- 1 root root 10215488 Jun 30 00:23 cloudera-manager-agent-6.2.0-968826.el7.x86_64.rpm
-rw-r--r-- 1 root root 1187380436 Jun 30 00:32 cloudera-manager-daemons-6.2.0-968826.el7.x86_64.rpm
-rw-r--r-- 1 root root 9984 Jun 30 00:23 cloudera-manager-server-6.2.0-968826.el7.x86_64.rpm
-rw-r--r-- 1 root root 10992 Jun 30 00:23 cloudera-manager-server-db-2-6.2.0-968826.el7.x86_64.rpm
-rw-r--r-- 1 root root 4763392 Jun 30 00:23 docker-engine-1.7.1-1.el6.x86_64.rpm
-rw-r--r-- 1 root root 14200108 Jun 30 00:23 enterprise-debuginfo-6.2.0-968826.el7.x86_64.rpm
-rw-r--r-- 1 root root 184988341 Jun 30 00:28 oracle-j2sdk1.8-1.8.0+update181-1.x86_64.rpm
drwxr-xr-x 2 root root 4096 Jun 30 04:36 repodata
-rw-r--r-- 1 root root 1718 Jun 30 00:23 RPM-GPG-KEY-cloudera
[root@manager cm6]# pwd
/var/www/html/cloudera-repos/cm6
配置yum文件,这个地方我出现了好几次问题, 贴进去就好。这个yum配置文件会在后端网页上识别出来。一定要配置好。
[root@manager cm6]# cat /etc/yum.repos.d/cloudera-manager.repo
[cloudera-manager]
name = Cloudera Manager, Version
baseurl = http://manager/cloudera-repos/cm6/
gpgcheck = 1
然后执行:
yum clean all
yum makecache
注意,我之前也配置了本地yum源,还有网络yum源端,因为安装过程中需要安装一些其他的包。
可以提前在所有节点上安装以下包。
yum install -y redhat-lsb httpd mod_ssl openssl-devel python-psycopg2 MySQL-python libpq.so
```
### 2.1.15.导入GPG key(如果没有这步操作,很可能cloudera服务安装失败)manager节点
```
rpm --import http://manager/cloudera-repos/cm6/RPM-GPG-KEY-cloudera
```
### 2.1.16. 安装 Cloudera Manager(manager节点)
```
sudo yum install cloudera-manager-daemons cloudera-manager-agent cloudera-manager-server
注意:第一次安装的时候由于yum没有配置好,导致yum install无法安装成功,我进行了手工安装
手工安装的话,需要先安装
yum install -y redhat-lsb httpd mod_ssl openssl-devel python-psycopg2 MySQL-python libpq.so
然后安装
rpm -ivh cloudera-manager-daemons-6.2.0-968826.el7.x86_64.rpm
rpm -ivh cloudera-manager-server-6.2.0-968826.el7.x86_64.rpm
rpm -ivh cloudera-manager-agent-6.2.0-968826.el7.x86_64.rpm
安装完CM后/opt/ 下会出现cloudera目录
mv /opt/parcels/* /opt/cloudera/parcel-repo # 将parcel包移动到指定位置
在/opt/cloudera/parcel-repo执行以下命令:
sha1sum CDH-6.2.0-1.cdh6.2.0.p0.967373-el7.parcel | awk '{ print $1 }' > CDH-6.2.0-1.cdh6.2.0.p0.967373-el7.parcel.sha
执行初始化脚本:
/opt/cloudera/cm/schema/scm_prepare_database.sh mysql cmserver cmserveruser password
注意password这个是之前设置的,以下是执行的命令。
#/opt/cloudera/cm/schema/scm_prepare_database.sh mysql cmserver cmserveruser root
#service cloudera-scm-server start
打开server服务:
service cloudera-scm-server start
静候几分钟,打开http://10.10.10.160:7180
```
## 2.2 其他服务安装
### 2.2.1 登录cm WEB界面
```
http://主机ip:7180/cmf/login 访问CM
用户名admin
密码admin
遇到问题:7180服务没有启动
解决方法:
netstat -an |grep 7180
service cloudera-scm-server status
查看失败原因
```
### 2.2.2 具体安装步骤
注意在安装的过程中都是图形界面安装,yum源必须要安装好,否则添加node的时候无法安装rpm包。
#### WELCOME
```
默认安装,下一步
```
#### Accept License
```
默认安装,下一步
```
#### Select Edition
```
选择中间试用,下一步
```
#### Welcome (Add Cluster - Installation)
```
默认安装,下一步
```
#### Specify Hosts
```
主机是自己规划安装agent的主机
我添加了
hadoop01,hadoop02,hadoop03
就搜搜到了三台机器
```
![image.png](http://www.icode9.com/i/li/?n=2&i=images/20210630/1625060733906461.png?,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
#### Select Repository
```
默认安装,下一步,这里比较容易出现问题,如果yum没有配置好。所以前期步骤一定要配置好。
```
![image.png](http://www.icode9.com/i/li/?n=2&i=images/20210630/1625060863842459.png?,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
#### JDK 安装选项
```
默认安装,下一步
```
#### Enter Login Credentials
```
密码我三台机器的root密码是redhat
```
#### Install Agents
```
最到考验网速的时候了,该页面使用js进行刷新,千万别手动刷新,手动刷新的话安装列表中之前已经功成的会消失,未成功的显示,未成功即使安装成功了,cm会管理不到之前已经成功但刷新后未显示的主机,在安装集群时只能选择本次显示的(原因未知)。网速过慢的话安装会失败,一定要耐心等待,别做无关操作。
```
#### Install Parcels
```
等待中,时间较长
```
![image.png](http://www.icode9.com/i/li/?n=2&i=images/20210630/1625060919435098.png?,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
#### Inspect Hosts
```
![image.png](http://www.icode9.com/i/li/?n=2&i=images/20210630/1625060950892873.png?,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
等待时间较长,执行完毕后,就完成了。
```
## 2.3 大数据组件安装
#### Select Services
```
下一步
```
#### 自定义角色分配
```
下一步
```
#### 数据库设置
```
这个要选择manager
然后添加mysql设置的数据库,用户密码
```
#### 审核更改
```
默认
```
#### 命令详细信息
```
下一步
```
#### summary
```
完成安装
```
这样就可以登录界面进去,注意在配置的过程中,出现了ntp的问题,注意ntp一定要配置好。
第一次进入后,许多服务标红,查看后是agent与cm失去连接。
#ntpstat(所有节点)
只有cm启动,其余莫名停止。
#systemctl start ntpd(停止节点)
#ntpdate -u cdh1(ntp服务端)
在失去的节点 执行
service cloudera-scm-agent restart(停止节点)
重启 正常启动不报错
注
service cloudera-scm-agent status(查看 agent 状态)
【参考资料】
https://www.cnblogs.com/swordfall/p/10816797.html
https://blog.csdn.net/wolf_333/article/details/89071203
http://www.cnblogs.com/mylovelulu/p/10384732.html
https://blog.csdn.net/qq_40127822/article/details/84441869
https://www.cnblogs.com/raphael5200/p/5293960.html
https://www.waitig.com/%E5%AF%B9cloudera-hadoop%E5%A4%9A%E4%B8%80%E4%BA%9B%E4%BA%86%E8%A7%A3.html cdh切换日志目录
https://www.520mwx.com/view/46525 cdh服务器磁盘划分
标签:cloudera,CDH6.2,离线,echo,manager,rpm,mysql,root,安装 来源: https://blog.51cto.com/lishiyan/2961730