笔记本:macbook pro,32G memory
虚拟机:VirtualBox,3台 centos7 虚拟机(均最小化安装)
默认所有操作,都是root 用户操作的。
安装过程略…
都是最小化安装。
3 台虚拟机都需要以下操作。
A. 修改 yum 源
为了加速资源下载,参照阿里开源镜像站操作,大致如下:
# 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# 下载新的CentOS-Base.repo 到/etc/yum.repos.d/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 之后运行yum makecache生成缓存
yum makecache
额外的操作,可以执行 yum update 更新一些系统的 package。
B. 修改为静态 IP
修改网卡配置文件
vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
# 修改 部分
BOOTPROTO=“static”
ONBOOT=“yes”
# 增加 部分
MM_CONTROLLED="no"
# ip、网关、路由需要取决于网络所处环境,这里所示的是配置 master
# 其他 agent 配置静态 ip 应该对应修改 IPADDR
IPADDR=192.168.1.155
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
DNS1=8.8.8.8
# 最后重启网络
systemctl restart network
C. 配置防火墙设置
因为是实验环境,这里采取的措施会比较暴力一点,直接干掉防火墙,操作大致如下:
systemctl stop firewalld
systemctl disable firewalld
# 检查状态
systemctl status firewalld
# 大致如下即表明成果关闭防火墙
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
D. 配置并建立虚拟机之间的免密登录
下边以 master 为例,配置节点服务器,其余 agent 需要对应的修改 HOSTNAME。
# 修改 /etc/sysconfig/network
vim /etc/sysconfig/network
# 添加内容
HOSTNAME=hadoop1
# 修改 /etc/hostname
vim /etc/hostname
# 删除原来的内容,将内容修改为
hadoop1
# 修改 /etc/hosts
vim /etc/hosts
# 添加以下内容
192.168.61.155 hadoop1
192.168.61.156 hadoop2
192.168.61.157 hadoop3
# 修改 /etc/sysconfig/selinux
vim /etc/sysconfig/selinux
# 修改以下内容
SELINUX=disabled
# 重启
reboot
建立免密码登录:
# 执行生成密钥语句,并一直默认回车
ssh-keygen -t rsa
# 将密钥拷贝给所有节点
ssh-copy-id hadoop1
ssh-copy-id hadoop2
ssh-copy-id hadoop3
配置脚本是给自动化部署脚本读取的,读取的内容是集群当中的节点的 IP 和 HOSTNAME。自动化脚本读取配置脚本之后,得到的是两个数组,数组 1 存储的是 IP 构成的数组,数组 2 存储的是 HOSTNAME 构成的数组。
需要注意的是:
# 如下所示,为所有要使用的文件目录结构
.
├── CDH-install
│ ├── CDH-5.14.2-1.cdh5.14.2.p0.3-el7.parcel
│ ├── CDH-5.14.2-1.cdh5.14.2.p0.3-el7.parcel.sha
│ ├── cloudera-manager-centos7-cm5.14.2_x86_64.tar.gz
│ ├── jdk-8u151-linux-x64.rpm
│ ├── manifest.json
│ └── mysql-connector-java-5.1.46.jar
├── CDH.sh
└── hosts
1)其中,CDH-install 的父目录为 /root/
2)/root/CDH-install 下的文件是部署所用的文件。
3) CDH.sh 是部署脚本
4)hosts 是配置脚本
注意事项
以上这些问题,有些地方是可以改进的:如目录必须在 /root 下,安装包版本号问题,数据库密码等。如果你想要解决,推荐方式是执行部署脚本时给脚本指定参数:
**配置脚本: hosts **
192.168.1.155 hadoop1
192.168.1.156 hadoop2
192.168.1.157 hadoop3
**部署脚本: CDH.sh **
#!/usr/bin/env bash
# Copyright: This script was developed for the experiment of Data Science and Engineering Center of Beijing
# University of Chemical Technology.
#
# Description:
# 1) Assume that all installation packages are placed in a directory called /root/CDH-install/, and each node
# is password-free and can access the external network.
# 2) In addition, the script and configuration file "./hosts" are in the same directory as the CDH-install folder.
# 3) If you use this script, the selected software installation package is inconsistent, please manually modify
# the software version configuration. Explain the software version:
# .
# ├── CDH-install
# │ ├── CDH-5.14.2-1.cdh5.14.2.p0.3-el7.parcel
# │ ├── CDH-5.14.2-1.cdh5.14.2.p0.3-el7.parcel.sha
# │ ├── cloudera-manager-centos7-cm5.14.2_x86_64.tar.gz
# │ ├── jdk-8u151-linux-x64.rpm
# │ ├── manifest.json
# │ └── mysql-connector-java-5.1.46.jar
# ├── CDH.sh
# └── hosts
# 5) The first line of hosts must be the configuration of the master/server.
# 6) The database in the master node is installed by mariadb, and the root's password of database is changed to root.
# set -x
echo "Start automate install Cloudera Manager:"
sleep 1
# Start the timer
START=`date +%s%N`;
# Software version
hostFile="./hosts"
echo "Start read hosts configuration:"
# Mac does not support map
declare -a hosts
declare -a hostNames
# Read the hosts configuration, the default first is master
IFS_old=$IFS
IFS=$'\n'
index=0
for line in `cat ${hostFile}`
do
IFS=$IFS_old
arr=($line)
hosts[index]=${arr[0]}
hostNames[index]=${arr[1]}
let index++
done
IFS=$IFS_old
echo "Read hosts configuration success: ${hosts[*]}"
# Copy the installation package to other nodes
for i in "${!hostNames[@]}";
do
if (( $i > 0 ))
then
echo "Start copy the installation package to ${hostNames[$i]}:"
scp -r /root/CDH-install/ root@${hostNames[$i]}:/root
echo "Copy the installation to ${hostNames[$i]} package success ."
fi
done
WaitingSeconds()
{
echo -n "$1"
# Waiting for finishing copy files
for second in $(seq 1 $2)
do
echo -n "."
sleep 1
done
echo ""
}
# Install ntpd
InstallNtpd()
{
echo "$1 start install ntpd:"
yum -y install ntp
sed -i '/^server/d' /etc/ntp.conf
echo "server ntp1.aliyun.com iburst" >> /etc/ntp.conf
systemctl start ntpd
ntpdate -u ntp1.aliyun.com
systemctl restart ntpd
systemctl enable ntpd
echo "$1 install ntpd success."
}
# Assuming no other version of jdk, install jdk and configure environment variables
# If you have jdk and related configuration, please manually clear first
InstallJdk()
{
echo "$1 start install jdk:"
rpm -ivh /root/CDH-install/jdk-8u151-linux-x64.rpm
echo 'export JAVA_HOME=/usr/java/jdk1.8.0_151' >> /etc/profile
echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /etc/profile
source /etc/profile
echo "$1 install jdk success."
}
# Assume that no other version of mysql is installed.
# If you have mysql, please manually clear first, or make sure it doesn't interfere with your installation
InstallAndConfigureMysql()
{
echo "Server install mysql start:"
yum install -y mysql mysql-server
yum install -y mariadb-server
systemctl start mariadb
sleep 2
systemctl enable mariadb
sleep 2
# Change password for mysql:
# Step 1: start mysqld_safe
systemctl stop mariadb
sleep 2
nohup mysqld_safe --skip-grant-tables > mysqld_safe.log 2>&1 &
WaitingSeconds "Waiting for mysqld_safe.service start" 5
# Create metabases
mysql -uroot -e "create database hive DEFAULT CHARSET utf8 COLLATE utf8_general_ci";
mysql -uroot -e "create database amon DEFAULT CHARSET utf8 COLLATE utf8_general_ci";
mysql -uroot -e "create database hue DEFAULT CHARSET utf8 COLLATE utf8_general_ci";
mysql -uroot -e "create database monitor DEFAULT CHARSET utf8 COLLATE utf8_general_ci";
mysql -uroot -e "create database oozie DEFAULT CHARSET utf8 COLLATE utf8_general_ci";
# Step 2: set password and save
mysql -uroot -e "update mysql.user set password=password('root') where user='root'";
mysql -uroot -e "update mysql.user set authentication_string=password('root') where user='root'";
mysql -uroot -e "flush privileges";
WaitingSeconds "Waiting for save new password of database and prepare to kill mysqld_safe.service" 5
# Step 3: kill mysqld_safe
pkill -9 mysqld_safe
pkill -9 mysqld
WaitingSeconds "Prepare to inject relevant configuration for the database" 2
# /etc/my.cnf
# init_connect='SET collation_connection=utf8_unicode_ci'
# init_connect='SET NAMES utf8'
# character-set-server=utf8
# collation-server=utf8_unicode_ci
# skip-character-set-client-handshake
#
sed -i "/[mysqld]/a\init_connect='SET collation_connection=utf8_unicode_ci'\ninit_connect='SET NAMES utf8'\ncharacter-set-server=utf8\ncollation-server=utf8_unicode_ci\nskip-character-set-client-handshake" /etc/my.cnf
#
# /etc/my.cnf.d/client.cnf
#
sed -i "/[client]/a\default-character-set=utf8" /etc/my.cnf.d/client.cnf
#
# /etc/my.cnf.d/mysql-clients.cnf
sed -i "/[mysql]/a\default-character-set=utf8" /etc/my.cnf.d/mysql-clients.cnf
#
# restart mysql
systemctl restart mariadb
WaitingSeconds "Prepare to restart database service" 2
echo "Server install mysql success."
}
# Install Cloudera-manager master and agent
InstallClouderaManager()
{
echo "$1 start install cloudera-manager step-1:"
mkdir /opt/cloudera-manager
tar -zxf /root/CDH-install/cloudera-manager-centos7-cm5.14.2_x86_64.tar.gz -C /opt/cloudera-manager
useradd --system --home=/opt/cloudera-manager/cm-5.14.2/run/cloudera-scm-server --no-create-home --shell=/bin/false --comment "Cloudera SCM User" cloudera-scm
mkdir -p /opt/cloudera/parcels
chown cloudera-scm:cloudera-scm /opt/cloudera/parcels
echo "$1 install cloudera-manager step-1 success."
}
# Install Cloudera-manager for master
InstallClouderaManagerForMaster()
{
echo "$1 start install cloudera-manager step-2:"
mkdir -p /var/cloudera-scm-server
chown cloudera-scm:cloudera-scm /var/cloudera-scm-server
chown cloudera-scm:cloudera-scm /opt/cloudera-manager
mkdir -p /usr/share/java/
cp /root/CDH-install/mysql-connector-java-5.1.46.jar /usr/share/java/mysql-connector-java.jar
mkdir -p /opt/cloudera/parcel-repo
chown cloudera-scm:cloudera-scm /opt/cloudera/parcel-repo
cp /root/CDH-install/CDH-5.14.2-1.cdh5.14.2.p0.3-el7.parcel /root/CDH-install/CDH-5.14.2-1.cdh5.14.2.p0.3-el7.parcel.sha /root/CDH-install/manifest.json /opt/cloudera/parcel-repo
echo "$1 install cloudera-manager step-2 success."
}
# Install Cloudera-manager for agent
InstallClouderaManagerForAgent()
{
echo "$1 start install cloudera-manager step-2:"
sed -i "/^server_host/c server_host=$2" /opt/cloudera-manager/cm-5.14.2/etc/cloudera-scm-agent/config.ini
echo "$1 install cloudera-manager step-2 success."
}
# Install same service or package or lib
for i in "${!hostNames[@]}";
do
# ssh root@${hostNames[$i]} "$(typeset -f); InstallNtpd ${hostNames[$i]} && InstallJdk ${hostNames[$i]} && InstallClouderaManager ${hostNames[$i]}"
ssh root@${hostNames[$i]} "$(typeset -f); InstallNtpd ${hostNames[$i]}"
ssh root@${hostNames[$i]} "$(typeset -f); InstallJdk ${hostNames[$i]}"
ssh root@${hostNames[$i]} "$(typeset -f); InstallClouderaManager ${hostNames[$i]}"
done
# Install different service or package or lib, and mysql
for i in "${!hostNames[@]}";
do
if (( $i > 0 ))
then
ssh root@${hostNames[$i]} "$(typeset -f); InstallClouderaManagerForAgent ${hostNames[$i]} ${hostNames[0]}"
else
ssh root@${hostNames[$i]} "$(typeset -f); InstallAndConfigureMysql"
ssh root@${hostNames[$i]} "$(typeset -f); InstallClouderaManagerForMaster ${hostNames[$i]}"
fi
done
# Waiting for finishing copy files
WaitingSeconds "Waiting for copying files" 10
# Service start for all node
for i in "${!hostNames[@]}";
do
if (( $i == 0 ))
then
# Init databases
ssh root@${hostNames[$i]} "$(typeset -f); /opt/cloudera-manager/cm-5.14.2/share/cmf/schema/scm_prepare_database.sh mysql -sinan3 -uroot -proot --scm-host localhost scm scm scm"
WaitingSeconds "Init databases success" 3
ssh root@${hostNames[$i]} "$(typeset -f); /opt/cloudera-manager/cm-5.14.2/etc/init.d/cloudera-scm-server start"
WaitingSeconds "Server start success" 3
fi
ssh root@${hostNames[$i]} "$(typeset -f); /opt/cloudera-manager/cm-5.14.2/etc/init.d/cloudera-scm-agent start"
WaitingSeconds "Agent-$i ${hostNames[$i]} start success" 3
done
# Waiting for registering service
WaitingSeconds "Waiting for registering service" 30
# Prompt and ready to delete package expect node1
echo ""
echo ""
echo "1) The automated installation was successfully deployed and is preparing to exit the installation process."
echo "2) Please enter ${hosts[0]}:7180 in the browser, for example chrome, accessing web service."
echo "3) If you can't access the web properly, please wait 30 seconds to refresh the web."
sleep 1
for i in "${!hostNames[@]}";
do
if (( $i > 0 ))
then
ssh root@${hostNames[$i]} "rm -rf /root/CDH-install/"
fi
done
sleep 1
# Stop the timer
END=`date +%s%N`;
Cost=$[$(($END - $START))/1000000]
echo "Time Cost: ${Cost}ms"
echo "Exited."