大数据集群hadoop环境搭建

1、集群规划

统一环境配置

[所有节点]IP地址设置

  • 修改Ip地址

vi /etc/sysconfig/network-scripts/ifcfg-ens33

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"  # 设置为静态ip static
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
NAME="ens33"  # 网卡的名称
DEVICE="ens33" # 设备的名称
ONBOOT="yes"  # 设置为yes, 表示开机启动
IPADDR="192.168.46.150"  # ip地址
PREFIX="24"  # 子网掩码
GATEWAY="192.168.46.2" # 网关
DNS1="114.114.115.115"  # DNS
  • 重启网络服务

systemctl restart network

  • 测试网络

ping www.baidu.com

如果可以ping通公网: 说明 ip地址和网关都配置正确

如果通过 ip addr 不能查看到ip地址, 说明配置有错误

如果可以ping通内网 192.168.46.1 但是不能ping通外网的话, 则说明网关配置有错误

[所有节点]设置主机名

  • 编辑主机名配置文件

vi /etc/hostname

hadoop01

[所有节点]设置域名映射解析

  • 编辑hosts文件

vi /etc/hosts

192.168.46.145 hadoop01 hadoop01

192.168.46.146 hadoop02 hadoop02

192.168.46.147 hadoop03 hadoop03

192.168.46.148 biz01 biz01

[所有节点]关闭防火墙和Selinux

  • 关闭防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service
  • 关闭Selinux

vi /etc/selinux/config
​
​
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

[所有节点]配置免密登录

  1. 在所有节点生成公钥和私钥

    ssh-keygen -t rsa

    后面直接所有的交互都敲回车 即可

  2. 拷贝公钥到每台服务器

    ssh-copy-id hadoop01

    ssh-copy-id hadoop02

    ssh-copy-id hadoop03

  3. 验证ssh登录

    ssh hadoop01

    exit # 退出ssh登录

[所有节点]配置服务器节点时钟同步

  1. 在所有节点安装ntpdate

    yum install -y ntpdate

  2. 增加定时任务

    crontab -e

    */1 * * * * /usr/sbin/ntpdate -u ntp4.aliyun.com > /dev/null 2>&1

[所有节点]安装常用软件

yum install -y vim
yum install -y net-tools
yum install -y lrzsz
yum install -y rsync
yum install -y wget

[所有节点]创建统一目录

mkdir -p /bigdata/{soft,server}

/bigdata/soft      安装文件的存放目录
/bigdata/server  软件安装的目录

3、定义同步数据脚本

[所有节点]安装软件rsync

yum install -y rsync

[hadoop01] 配置同步脚本

mkdir /root/bin
cd /root/bin
vim xsync

#!/bin/bash
#1 获取命令输入参数的个数,如果个数为0,直接退出命令 
paramnum=$#
echo "paramnum:$paramnum"
if (( paramnum == 0 )); then
    echo no params;
    exit;
fi
# 2 根据传入参数获取文件名称
p1=$1
file_name=`basename $p1` 
echo fname=$file_name
#3 获取输入参数的绝对路径 
pdir=`cd -P $(dirname $p1); pwd`
echo pdir=$pdir 
#4 获取用户名称 
user=`whoami`
#5 循环执行rsync
current=`hostname` 
nodes=$(cat /root/bin/works)
for host in $nodes; do 
  echo ------------------- $host -------------- 
  if [ "$host" != "$current" ];then
     rsync -rvl $pdir/$file_name $user@$host:$pdir
  fi
done

[hadoop01]创建works文件

cd /root/bin

vi workers

hadoop01
hadoop02
hadoop03

4、添加环境变量

vi /etc/profile.d/custom_env.sh
#! /bin/bash
# root/bin
export PATH=$PATH:/root/bin

source /etc/profile

设置文件执行权限

chmod u+x /root/bin/xsync

5、测试同步脚本

猜你喜欢

转载自blog.csdn.net/weixin_43889788/article/details/129486554