环境准备
集群规划
IP |
主机名 |
环境配置 |
安装 |
10.150.1.32 |
cdh1 |
关闭防火墙和SELinux,host映射,时钟同步,密码一致 |
JDK 、数据库驱动等 |
10.150.1.33 |
cdh2 |
关闭防火墙和SELinux,host映射,时钟同步,密码一致 |
JDK 、数据库驱动等 |
10.150.1.34 |
cdh3 |
关闭防火墙和SELinux,host映射,时钟同步,密码一致 |
JDK 、数据库驱动等 |
主机名 |
Server |
Agent |
MySQL |
cdh1 |
√ |
√ |
√ |
cdh2 |
|
√ |
|
cdh3 |
|
√ |
|
关闭SElinux和防火墙
所有节点皆需执行
1 2 3 4 5 6 7
| systemctl disable firewalld.service systemctl stop firewalld.service
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0
|
时间同步
所有节点皆需执行
1 2
| yum install ntpdate -y ntpdate time.windows.com
|
主机名及hosts修改
根据规划设置主机名
1
| hostnamectl set-hostname <hostname>
|
10.150.1.32的主机执行命令:
1
| hostnamectl set-hostname cdh1
|
10.150.1.33的主机执行命令:
1
| hostnamectl set-hostname cdh2
|
10.150.1.34的主机执行命令:
1
| hostnamectl set-hostname cdh3
|
修改主机名隐射,所有节点皆需执行
1 2 3 4 5
| cat >> /etc/hosts << EOF 10.150.1.32 cdh1 10.150.1.33 cdh2 10.150.1.34 cdh3 EOF
|
配置ssh免密
所有节点皆需执行
1 2 3 4
| ssh-keygen -t rsa ssh-copy-id -i ~root/.ssh/id_rsa.pub root@cdh1 ssh-copy-id -i ~root/.ssh/id_rsa.pub root@cdh2 ssh-copy-id -i ~root/.ssh/id_rsa.pub root@cdh3
|
系统参数设置
所有节点皆需执行
1 2 3 4 5 6
| sysctl vm.swappiness=10 echo 'vm.swappiness=10'>> /etc/sysctl.conf echo never > /sys/kernel/mm/transparent_hugepage/defrag echo never > /sys/kernel/mm/transparent_hugepage/enabled echo 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' >> /etc/rc.local echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local
|
CM安装
安装MySQL
主节点安装即可,这里采用使用我编写的mysql安装脚本一键安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| #! /bin/bash GROUP="mysql" USER="mysql" MYSQL_HOME="/usr/local/mysql/" MYSQL_DATA_HOME="/data/mysql/data" MYSQL_VERSION="mysql-5.7.33-linux-glibc2.12-x86_64" DOWNLOAD_PATH="/usr/local/src" if [ $(id -u) != "0" ];then echo -e "\033[31m Error: You must be root to run this script! \033[0m" exit 1 fi #root账号校验 ping -c 1 -W 1 baidu.com &> /dev/null || echo -e "\033[5;31m Network is not working, Please check\033[0m" ping -c 1 -W 1 baidu.com &> /dev/null || exit 4 #网络检查
rpm -e --nodeps `rpm -qa | grep mariadb` #卸载自带mariadb
setenforce 0 sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config && systemctl stop firewalld #关闭selinux和防火墙
echo "=================================start install mysql===================================" if [ -z $(cat /etc/group|awk -F: '{print $1}'| grep -w "$GROUP") ] then groupadd $GROUP if(( $? == 0 )) then echo "group $GROUP add sucessfully!" fi else echo "$GROUP is exsits" fi if [ -z $(cat /etc/passwd|awk -F: '{print $1}'| grep -w "$USER") ] then adduser -g $GROUP $USER if (( $? == 0 )) then echo "user $USER add sucessfully!" fi else echo "$USER is exsits" fi for i in wget do yum -y install $i done >/dev/null echo "==================================downloading mysql====================================" if [ ! -f "${DOWNLOAD_PATH}/${MYSQL_VERSION}.tar.gz" ]; then wget https://cdn.mysql.com//Downloads/MySQL-5.7/${MYSQL_VERSION}.tar.gz -P ${DOWNLOAD_PATH} >/dev/null fi if(( $? == 0 )) then echo "MySQL DownLoad sucessfully!" else echo "MySQL DownLoad failed!" exit 1 fi cd ${DOWNLOAD_PATH} echo "=================================unpackaging mysql=====================================" tar xzvf ${MYSQL_VERSION}.tar.gz -C /usr/local/ mv /usr/local/${MYSQL_VERSION} /usr/local/mysql if [ -s /etc/my.cnf ]; then mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%M%S`.bak fi cat << EOF >/etc/my.cnf [mysqld] bind-address=0.0.0.0 #绑定的IP port=3306 #mysql占用的端口 basedir=/usr/local/mysql #mysql安装目录 datadir=/data/mysql/data #mysql数据目录 socket=/tmp/mysql.sock #socket位置 log-error=/data/mysql/logs/mysql.err #error日志路径 pid-file=mysql.pid #进程id文件 #character config character_set_server=utf8mb4 #编码格式 symbolic-links=0 #关闭符号链接 explicit_defaults_for_timestamp=true lower_case_table_names=1 #不区分大小写 log_bin =/data/mysql/binlog/mysql-bin #logbin文件路径 binlog_format=row #binlog max_connections =1024 #mysql最大连接数 server-id=1 #数据库服务器ID,配置主从或者集群时 server id必须唯一 sync_binlog=1 #二进制日志文件刷新到磁盘上 expire_logs_days = 30 #binlog日志 超过30天的自动清理 slow_query_log = 1 #启用慢查询日志 long_query_time = 2 #慢查询时间 slow_query_log_file=/data/mysql/logs/slow.log #慢查询日志路径 EOF mkdir -p /data/mysql/{binlog,data,logs} chown -R mysql:mysql $MYSQL_HOME chown -R mysql:mysql /data/mysql/ $MYSQL_HOME/bin/mysqld --initialize-insecure --user=$USER cp $MYSQL_HOME/support-files/mysql.server /etc/init.d/mysql chmod +x /etc/rc.d/init.d/mysql chkconfig --add mysql echo "export PATH=$PATH:/usr/local/mysql/bin/" >>/etc/profile source /etc/profile /etc/init.d/mysql start echo "==========================Mysql installation completed================================" exit 0
|
mysql 设置密码
1 2
| use mysql; set password for root@localhost = password('123456');
|
mysql开启远程连接
1 2
| update user set host = '%' where user = 'root'; FLUSH PRIVILEGES;
|
mysql 创建表
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| mysql> create database activity default character set = 'utf8'; Query OK, 1 row affected (0.02 sec)
mysql> create database hive default character set = 'utf8'; Query OK, 1 row affected (0.06 sec)
mysql> create database hue default character set = 'utf8'; Query OK, 1 row affected (0.02 sec)
mysql> create database oozie default character set = 'utf8'; Query OK, 1 row affected (0.05 sec)
mysql> create database reports default character set = 'utf8'; Query OK, 1 row affected (0.05 sec)
|
配置MySQL驱动
每个节点都需安装
1 2 3
| wget https://cdn.mysql.com//archives/mysql-connector-java-5.1/mysql-connector-java-5.1.46.tar.gz && mkdir -p /usr/share/java
tar zxvf mysql-connector-java-5.1.46.tar.gz && cp mysql-connector-java-5.1.46/mysql-connector-java-5.1.46-bin.jar /usr/share/java/mysql-connector-java.jar
|
安装CM
搭建本地yum源
注:任意节点搭建即可,这里采用主节点搭建
1 2 3 4 5 6 7 8
| #更新yum源httpd yum -y install httpd #查看httpd状态 systemctl status httpd.service #启动httpd service httpd start #配置httpd永久生效(重启生效) chkconfig httpd on
|
1 2 3 4 5 6
| #更新yum源yum-utils createrepo yum -y install yum-utils createrepo #进入yum源路径 cd /var/www/html/ #创建cm文件夹 mkdir cm
|
上传资源文件到httpd文件路径
官方地址:https://docs.cloudera.com/documentation/enterprise/6/release-notes/topics/cm-retrofit-auth-downloads.html
注:自2021年2月1日起,所有CDH和Cloudera Manager的下载都需要用户名和密码,教程这里选择以前下载的资源文件。
百度网盘:https://pan.baidu.com/s/1j4BpzMJ53UblqjZBW5RO6Q 提取码:4f2s
创建本地源
1
| createrepo /var/www/html/cm/
|
创建repo
1 2 3 4 5 6 7
| vim /etc/yum.repos.d/cloudera-manager.repo #添加如下内容 [cloudera-manager] name=Cloudera Manager, Version yum baseurl=http://10.150.1.32/cm gpgcheck=0 enabled=1
|
更新yum源
1 2
| yum clean all yum makecache
|
验证
1
| yum list | grep cloudera-manager
|
分发repo文件
1 2
| scp /etc/yum.repos.d/cloudera-manager.repo root@cdh2:/etc/yum.repos.d/ scp /etc/yum.repos.d/cloudera-manager.repo root@cdh3:/etc/yum.repos.d/
|
安装JDK
所有节点,皆需安装
1
| yum -y install oracle-j2sdk1.8
|
cdh1节点安装
1 2 3
| yum -y install cloudera-manager-daemons yum -y install cloudera-manager-server yum -y install cloudera-manager-agent
|
cdh2和cdh3节点安装
1 2
| yum -y install cloudera-manager-daemons yum -y install cloudera-manager-agent
|
配置CDH数据库
1
| /opt/cloudera/cm/schema/scm_prepare_database.sh mysql -hlocalhost -uroot -p scm scm
|
CDH安装
上传文件到/opt/cloudera/parcel-repo 目录 并复制sha文件
1
| cp CDH-6.2.0-1.cdh6.2.0.p0.967373-el7.parcel.sha1 CDH-6.2.0-1.cdh6.2.0.p0.967373-el7.parcel.sha
|
修改所属组权限 cloudera-scm
如下图所示
启动cloudera-manager-server
1
| systemctl enable cloudera-scm-server && systemctl start cloudera-scm-server
|
登入web控制台,进行服务的部署(cdh1节点的IP+7180端口,帐号密码默认都是admin)
继续下一步
同意许可
选择企业试用版
开始进行集群的安装
填写集群名字
填写主机名并点击搜索按钮
填写本地yum源地址并检查cdh版本是否和上传的文件一致
jdk之前的步骤已安装,现在直接下一步即可
输入统一的服务器密码
开始安装agent
agent安装完成
安装Parcels
性能检查
选择服务安装
数据库配置
至此,cdh集群搭建完成
参考来源
1.CDH和CM介绍及搭建
2.CDH 安装与部署