环境及软件说明
环境说明
本人PC虚拟机VM10,里面安装了3台CentOS7.4 .集群环境规划如下:
CPU                      IP                          主机名               角色                         内存
2核心2线程          192.168.1.31         cdh1                CM server,agent      8G
2核心2线程          192.168.1.32         cdh2                agent                        2G
2核心2线程          192.168.1.33         cdh3                agent                        2G

我的电脑16G内存,只能上面这样规划了,最后CDH是能安装成功的,只不过没法用,资源太少了。

所需软件及说明
1:JDK1.8   
2:Cloudera Manager     cloudera-manager-centos7-cm5.14.0_x86_64.tar.gz      下载地址: https://archive.cloudera.com/cm5/cm/5/
3:CDH    CDH-5.14.4-1.cdh5.14.4.p0.3-el7.parcel.sha1,CDH-5.14.4-1.cdh5.14.4.p0.3-el7.parcel, manifest.json                                    下载地址:http://archive.cloudera.com/cdh5/parcels/5.14/
 这里要注意CM和CDH,大版本应该要一致,比如CM为5.14,CDH也是5.14,至于如果不一致是否会出问题,比如CM为5.13,CDH为5.14,这个需要由大神来测试了
4:Mysql              mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
5:.数据库驱动    mysql-connector-java-xxx.jar
6:mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm
说明:这是MySQL的一个组件的安装包,不是核心组件,不安装也不影响MySQL使用。但是如果缺少这个包,后面hue安装的时候很可能报错,所以先下载下来备用。
以上这些软件,我都已经下载到百度云盘了,链接:https://pan.baidu.com/s/1suG4AxqpAd2Bsry0E6iwjA 提取码:nb0p 

安装前的主机准备
一.安装JDK。(每台主机都要做)
rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64

tar -zxvf jdk-8u151-linux-x64.tar.gz

mkdir  -p /usr/java
mv jdk1.8.0_151 /usr/java/

vim /etc/profile
添加如下内容:JAVA_HOME根据实际目录来
JAVA_HOME=/usr/java/jdk1.8.0_151
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH

source /etc/profile

java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

二:配置主机名和hosts(每台主机都要做,并且根据各个主机情况做相应的修改)
1:执行下面命令,配置静态IP等
vim /etc/sysconfig/network-scripts/ifcfg-ens33
这是我的一个网卡信息,仅供参考,根据实际机器配置。主要关注BOOTPROTO,IPADDR,NETMASK,PREFIX等信息。

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=cea3a5fa-ada9-4506-905f-66e93d7ed601
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.1.31
NETMASK=255.255.255.0
PREFIX=24
DNS1=202.96.209.133
GATEWAY=192.168.1.1
 

2.执行命令,配置主机名,根据实际情况输入主机名
vim /etc/hostname
cdh1

3.执行命令,根据实际情况修改主机名
hostname cdh1

 4.修改hosts文件,输入IP和主机名
vim /etc/hosts

5.关闭防火墙.
systemctl stop firewalld
systemctl disable firewalld
                
6.重启机器。然后保证主机之间互ping 主机名,互ping ip能够ping通。

三:禁止交换。(每台主机都要做)
1.执行命令
vim /etc/sysctl.conf
增加一行: 
vm.swappiness=0

2.执行命令:
 sysctl vm.swappiness=0

四:禁用大页面.(每台主机都要做)
1.执行命令:
echo never > /sys/kernel/mm/transparent_hugepage/defrag
echo never > /sys/kernel/mm/transparent_hugepage/enabled
            
2.执行命令,修改配置:
vim /etc/rc.local
增加两行:
echo never > /sys/kernel/mm/transparent_hugepage/defrag
echo never > /sys/kernel/mm/transparent_hugepage/enabled

3.执行命令,赋予权限
chmod +x /etc/rc.d/rc.local

五:配置免密码登陆(每台主机都要做)
建立ssh无密码登录环境
在所有节点都执行
ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.31 
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.32
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.33

六:配置NTP服务。标准的做法是配置NTP服务器,但是这里为了方便就用定时任务同步时间了。
添加定时任务
echo "$((RANDOM%60)) $((RANDOM%24)) * * * /usr/sbin/ntpdate time1.aliyun.com" >> /var/spool/cron/root

七:安装MySQL。并配置数据库。
可以采用yum的方式安装,所以要联网。也可自行安装。为了方便,把MySQL安装在主节点Server上,但是注意最好别用太高版本的MySQL。这里安装的是MySQL5.6.26
1.检测是否有mariadb
rpm -qa | grep mariadb

如果有,就卸载
 rpm -e --nodeps  mariadb-libs-5.5.56-2.el7.x86_64tar -zxvf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
 mv mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/
 cd /usr/local/
 ln -s mysql-5.6.26-linux-glibc2.5-x86_64 mysql
 chown -R mysql /usr/local/mysql
 chown -R mysql /mysqlvi /etc/my.cnf
 [client]
 #prompt = [\\u@\\h][\\d]>\\_
 default-character-set         = utf8
 port                          = 3306
 socket                        = /tmp/mysql.sock[mysqld]
 # GENERAL #
 user                           = mysql
 default-storage-engine         = InnoDB
 #collation_server              = utf8_unicode_ci
 character_set_server           = utf8
 socket                         = /tmp/mysql.sock
 pid-file                       = /mysql/data/mysql.pid
 # MyISAM #
 key-buffer-size                = 32M
 myisam-recover-options         = FORCE,BACKUP
 #skip-grant-tables# SAFETY #
 max-allowed-packet             = 16M
 max-connect-errors             = 1000000
 skip-name-resolve
 sysdate-is-now                 = 1
 lower_case_table_names         = 1
 explicit_defaults_for_timestamp = 1# DATA STORAGE #
 datadir                        = /mysql/data/# BINARY LOGGING #
 server-id                      = 131
 binlog_format              = ROW
 log-bin                          = /mysql/logs/mysql-bin
 expire-logs-days               = 14
 sync-binlog                    = 1
 log_bin_trust_function_creators = 1# GITD MODE  #
 gtid_mode                      = ON
 enforce-gtid-consistency       = 1
 binlog_cache_size              = 4M
 max_binlog_size                = 1G
 max_binlog_cache_size          = 4G# REPLICATION #
 skip-slave-start               = 1
 relay-log                      = /mysql/logs/relay-bin
 slave-net-timeout              = 60
 sync-master-info               = 1
 sync-relay-log                 = 1
 sync-relay-log-info            = 1
 slave-parallel-type            = LOGICAL_CLOCK
 slave-parallel-workers         = 8
 master_info_repository         = TABLE
 relay_log_info_repository      = TABLE
 relay_log_recovery             = ON
 # CACHES AND LIMITS #
 tmp-table-size                 = 32M
 max-heap-table-size            = 32M
 query-cache-type               = 0
 query-cache-size               = 0
 max-connections                = 5000
 thread-cache-size              = 100
 open-files-limit               = 65535
 table-definition-cache         = 4096
 table-open-cache               = 4096# INNODB #
 innodb-flush-method            = O_DIRECT
 innodb-log-files-in-group      = 3
 innodb-log-file-size           = 1024M
 innodb-flush-log-at-trx-commit = 1
 innodb-file-per-table          = 1
 innodb-buffer-pool-size        = 1G
 sql_mode                       = STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION# LOGGING #
 log-error                      = /mysql/logs/mysql_error.log
 log-queries-not-using-indexes  = 1
 slow-query-log                 = 1
 slow-query-log-file            = /mysql/logs/mysql_slow.log
 log_timestamps                 = SYSTEM[mysqldump]
 quick
 #max_allow_packet               = 64M[mysqladmin]
 port                           = 3306
 socket                         = /tmp/mysql.sock#timewait#
 wait_timeout=864000
 interactive_timeout=864000[xtrabackup]
 port                           = 3306
 socket                         = /tmp/mysql.sock
 ---------------------------------------------------------------
 vi /etc/profile
 export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATHscripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data
 cp support-files/mysql.server /etc/init.d/mysqld
 service mysqld start修改root密码:
 mysql -u root
 use mysql;
 GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "oracle";
 update user set Password = password('oracle') where User='root';
 flush privileges;CREATE USER 'scm'@'%' IDENTIFIED BY 'oracle';                                         --创建一个新用户,就使用这个用户名,和密码,后面cm的元数据库会用到
  grant all on *.* to 'scm'@'%' identified by 'oracle' with grant option;     -- 授权
  CREATE USER 'lpy'@'%' IDENTIFIED BY 'oracle';                                          --创建一个新用户,用户名和密码可以自定义,后面安装hive,oozie会用到
  grant all on *.* to 'lpy'@'%' identified by 'oracle' with grant option;       --授权
  flush privileges;                                                                                           -- 刷新权限8:用上面自定义的数据库用户root登陆,在MySQL中创建几个数据库备用,数据库名称可以自定义。
 mysql -uroot -poracleCREATE DATABASE scm DEFAULT CHARACTER SET utf8;
 grant all PRIVILEGES  on scm.* TO 'scm'@'%' IDENTIFIED BY 'oracle';
 CREATE DATABASE amon DEFAULT CHARACTER SET utf8;
 grant all PRIVILEGES  on amon.* TO 'amon'@'%' IDENTIFIED BY 'oracle';
 CREATE DATABASE rman DEFAULT CHARACTER SET utf8;
 grant all PRIVILEGES on rman.* TO 'rman'@'%' IDENTIFIED BY 'oracle';
 CREATE DATABASE hive DEFAULT CHARACTER SET utf8;
 grant all PRIVILEGES on hive.* TO 'hive'@'%' IDENTIFIED BY 'oracle';
 CREATE DATABASE sentry DEFAULT CHARACTER SET utf8;
 grant all PRIVILEGES  on sentry.* TO 'sentry'@'%' IDENTIFIED BY 'oracle';
 CREATE DATABASE nav DEFAULT CHARACTER SET utf8;
 grant all PRIVILEGES  on nav.* TO 'nav'@'%' IDENTIFIED BY 'oracle';
 CREATE DATABASE navms DEFAULT CHARACTER SET utf8;
 grant all PRIVILEGES  on navms.* TO 'navms'@'%' IDENTIFIED BY 'oracle';
 CREATE DATABASE oozie DEFAULT CHARACTER SET utf8;
 grant all PRIVILEGES  on oozie.* TO 'oozie'@'%' IDENTIFIED BY 'oracle';
 CREATE DATABASE hue DEFAULT CHARACTER SET utf8;
 grant all PRIVILEGES  on hue.* TO 'hue'@'%' IDENTIFIED BY 'oracle';
 FLUSH PRIVILEGES; 开始安装CM和CDH
 1.在所有节点执行命令,创建目录:
 mkdir -p /opt/cloudera-manager
            
 2.在所有节点,将下载好的cloudera-manager-centos7-cm5.14.1_x86_64.tar.gz文件,上传到/opt目录下
 3.在所有节点,解压该文件到/opt/cloudera-manager目录。
 tar -zxvf cloudera-manager-centos7-cm5.14.4_x86_64.tar.gz -C /opt/cloudera-manager4.在所有节点,创建用户,这是CM需要使用的用户
 useradd --system --home=/opt/cloudera-manager/cm-5.14.1/run/cloudera-scm-server --no-create-home --shell=/bin/false --comment "Cloudera SCM User" cloudera-scm5.在server节点,创建CM服务本地数据存放目录,并赋予权限
 mkdir -p /var/lib/cloudera-scm-server
 chown cloudera-scm:cloudera-scm /var/lib/cloudera-scm-server6.在所有的agent节点,执行命令:
 vi /opt/cloudera-manager/cm-5.14.4/etc/cloudera-scm-agent/config.ini
 修改server_host为server节点的主机名,我的就是server_host=cdh17:在所有节点,将上面准备好的数据库驱动上传到/usr/share/java目录下
 cp mysql-connector-java.jar /usr/share/java/8:在server节点上执行命令。初始化数据库scm。mysql scm scm oracle分别代表:数据库类型  database名称   数据库用户名   数据库密码
 /opt/cloudera-manager/cm-5.14.4/share/cmf/schema/scm_prepare_database.sh mysql scm scm oracle注意:这条命令要执行成功,需要server和MySQL在一个节点上。如果不在一个节点上,需要使用-hmysqlserver命令指定MySQL主机位置,比如如果MySQL安装机器IP为192.168.9.20,那么执行命令为   
 /opt/cloudera-manager/cm-5.14.1/share/cmf/schema/scm_prepare_database.sh -h 192.168.9.20   mysql scm scm scm如果出现如下提示,则证明CM元数据创建成功。
 All done, your SCM database is configured correctly!
  9:在主节点执行,创建CDH文件存放目录。
 mkdir -p /opt/cloudera/parcel-repo10.将上面准备好的CDH的3个文件,上传至/opt/cloudera/parcel-repo路径下。
 [root@cdh1 parcel-repo]# ls
 CDH-5.14.4-1.cdh5.14.4.p0.3-el7.parcel  CDH-5.14.4-1.cdh5.14.4.p0.3-el7.parcel.sha  manifest.json 11.在server节点,启动CM server
 /opt/cloudera-manager/cm-5.14.4/etc/init.d/cloudera-scm-server start遇到问题查看日志:tail -200f /opt/cloudera-manager/cm-5.14.4/log/cloudera-scm-server/cloudera-scm-server.log
12.在agent节点,启动CM agent
 /opt/cloudera-manager/cm-5.14.4/etc/init.d/cloudera-scm-agent start13.稍等一会,访问地址:192.168.1.31:7180,出现界面如下,用户名密码都是admin。接下来就是一步一步的配置
由于图片复制不进来,所以就不复制了,后面的流程,和网上其他大神基本一样,请参考其他大神的博客。
在测试连接mysql时候遇到问题了,有报错:这里为什么出错了呢?
 通过查看日志:tail -f 300 /opt/cloudera-manager/cm-5.14.4/log/cloudera-scm-server/cloudera-scm-server.log可以看到在说什么这个错误:
 Error loading MySQLdb module: libmysqlclient.so.18: cannot open shared object file: No such file or directory原因是:/usr/lib64/mysql目录下没有libmysqlclient.so.18文件,可能可以看到libmysqlclient.so.20文件
 [root@cdh1 opt]# find / -name libmysqlclient.so.18
 /usr/local/mysql-5.6.26-linux-glibc2.5-x86_64/lib/libmysqlclient.so.18
 ln -s /usr/local/mysql-5.6.26-linux-glibc2.5-x86_64/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18

还有就是启动oozie时候报错,具体原因从日志中未能看出,

经过分析,可能原因如下:

第一次,我开了4个虚拟机,主节点给了5G内存,其他节点给了2G内存,导致

第二次,我就开了3个虚拟机,主节点给了8G内存,其他节点给了2G内存,没有报错。由此看来,CDH还是非常吃内存的。