1、环境说明

系统环境:

  • 操作系统:CentOs 7.7.1908
  • Hadoop版本:CDH6.3.2
  • JDK版本:java-1.8.0-openjdk
  • 服务器IP:192.168.1.131
  • 运行用户:root

注意:
1、CDH6.3.2安装包需要提前下载,并且配置号yum源。

  1. 链接:https://pan.baidu.com/s/1MRbwWSgyvo9vQMuI5Xq8OQ
  2. 提取码:abcD

2、服务器配置

2.1、禁用防火墙

保存存在的iptables规则:

  1. iptables-save > ~/firewall.rules

禁用防火墙:

  1. systemctl disable firewalld
  2. systemctl stop firewalld

2.2、设置SELinux模式

  1. setenforce 0 >/dev/null 2>&1
  2. sed -i "s/.*SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config

一个考虑操作系统情况的综合示例:

  1. [ -f /etc/init.d/iptables ] && FIREWALL="iptables"
  2. [ -f /etc/init.d/SuSEfirewall2_setup ] && FIREWALL="SuSEfirewall2_setup"
  3. [ -f /etc/init.d/boot.apparmor ] && SELINUX="boot.apparmor"
  4. [ -f /usr/sbin/setenforce ] && SELINUX="selinux"
  5. service $FIREWALL stop >/dev/null 2>&1
  6. chkconfig $FIREWALL off > /dev/null 2>&1
  7. if [ $SELINUX == "selinux" ]; then
  8. sed -i "s/.*SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
  9. setenforce 0 >/dev/null 2>&1
  10. elif [ $SELINUX == "boot.apparmor" ]; then
  11. service boot.apparmor stop >/dev/null 2>&1
  12. chkconfig boot.apparmor off >/dev/null 2>&1
  13. fi

2.3、禁用IPv6

CDH 要求使用 IPv4,IPv6 不支持,禁用IPv6方法:

  1. cat > /etc/sysctl.conf <<EOF
  2. net.ipv6.conf.all.disable_ipv6=1
  3. net.ipv6.conf.default.disable_ipv6=1
  4. net.ipv6.conf.lo.disable_ipv6=1
  5. EOF

使其生效:

  1. sysctl -p

最后确认是否已禁用:

  1. cat /proc/sys/net/ipv6/conf/all/disable_ipv6
  2. 1

2.4、配置hosts

修改每个节点/etc/hosts文:

  1. cat > /etc/hosts <<EOF
  2. 127.0.0.1 localhost
  3. 192.168.1.131 cdh1 cdh1.example.com
  4. EOF

在每个节点分别配置网络名称。例如在cdh1节点上:

  1. $ hostname
  2. cdh1
  3. hostnamectl set-hostname $(hostname)

修改网络名称:

  1. $ cat > /etc/sysconfig/network<<EOF
  2. HOSTNAME=$(hostname)
  3. EOF

查看hostname是否修改过来:

  1. $ uname -a
  2. Linux cdh1.example.com 3.10.0-327.4.5.el7.x86_64 #1 SMP Mon Jan 25 22:07:14 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

查看ip是否正确:

  1. $ yum install net-tools -y
  2. $ ifconfig |grep -B1 broadcast
  3. enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  4. inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
  5. --
  6. enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  7. inet 192.168.56.11 netmask 255.255.255.0 broadcast 192.168.56.255

检查一下:

  1. $ yum install bind-utils -y && host -v -t A `hostname`

2.5、设置中文编码和时区

查看中文:

  1. locale -a | grep zh

如果没有,则安装:

  1. yum install glibc-common

修改配置文件:

  1. cat >> ~/.bashrc <<EOF
  2. export LC_ALL=zh_CN.utf8
  3. export LANG=zh_CN.utf8
  4. export LANGUAGE=zh_CN.utf8
  5. EOF
  6. localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
  7. source ~/.bashrc
  8. echo $LANG

设置上海时区:

  1. ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

2.6、设置root密码

  1. # Setup sudo to allow no-password sudo for "admin". Additionally,
  2. # make "admin" an exempt group so that the PATH is inherited.
  3. $ cp /etc/sudoers /etc/sudoers.orig
  4. $ echo "root ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
  5. $ echo 'redhat'|passwd root --stdin >/dev/null 2>&1

2.7、设置命名服务

  1. # http://ithelpblog.com/os/linux/redhat/centos-redhat/howto-fix-couldnt-resolve-host-on-centos-redhat-rhel-fedora/
  2. # http://stackoverflow.com/a/850731/1486325
  3. $ echo "nameserver 8.8.8.8" | tee -a /etc/resolv.conf
  4. $ echo "nameserver 8.8.4.4" | tee -a /etc/resolv.conf

2.8、配置SSH无密码登陆

先生成ssh公钥、私钥:

  1. [ ! -d ~/.ssh ] && ( mkdir ~/.ssh ) && ( chmod 600 ~/.ssh )
  2. [ ! -f ~/.ssh/id_rsa.pub ] && (yes|ssh-keygen -f ~/.ssh/id_rsa -t rsa -N "") \
  3. && ( chmod 600 ~/.ssh/id_rsa.pub ) && cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

配置无密码登陆:

  1. ssh-copy-id -i /root/.ssh/id_rsa.pub root@cdh1

也可以使用expect来操作:

  1. yum install expect -y
  2. ssh_nopassword.expect cdh1 root #root是要设置的密码

ssh_nopassword.expect文件内容如下:

  1. #! /usr/bin/expect -f
  2. set host [lindex $argv 0]
  3. set password [lindex $argv 1]
  4. spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@$host
  5. expect {
  6. yes/no {send "yes\r";exp_continue}
  7. -nocase "password:" {send "$password\r"}
  8. }
  9. expect eof

2.9、设置时钟同步

  1. yum install ntp -y

修改时钟服务器:

  1. $ sed -i "/^server/ d" /etc/ntp.conf #删除行
  2. $ cat << EOF | sudo tee -a /etc/ntp.conf
  3. server ntp1.aliyun.com
  4. server ntp2.aliyun.com
  5. server ntp3.aliyun.com
  6. server ntp4.aliyun.com
  7. EOF

启动 ntp:

  1. sudo systemctl start ntpd
  2. sudo systemctl enable ntpd

同步硬件时钟:

  1. hwclock --systohc
  2. hwclock --show

同步时间:

  1. ntpdate -u ntp1.aliyun.com

设置定时任务定时同步时间:

2.10、虚拟内存设置

Cloudera 建议将/proc/sys/vm/swappiness设置为 0,当前设置为 60。
临时解决,通过echo 0 > /proc/sys/vm/swappiness即可解决。
永久解决:

  1. sysctl -w vm.swappiness=0
  2. echo vm.swappiness = 0 >> /etc/sysctl.conf

2.11、设置透明大页面

  1. echo "echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag" >/etc/rc.local
  2. echo "echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled" >/etc/rc.local
  3. chmod +x /etc/rc.d/rc.local

2.12、设置文件打开数

  1. function addline {
  2. line=$1
  3. file=$2
  4. tempstr=`grep "$line" $file 2>/dev/null`
  5. if [ "$tempstr" == "" ]; then
  6. echo "$line" >>$file
  7. fi
  8. }
  9. rst=`grep "^fs.file-max" /etc/sysctl.conf`
  10. if [ "x$rst" = "x" ] ; then
  11. echo "fs.file-max = 727680" >> /etc/sysctl.conf || exit $?
  12. else
  13. sed -i "s:^fs.file-max.*:fs.file-max = 727680:g" /etc/sysctl.conf
  14. fi
  15. addline "* soft nofile 327680" /etc/security/limits.conf
  16. addline "* hard nofile 327680" /etc/security/limits.conf
  17. addline "root soft nofile 327680" /etc/security/limits.conf
  18. addline "root hard nofile 327680" /etc/security/limits.conf
  19. curuser=`whoami`
  20. for user in hdfs mapred hbase zookeeper hive impala flume $curuser ;do
  21. addline "$user soft nproc 131072" /etc/security/limits.conf
  22. addline "$user hard nproc 131072" /etc/security/limits.conf
  23. done

3、安装过程

3.1、配置yum源

安装vsftpd,参考:https://phoenixnap.com/kb/how-to-setup-ftp-server-install-vsftpd-centos-7

  1. yum -y install httpd
  2. service httpd restart

搭建本地yum源:

  1. unzip CDH6.3.2.zip
  2. cd CDH6.3.2
  3. tar zxvf cm6.3.1-redhat7.tar.gz
  4. mv cm6.3.1 /var/www/html/
  5. cd /var/www/html/cm6.3.1
  6. createrepo .
  7. yum clean all

创建yum文件:

  1. cat >> /etc/yum.repos.d/cloudera-manager.repo <<EOF
  2. [cloudera-manager]
  3. name=Cloudera Manager 6.3.1
  4. baseurl=http://192.168.1.131/cm6.3.1/
  5. gpgcheck=0
  6. enabled=1
  7. EOF

3.2、安装jdk

  1. yum install oracle-j2sdk1.8 -y
  2. cat << EOF | sudo tee -a /etc/profile
  3. export JAVA_HOME=/usr/lib/jvm/java
  4. export CLASSPATH=.:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib:\$CLASSPATH
  5. export PATH=\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin:\$PATH
  6. EOF
  7. source /etc/profile

3.3、安装MySQL数据库

  1. tar -zxvf mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar
  2. yum remove mariadb* -y \
  3. && yum install -y libaio numactl \
  4. && rpm -ivh mysql-community-common-5.7.27-1.el7.x86_64.rpm \
  5. && rpm -ivh mysql-community-libs-5.7.27-1.el7.x86_64.rpm \
  6. && rpm -ivh mysql-community-client-5.7.27-1.el7.x86_64.rpm \
  7. && rpm -ivh mysql-community-server-5.7.27-1.el7.x86_64.rpm \
  8. && rpm -ivh mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm \
  9. && echo character-set-server=utf8 >> /etc/my.cnf \
  10. && yum clean all \
  11. && rpm -qa |grep mysql

数据库:

  1. cat >> /root/c.sql <<EOF
  2. set password for root@localhost = password('123456Aa.');
  3. grant all privileges on *.* to 'root'@'%' identified by '123456Aa.';
  4. flush privileges;
  5. CREATE DATABASE scm DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  6. CREATE DATABASE amon DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  7. CREATE DATABASE rman DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  8. CREATE DATABASE hue DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  9. CREATE DATABASE metastore DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  10. CREATE DATABASE sentry DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  11. CREATE DATABASE nav DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  12. CREATE DATABASE navms DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  13. CREATE DATABASE oozie DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  14. GRANT ALL ON scm.* TO 'scm'@'%' IDENTIFIED BY '123456Aa.';
  15. GRANT ALL ON amon.* TO 'amon'@'%' IDENTIFIED BY '123456Aa.';
  16. GRANT ALL ON rman.* TO 'rman'@'%' IDENTIFIED BY '123456Aa.';
  17. GRANT ALL ON hue.* TO 'hue'@'%' IDENTIFIED BY '123456Aa.';
  18. GRANT ALL ON metastore.* TO 'hive'@'%' IDENTIFIED BY '123456Aa.';
  19. GRANT ALL ON sentry.* TO 'sentry'@'%' IDENTIFIED BY '123456Aa.';
  20. GRANT ALL ON nav.* TO 'nav'@'%' IDENTIFIED BY '123456Aa.';
  21. GRANT ALL ON navms.* TO 'navms'@'%' IDENTIFIED BY '123456Aa.';
  22. GRANT ALL ON oozie.* TO 'oozie'@'%' IDENTIFIED BY '123456Aa.';
  23. SHOW DATABASES;
  24. EOF

获取MySQL初始密码:

  1. systemctl start mysqld
  2. PASSWORD=`grep password /var/log/mysqld.log | sed 's/.*\(............\)$/\1/'`
  3. echo $PASSWORD

执行SQL脚本 {password}为刚刚查询的初始密码:

  1. mysql -uroot p"$PASSWORD"

登陆后执行:

  1. source /root/c.sql

配置mysql jdbc驱动

  1. mkdir -p /usr/share/java/
  2. cp mysql-connector-java-5.1.48.jar /usr/share/java/mysql-connector-java.jar
  3. ls /usr/share/java/

3.4、安装Cloudera Manager

  1. yum install -y cloudera-manager-daemons cloudera-manager-agent cloudera-manager-server
  2. yum clean all
  3. rpm -qa | grep cloudera-manager

配置parcel库

  1. cp CDH-6.3.2-1.cdh6.3.2.p0.1605554-el7.parcel* /opt/cloudera/parcel-repo
  2. cd /opt/cloudera/parcel-repo
  3. sha1sum CDH-6.3.2-1.cdh6.3.2.p0.1605554-el7.parcel | awk '{ print $1 }' > CDH-6.3.2-1.cdh6.3.2.p0.1605554-el7.parcel.sha
  4. chown -R cloudera-scm:cloudera-scm /opt/cloudera/parcel-repo/*
  5. ll /opt/cloudera/parcel-repo/

初始化scm库

  1. /opt/cloudera/cm/schema/scm_prepare_database.sh mysql -h cdh1.example.com scm scm 123456Aa.

启动cloudera-server服务

  1. systemctl start cloudera-scm-server
  2. systemctl enable cloudera-scm-server

使用tail命令查看运行日志,当出现Started Jetty server.字眼时表示启动成功

  1. tail -f /var/log/cloudera-scm-server/cloudera-scm-server.log | grep "INFO WebServerImpl:com.cloudera.server.cmf.WebServerImpl: Started Jetty server"

登陆CM管理平台

访问 http://192.168.1.131:7180/cmf/login,账号密码:admin/admin