当前位置:   article > 正文

开源大数据集群部署(二)集群基础环境实施准备_大数据集群配置/etc/hosts

大数据集群配置/etc/hosts

作者:櫰木

环境准备

本次使用到的二进制软件包目录为:系统初始化前提是操作系统已完成安装、各个主机之间网络互通,系统常用命令已安装,本默认这些前提条件已具备,不在阐述。

1 主机环境初始化

安装centos系统完成后需要对主机进行初始化配置和验证工作,在所有主机上(hd1.dtstack.com-hd3)均要进行操作,并按照对应hosts修改主机名:
(主机名必须为xxx.xxx.com 匹配freeipa安装需求)
(1) 主机配置映射(操作权限root)

$ cat>>/etc/hosts <<EOF
172.16.104.226 hd1.dtstack.com
172.16.106.252 hd2.dtstack.com
172.16.107.127 hd3.dtstack.com
172.16.106.165 hd.dtstack.com
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

(2)关闭防火墙&selinux(操作权限root)

$ systemctl stop firewalld
$ systemctl disable firewalld
$ setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  • 1
  • 2
  • 3

(3) 创建集群系统用户(操作权限root)

系统用户属组用途
hadoophadoophadoop集群用户
mysqlhadoopmysql数据库用户
hdfshadoophadoop集群用户
trinohadooppresto集群用户
prometheusprometheus监控平台用户
grafanagrafana监控平台用户
zookeeperzookeeperzk集群用户
hivehadoophive组件用户
yarnhadoophadoop集群用户

创建hadoop集群所需用的的用户和用户组
创建示例如下:

[root@hd1.dtstack.com ~]$ remote_op.sh "groupadd hadoo p"
[root@hd1.dtstack.com ~]$ remote_op.sh "useradd hive -G hadoop"
[root@hd1.dtstack.com ~]$ remote_op.sh "echo hive | passwd --stdin hive"
  • 1
  • 2
  • 3

(4)安装java环境(操作权限root)
本次中java软件包安装目录在/root/bigdata

$ cd /opt/bigdata
$ tar -zvxf zulu11.60.19-ca-jdk11.0.17-linux_x64.tar.gz -C /opt
tar -zxvf jdk-8u281-linux-x64.tar.gz
ln -s  /opt/jdk1.8.0_281  /opt/java
  • 1
  • 2
  • 3
  • 4

2 配置ssh互信

ssh互信配置(操作权限hadoop)
在集群系统 hd1.dtstack.com-hd3.dtstack.com共3台设备上执行如下命令:

$ cd $HOME  #在hadoop当前目录下创建ssh互信
$ ssh-keygen -t rsa   #一路回车,不需要输入任何信息
  • 1
  • 2

将hd1.dtstack.com公钥添加到认证文件中,在hd1.dtstack.com主机root用户当前家目录下执行如下命令:
生产各自的keytab文件

ssh-keygen -t rsa
  • 1

用ssh-copy-id 把公钥复制到远程主机上,命令也要(以下命令ip需要填写所有节点ip并在每个节点均执行)

ssh-copy-id -i  .ssh/id_rsa.pub root@xxx.xxx.xxx
  • 1

以上命令在三个阶段均要执行

ssh互信验证
hd1.dtstack.com-hd3.dtstack.com主机上互相执行ssh登录命令验证,如下:

[hadoop@hd1.dtstack.com ~]$ ssh hd2.dtstack.com
  • 1

验证截图如下:
在这里插入图片描述
ssh命令执行过去,无报错表示ssh互信配置成功。
root和hdfs以及yarn权限ssh互信
同理操作,配置主机root权限和hdfs以及yarn权限全主机互信。

3 统一环境变量配置

环境变量分两个文件:/etc/profile和各用户下.bashrc(bash),建议/etc/profile根据规划好的目录结构,统一设置环境变量。本次设置将hadoop,zookeeper,hive,java环境变量整体设置完成

[root@hd1.dtstack.com ~]# cat >>/etc/profile.d/bigdata.sh<<EOF
#!/bin/bash
export HADOOP_HOME=/opt/hadoop
export HBASE_HOME=/opt/hbase
export SPARK_HOME=/opt/spark
export SPARK_CONF_DIR=/opt/spark/conf
export HBASE_CONF_DIR=/opt/hbase/conf
export HBASE_LIB=/opt/hbase/lib
export TEZ_HOME=/opt/tez
export TEZ_CONF_DIR=/opt/tez/conf
export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_HOME}/lib/native
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$TEZ_HOME/*:$TEZ_HOME/lib/*
export HADOOP_OPTS="-Djava.library.path=${HADOOP_HOME}/lib/native"
export LD_LIBRARY_PATH=$HADOOP_HOME/lib/native
export HADOOP_CONF_DIR=/opt/hadoop/etc/hadoop
export HIVE_HOME=/opt/hive
export HIVE_CONF_DIR=/opt/hive/conf
export PATH=$PATH:$HIVE_HOME/bin
export ZK_HOME=/opt/zookeeper
#export YARN_CONF_DIR=/opt/hadoop/etc/hadoop
export JAVA_HOME="/opt/java"
export PATH=$HADOOP_HOME/bin:$JAVA_HOME/bin:$ZK_HOME/bin:/opt/mysql/bin:$PATH
export HADOOP_CLASSPATH=`hadoop classpath`

EOF
  • 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

4 系统调优

hd1.dtstack.com-hd3.dtstack.com所有机器上都要执行,且以root权限执行
调整swap、内存分配、网络连接参数

$ cat>>/etc/sysctl.conf <<EOF
#避免使用swap
vm.swappiness = 1
#修改内存分配策略
vm.overcommit_memory=2
vm.overcommit_ratio=90
#网络连接上限
net.core.somaxcomm=32768
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

增大同时打开文件描述符

$ cat>>/etc/security/limits.conf <<EOF
hadoop  soft   nofile   32768
hadoop hard nofile 65536
hadoop soft   nproc   32768
hadoop hard nproc 65536
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

关闭THP

$ cat>>/etc/rc.local <<EOF
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

5 NTP服务配置

安装
在hd1.dtstack.com-hd3.dtstack.com各个主机上root权限下执行:

$ yum install -y ntp
  • 1

配置时间同步服务端
在hd1.dtstack.com主机root权限下执行

ntp配置

$ cat /etc/ntp.conf|grep -v '#'|grep -v ^$
driftfile /var/lib/ntp/drift     #存放记录时间误差
restrict default nomodify notrap nopeer noquery   #默认拒绝所有来源访问
restrict 127.0.0.1  #开放本机的任何访问
restrict ::1
restrict 172.16.104.0 mask 255.255.255.0 nomodify notrap  #允许104网段机器参与ntp同步
includefile /etc/ntp/crypto/pw    
keys /etc/ntp/keys
server  172.16.104.226    #时间同步服务器
server  127.127.1.0       #当上面时间不可用时,以本地时间作为时间服务
fudge   127.0.0.1 stratum 10
disable monitor
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

说明:

  • server 172.16.104.226表示内网时间同步服务器,其余机器都从这台同步时间
  • server 172.16.104.226可以替换成其他时间服务中心IP(看生产环境配置)

ntp服务启动和验证
启动

service ntpd start
  • 1

验证

service ntpd status
  • 1

在这里插入图片描述
Active状态为running表示服务启动成功

配置时间同步客户端
在hd2.dtstack.com主机root权限下执行

配置时间同步服务源

[root@hd2.dtstack.com ~]# cp /etc/ntp.conf /etc/ntp.conf.bak
[root@hd2.dtstack.com ~]# cat >/etc/ntp.conf<<EOF
driftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict ::1
server 172.16.104.226
restrict 172.16.104.226 nomodify notrap noquery
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

手动同步时间(建议第一次手动同步)

$ ntpdate -u 172.16.104.226
  • 1

在这里插入图片描述
拉起同步服务

service ntpd start
  • 1

检查方法同上
同步到其他节点(hd3.dtstack.com、hd2.dtstack.com)

[root@hd2.dtstack.com ~]# scp /etc/ntp.conf root@hd2.dtstack.com:/etc/
  • 1

启动其余主机(hd3.dtstack.com)上ntpd服务

[root@hd2.dtstack.com ~]# ssh hd3.dtstack.com 'service ntpd start'
[root@hd2.dtstack.com ~]# ssh hd2.dtstack.com'service ntpd start'
  • 1
  • 2

检查其余机器(hd3.dtstack.com)上ntpd服务启动状态

[root@hd2.dtstack.com ~]# ssh hd3.dtstack.com 'service ntpd status'
[root@hd2.dtstack.com ~]#ssh hd2.dtstack.com'service ntpd start''
  • 1
  • 2

检查连接情况

[root@hd2.dtstack.com ~]# ntpq -p
  • 1

在这里插入图片描述

6 自动化同步脚本

配置文件同步脚本【1】remote_scp.sh

[root@hd1.dtstack.com software]# cat /root/bin/remote_scp.sh
#!/bin/bash
for i in hd{2..3}
do
 #echo $i
 if [  -d $1  ]
then
 echo -e '\033[33m 当前主机为'$i',传输文件为'$1'\033[0m'
 scp -rp $1 $i:$2
else
 #echo "当前节点为$,传输文件为$1"
 echo -e '\033[33m 当前主机为'$i',传输文件为'$1'\033[0m'
 scp $1 $i:$2
fi
done
status=`echo $?`
if [ $status -eq 0 ]
then
 echo -e "$1文件传输完成"
else
 echo -e "请检查传入参数"
fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

使用案例:
格式:remote_scp.sh 源目录 目标目录
在这里插入图片描述
说明:将test.log 分发到hd1.dtstack.com-hd3.dtstack.com/root目录下
配置文件同步脚本【2】remote_op.sh

[root@hd1.dtstack.com ~]# cat /root/bin/remote_op.sh
#!/bin/bash
for i in hd2.dtstack.com hd3.dtstack.com
do
  echo  -e '\033[33m 当前主机为'$i'\033[0m'
  ssh $i $1
done
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

使用案例:
格式:remote_op.sh “执行命令内容”
在这里插入图片描述

7 软件包仓库

建议在安装hadoop集群前,提前将所需安装的二进制软件包,统一存放软件包仓库中。
本次使用的软件包都在主机hd1.dtstack.com上/root/bigdata下

8 keytab生成脚本

在所有节点均需执行此操作
/root/bigdata
vi getkeytabs.sh

set -x
 
CMKEYTAB="/data/kerberos/apache-user.keytab"
CMUSER="apache-user"
REALM="DTSTACK.COM"
IPASERVER="hd.dtstack.com"
 
hosts=`hostname`
DEST="$1"
FULLPRINC="$2"/${hosts}@${REALM}
USER=$2
# Passwd based kinit
#echo PASSWORD | kinit $CMUSER@$REALM
 
# Or per keytab (keytab needs to be generated before)
kinit -k -t $CMKEYTAB $CMUSER@$REALM
 
PRINC=$( echo $FULLPRINC | sed "s/\@$( echo $REALM )//" )
 
echo $PRINC

echo Retrieving keytab for $FULLPRINC for $DEST
 
echo Checking for existing service principle
if ipa service-find $FULLPRINC; then
echo Service principle found
else
echo Service principle not created, creating
ipa service-add $FULLPRINC --pac-type=NONE
fi
 
echo Ensuring service allows
ipa service-allow-create-keytab --users=$CMUSER $FULLPRINC
ipa service-allow-retrieve-keytab --users=$CMUSER $FULLPRINC
 
if ipa service-show $FULLPRINC | grep 'Keytab' | grep 'False'; then
echo Creating keytab for $FULLPRINC for $DEST
ipa-getkeytab -s $IPASERVER -p $PRINC -k $DEST -e rc4-hmac,aes256-cts,aes128-cts
else
echo Retrieving keytab for $FULLPRINC for $DEST
ipa-getkeytab -r -s $IPASERVER -p $PRINC -k $DEST
fi

chmod 644 $DEST
chown $USER:$USER $DEST
 
kdestroy
 
exit 0;
  • 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

备注

上文中$ 表示系统命令解释器开始符号,且表示所有机器都要执行,如出现[hadoop@hd1.dtstack.com ~]$表示,只在hd1.dtstack.com主机hadoop用户下执行

更多技术信息请查看云掣官网https://yunche.pro/?t=yrgw

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/410525
推荐阅读
相关标签
  

闽ICP备14008679号