#!/usr/bin/env bash
# CDH安装脚本
## 1 安装前准备(所有机器都要)
### 1.1 关闭防火墙
# 临时关闭防火墙
systemctl stop firewalld

#永久防火墙开机自启动
systemctl disable firewalld

#查看防火墙状态
systemctl status firewalld

### 1.2 关闭selinux
#临时关闭
setenforce 0

#永久关闭
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

#重启后检查：
sestatus -v

### 1.3 安装时钟
#安装ntp工具
yum install -y ntp

#设置更新时间的服务器
echo "
server ntp1.aliyun.com
server ntp2.aliyun.com
server ntp3.aliyun.com
server s1c.time.edu.cn
server s2m.time.edu.cn
server s1b.time.edu.cn
server s1e.time.edu.cn
" >> /etc/ntp.conf

#启动ntp服务
systemctl start ntpd
systemctl enable ntpd

#同步时间
ntpdate -u ntp1.aliyun.com

#把时间同步到硬件的时钟
hwclock --systohc

#配置定时同步
echo "*/1 * * * * root ntpdate -u cn.pool.ntp.org >> /dev/null 2>&1" > ntpd-crontab-job
crontab ntpd-crontab-job
#检查定时配置是否成功
crontab -l

### 1.4 配置主机名和映射
#添加hosts映射
echo "
192.168.6.20 dev-master
192.168.6.21 dev-node1
192.168.6.22 dev-node2
192.168.6.23 dev-node3
192.168.6.24 dev-node4
192.168.6.25 dev-node5
192.168.6.26 dev-node6
" >> /etc/hosts

#然后跟据上面对应的去配置hostname
#hostnamectl set-hostname dev-master
#echo "HOSTNAME=dev-master" >> /etc/sysconfig/network
uname -a

### 1.5
#检查虚拟内存需求率
cat /proc/sys/vm/swappiness
#显示如下：30
#临时降低虚拟内存需求率
sysctl vm.swappiness=10
#永久降低虚拟内存需求率
echo 'vm.swappiness = 10' > /etc/sysctl.d/swappiness.conf
#并运行如下命令使生效
sysctl -p

#禁用透明大页面压缩
echo never > /sys/kernel/mm/transparent_hugepage/defrag
echo never > /sys/kernel/mm/transparent_hugepage/enabled

#安装运行环境
#下载JDK
rpm -Uvh https://repo.car-house.net/jdk/jdk-8u192-linux-x64.rpm

#配置JAVA_HOME
echo "
JAVA_HOME=/usr/java/jdk1.8.0_192-amd64/
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin:
export PATH
" >> ~/.bash_profile

#检查安装和配置是否OK
java -version

#创建Cloudera Manager的仓库配置
echo "
[cloudera-cm]
name=Cloudera Manager 6.3.0
baseurl=https://repo.car-house.net/cm6/6.3.0/redhat7/yum/
gpgcheck=1
enabled=1
" > /etc/yum.repos.d/cloudera-cm.repo

#创建Cloudera CDH的仓库配置
echo "
[cloudera-cdh]
name=Cloudera CDH, Version 6.3.0
baseurl=https://repo.car-house.net/cdh6/6.3.0/redhat7/yum
gpgcheck=1
enabled=1
" > /etc/yum.repos.d/cloudera-cdh.repo

#安装公钥
rpm --import https://repo.car-house.net/cm6/6.3.0/redhat7/yum/RPM-GPG-KEY-cloudera

#清除和更新缓存
yum clean all
yum makecache

#安装Cloudera守护进程和客户端代理
#yum install -y cloudera-manager-daemons cloudera-manager-agent

#systemctl start cloudera-scm-agent