0
点赞
收藏
分享

微信扫一扫

CDH搭建(一)——环境准备

蓝莲听雨 2022-04-14 阅读 47
大数据

前言-虚拟机安装

Centos 7 

master :192.168.44.131

slave01:192.168.44.128

slave02:192.168.44.130

一、环境准备

1.1 配置hosts映射

# vim /etc/hosts

127.0.0.1 localhost  localhost
::1     localhost       localhost.localdomain   localhost6      localhost6.localdomain6
192.168.44.131 master master
192.168.44.128 slave01 slave01
192.168.44.130 slave02 slave02

1.2 网络配置

# vi /etc/sysconfig/network
--每台机器都要配置

【master】
NETWORKING=yes
HOSTNAME=master
GATEWAY=192.168.44.1

【slave01】
NETWORKING=yes
HOSTNAME=slave01
GATEWAY=192.168.44.1

【slave02】
NETWORKING=yes
HOSTNAME=slave02
GATEWAY=192.168.44.1

1.3 SSH免密登录

配置master对slave01、slave02两台服务器免密登录。

CDH服务开启与关闭是通过server和agent来完成的,所以这里不需要配置SSH免密登录,但是为了我们分发文件方便,在这里我们也配置SSH。
1)生成公钥和私钥:

# ssh-keygen -t rsa

--然后敲(三个回车),就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)

2)将公钥拷贝到要免密登录的目标机器上

# ssh-copy-id master
# ssh-copy-id slave01
# ssh-copy-id slave02

3)重复1和2的操作

 配置slave01对master、slave01、slave02三台服务器免密登录;

 配置slave02对master、slave01、slave02三台服务器免密登录。

1.4集群同步脚本


  在每台机器的/root目录下创建bin目录,并在bin目录下创建文件xsync.sh,

  chmod 777 xsync.sh

  文件内容如下:

#!/bin/bash
#1 获取输入参数个数,如果没有参数,直接退出
pcount=$#
if((pcount==0)); then
echo no args;
exit;
fi

#2 获取文件名称
p1=$1
fname=`basename $p1`
echo fname=$fname

#3 获取上级目录到绝对路径
pdir=`cd -P $(dirname $p1); pwd`
echo pdir=$pdir

#4 获取当前用户名称
user=`whoami`

#5 循环
for host in master slave01 slave02
do
        echo ------------------- $host --------------
        rsync -av $pdir/$fname $user@$host:$pdir
done

1.5 集群整体操作脚本

在每台机器的/root/bin目录下创建脚本xcall.sh

修改权限:chmod +x xcall.sh

测试:sh xcall.sh jps

脚本内容如下:

#! /bin/bash

for i in master slave01 slave02
do
        echo --------- $i ----------
        ssh $i "source /etc/profile ; $*"
done

1.6 关闭防火墙

--centos7之前的关闭方法
1、安装firewalld
yum -y install firewall

2、开机启动/禁用服务
systemctl enable/disable firewalld


--centos7关闭方法 【centos7后是使用的基于iptable的systemctl stop firewalld】
yum install iptables-services


3、启动/关闭服务
systemctl start/stop firewalld

4、查看服务状态
systemctl status firewalld

1.7 关闭SELINUX

安全增强型Linux(Security-Enhanced Linux)简称SELinux,它是一个 Linux 内核模块,也是Linux的一个安全子系统。为了避免安装过程出现各种错误,建议关闭,有如下两种关闭方法:

1)临时关闭(重启机器后会失效)

# setenforce 0

2)永久关闭(建议使用)

# vim /etc/selinux/config

--将SELINUX=enforcing 改为SELINUX=disabled

3)同步/etc/selinux/config配置文件

cd /root/bin
sh xsync.sh /etc/selinux/config 

--该脚本会批量修改其他机器的配置文件


4)重启master、slave01、slave02

# reboot

1.8 配置NTP时钟同步

1)确认是否需要安装 ntp 服务

[root@master java]# rpm -qa | grep ntp
python-ntplib-0.3.2-1.el7.noarch
ntpdate-4.2.6p5-29.el7.centos.2.x86_64   【ntpdate】
fontpackages-filesystem-1.44-8.el7.noarch
ntp-4.2.6p5-29.el7.centos.2.x86_64        【ntp】

2)若只有ntpdate而未见ntp,则需删除原有ntpdate,否则跳到 4)

# yum -y remove ntpdate-4.2.6p5-29.el7.centos.2.x86_64

3)重新安装ntp

# yum -y install ntp

4)启动ntpd并设置为开机自启

# sudo systemctl enable ntpd

# systemctl start ntpd

5)查看服务状态

# systemctl status ntpd

6) 检测时间同步情况

# ntpq -p

7)使用群发date命令查看结果

# cd /root/bin
# sh xcall.sh date

[root@master bin]# ll
total 8
-rwxr-xr-x. 1 root root 135 Apr 13 04:23 xcall.sh
-rwxrwxrwx. 1 root root 647 Apr 13 05:24 xsync
[root@master bin]# sh xcall.sh date
--------- master ----------
Wed Apr 13 08:11:37 UTC 2022
--------- slave01 ----------
Wed Apr 13 08:11:37 UTC 2022
--------- slave02 ----------
Wed Apr 13 08:11:37 UTC 2022

1.8 修改时区

1.查看系统当前的时区 # timedatectl
2.修改为中国时区    # timedatectl set-timezone Asia/Shanghai
  修改为世界时区    # timedatectl set-timezone UTC
3.时间不准确时校准时间  
  # yum install -y ntpdate
  # ntpdate us.pool.ntp.org
4.将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间((立即生效))
  # timedatectl set-local-rtc 1
5.查看硬件时间
  # hwclock --show

二、CM安装准备软件

2.1 安装JDK

# mkdir /usr/java
# tar -zxvf jdk-8u144-linux-x64.tar.gz -C /usr/java/
# vim /etc/profile
   在profile文件末尾添加JDK路径
    #JAVA_HOME
    export JAVA_HOME=/usr/java/jdk1.8.0_144
    export PATH=$PATH:$JAVA_HOME/bin
#source /etc/profile

# java -version

--将master中的JDK和环境变量分发到slave01、slave02两台主机
# cd /root/bin/
# sh xsync.sh /usr/java/
# sh xsync.sh /etc/profile

--分别在slave01、slave02上执行 source /etc/profile

2.2 安装Mysql


--查找是否安装MySQL
  # rpm -qa | grep mysql

--卸载rpm包   
  # rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64

--安装从网上下载文件的wget命令
  # yum -y install wget

--下载mysql的repo源
  # wget http://repo.mysql.com/mysql57-community-release-el6-10.noarch.rpm

-- 安装mysql-community-release-el7-5.noarch.rpm包
  # rpm -ivh mysql57-community-release-el6-10.noarch.rpm

--安装mysql
  # yum install mysql-server --nogpgcheck

  -- 安装过程中不加【--nogpgcheck】会报这个错误 
  -- Public key for mysql-community-server-5.7.37-1.el7.x86_64.rpm is not installed
  --报错原文
  --  Public key for mysql-community-server-5.7.37-1.el7.x86_64.rpm is not installed
  --  Failing package is: mysql-community-server-5.7.37-1.el7.x86_64
  --  GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

  --原因:CentOS7.X 安装mysql5.7的时候,GPG对于包的源key的验证没有通过
  --解决办法:绕过GPG验证成功安装
  --# yum install mysql-community-server --nogpgcheck

--启动数据库
  # service mysqld start

--开机自启动
  # chkconfig mysqld on

--查看密码A temporary password is generated for root@localhost: %bEiioEuo7h_
  # grep "password" /var/log/mysqld.log

--登陆数据库
  # mysql -u root -p

--首先需要设置密码的验证强度等级
  >> set global validate_password_policy=LOW;

--修改密码,这个版本需要密码是字母+数字
  >> SET PASSWORD = PASSWORD('abc123456'); 

--重新登陆
  # mysql -u root -p (abc123456)


- delete from user;
- GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'abc123456' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'abc123456' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'datalinux1' IDENTIFIED BY 'abc123456' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY 'abc123456' WITH GRANT OPTION;
grant all privileges on *.* to 'scm'@'localhost' identified by 'scm123456' with grant option;
grant all privileges on *.* to 'scm'@'datalinux1' identified by 'scm123456' with grant option;
grant all privileges on *.* to 'scm'@'127.0.0.1' identified by 'scm123456' with grant option;
grant all privileges on *.* to 'scm'@'%' identified by 'scm123456' with grant option;
- flush privileges;

举报

相关推荐

0 条评论