On the basis of Linux virtual machine environment to build Hadoop

1 main steps

  • Network Configuration
  • Modify the hostname
  • Turn off the firewall
  • Close SELinux
  • Installation jdk
  • Increase user hadoop
  • Configuring ssh trust
  • Hadoop configuration
Cluster deployment plan
Five servers,
A master node: nn1.hadoop, Master (the HA)
From a node: nn2.hadoop, Slave
Three working node:
s1.hadoop、s2.hadoop、s3.hadoop (work1     work2    work3)
nn1.hadoop machine as a working machine. whoami ifconfig
In actual production there should be an operating machine ( stepping stones)

 

 2 base environment to build

2.1 Configuration Ali cloud yum source

1) Installation sz rz tool for later upload and download files rz sz

yum install -y lrzsz
2) Download the repo file
3) with rz downloaded Centos-7.repo  upload files to a directory on a Linux system 
4) Back up and replace the repo file system
cp Centos- 7 .repo /etc/yum.repos.d/  
cd /etc/yum.repos.d/  
mv CentOS -Base.repo CentOS- Base.repo.bak 
mv Hundreds - 7 .repo CentOS Base.repo

5) execute the command yum update source

Clean All yum 
# server package information downloaded to the local computer cached 
yum makecache 
yum Update -y

Configured.

2.2 installation of common software

yum install -y openssh-server vim gcc gcc-c++ glibc-headers bzip2-devel lzo-devel curl wget openssh-clients zlib-devel autoconf automake cmake libtool openssl-devel fuse-devel snappy-devel telnet unzip zip net-tools.x86_64 firewalld systemd ntp

2.3 turn off the firewall

Check firewall status: firewall-cmd --state
Turn off the firewall: systemctl stop firewalld.service
Disable the firewall boot: systemctl disable firewalld.service
See if service startup: systemctl is-enabled firewalld.service

2.4 Close SELinux

View off
/ Usr / sbin / sestatus -v
Close method
vim /etc/selinux/config
The documents in the SELINUX = disabled

 To restart the server before installing the software

reboot
After starting with
/ Usr / sbin / sestatus -v View modify the state of selinux
View sure that the firewall is turned off: systemctl is-enabled firewalld.service
You can begin installing the software

Install JDK 2.5

2.5.1 JDK Download

Address: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

 

 

2.5.2 JDK installation

1) The installation file upload Linux systems rz command
After entering the specified directory, with the rz command to upload the file to the current directory
 
2) Install JDK

        Because it is rmp format file can be installed directly

rpm -ivh jdk-8u144-linux-x64.rpm

-ivh: installation progress during installation

JDK 2.5.3 configuration environment variable

1) modify the system environment variables file / etc / profile, at the end of the file append the following
export JAVA_HOME=/usr/java/jdk1.8.0_144
export JRE_HOME=$JAVA_HOME/jre
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
(安装目录默认在   /usr/java, 配置环境变量在 /etc/profile 文件中)
备注:export 用于设置或显示环境变量。  一个变量创建时,它不会自动地为在它之后创建的shell进程所知。而命令export 可以向后面的shell传递变量的值。
2)使修改生效,并配置JDK
    一定 要执行source 刷新一下
#使修改生效
source /etc/profile
#查看系统变量值
echo $PATH
#检查JDK 配置情况
java -version
NTP服务器 --> 阿里云 --> 一个小时同步一回
每台电脑都需要做以上工作 那么我们需要先做一个母盘 然后通过克隆的方式再创建自己的集群
集群健康运行的标准是 每台电脑的时间都是一样的
 
#命令:
crontab -e
0 * * * * /usr/sbin/ntpdate time1.aliyun.com >> /tmp/autontpdate 2>&1

2.6 修改主安装常用软件主机名

        (配置host是为了让计算机的ip和名字绑定,以后访问名字就行了)
hostnamectl set-hostname nn1.hadoop
#修改完后用hostname可查看当前主机名 // hostname是计算机名
hostname

2.7 创建hadoop 用户并设置 hadoop 用户密码

#创建hadoop用户
useradd hadoop

#给hadoop用户设置密码
000000

2.8 给hadoop用户,配置SSH密钥

2.8.1 通过普通方法添加hadoop用户在wheel组中

第一步。# useradd hadoop

setp2: passwd hadoop
配置秘钥之前,先配置hosts文件(/etc/hosts)
hadoop用户进入whell组后,有root部分权限,并且可以免密切换到root
step3: 修改权限验证,进入。# vi /etc/pam.d/su
step4: 打开两个功能:①只允许wheel组切换到root,②wheel进入root免密
            auth sufficient pam_wheel.so trust use_uid (去掉前面的#即可)
            auth required pam_wheel.so use_uid  (去掉前面的#即可) 
            可以用set命令,在不打开文件的时候就能替换文件内容
step5:将hadoop加入wheel组,先看一下系统中的组:cat  /etc/group
        # gpasswd  -a  hadoop  wheel  (将hadoop用户追加到wheel组中)
完成

2.8.2 配置hadoop用户的SSH免密

配置SSH密钥的目的:使得多台机器间可以免密登录。
实现原理:
使用ssh-keygen在linux01 上生成private和public密钥,将生成的public密钥拷贝到远程机器linux02 上后,就可以使用ssh命令无需密码登录到另外一台机器linux02上。如果想互相登录,则要把公钥私钥都拷贝到远程机器linux02 上。
    (备注:如果用ssh密钥登录,需要用户的家目录是700,.ssh目录700,公钥文件们必须是600权限,ssh针对某个用户,在多台计算机中进行操作的时候是免密的。ssh必须是非root用户的配置,如果不是很紧急,root一般不会ssh. 所以hadoop集群是针对某个用户的配置,让一个用户可以操作多台电脑)
#切换到hadoop用户
su – hadoop                       
#创建.ssh目录
mkdir ~/.ssh   
#生成ssh公私钥                         
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''    
#输出公钥文件内容并且重新输入到~/.ssh/authorized_keys文件中  ,必须放置authorized_keys文件中才能被#linux识别,不然被认为是自己的公钥。     
cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys 
#给~/.ssh文件加上700权限
chmod 700 ~/.ssh        
#给~/.ssh/authorized_keys加上600权限       
chmod 600 ~/.ssh/authorized_keys 

2.9 禁止非 whell 组用户切换到root,配置免密切换root

   通常情况下,一般用户通过执行“su -”命令、输入正确的root密码,可以登录为root用户来对系统进行管理员级别的配置。
    但是,为了更进一步加强系统的安全性,有必要建立一个管理员的组,只允许这个组的用户来执行 “su -” 命令登录为 root 用户,而让其他组的用户即使执行 “su -” 、输入了正确的 root 密码,也无法登录为 root 用户。在UNIX和Linux下, 这个组的名称通常为 “wheel” 。
1)修改/etc/pam.d/su配置
su 时要求用户加入到wheel组
修改/etc/pam.d/su文件,将“#auth\t\trequired\tpam_wheel.so”,替换成“auth\t\trequired\tpam_wheel.so”
sed -i 's/#auth\t\trequired\tpam_wheel.so/auth\t\trequired\tpam_wheel.so/g' '/etc/pam.d/su'
命令说明:
修改某个文件,并替换文件里的内容,命令格式:
sed -i 's/要被取代的字串/新的字串/g' '文件名'

-i :直接修改读取的文件内容,而不是输出到终端。

 

 

2)修改/etc/login.defs文件
只有wheel组可以su 到root
cp /etc/login.defs /etc/login.defs_back      先备份一个
# 把“SU_WHEEL_ONLY yes”字符串追加到/etc/login.defs文件底部
echo "SU_WHEEL_ONLY yes" >> /etc/login.defs 

tail /etc/login.defs     从文件底部查看

 

 3) 添加用户到管理员,禁止普通用户su 到 root

#把hadoop用户加到wheel组里

#查看wheel组里是否有hadoop用户

 

 

 

 4)用vuser1 用户验证一下,由于vuser1 没有在wheel 组里,所以没有 su - root 权限。

 

 5)修改/etc/pam.d/su文件,将字符串“#auth\t\tsufficient\tpam_wheel.so”替换成“auth\t\tsufficient\tpam_wheel.so”

sed -i 's/#auth\t\tsufficient\tpam_wheel.so/auth\t\tsufficient\tpam_wheel.so/g' '/etc/pam.d/su' 

验证免密码切换到 root 用户

 

 

2.10 配置hosts 文件

        在克隆机器前,配置nn1 机器的 /etc/hosts 文件,文件内需要配置nn1、nn2、s1、s2、s3 所有机器的IP 和 主机名。修改/etc/hosts文件,vim /etc/hosts。追加以下内容,不要把之前的内容删掉。

192.168.142.180 nn1.hadoop
192.168.142.181 nn2.hadoop
192.168.142.182 s1.hadoop
192.168.142.183 s2.hadoop
192.168.142.184 s3.hadoop

2.11 克隆4台机器

        执行完上面的命令,一个基础的linux系统就配置好了。然后把这个nn1.hadoop虚拟机导出,再根据这个导出的虚拟机创建4个linux系统。

        其中:nn2.hadoop: 从节点

                   s1.hadoop、s2.hadoop、s3.hadoop:三个工作节点

并用hadoop用户,测试彼此之间是否能进行ssh通信。

2.11.1 虚拟机克隆

右键 nn1 机器→ 管理 → 克隆。

克隆完成后,需要给克隆的虚拟机配置静态IP。

2.11.1.1 配置静态IP

1)查看网卡硬件名称和基本信息

ip add 

虚拟机会给每个克隆的虚拟机创建新网卡,如上面的 ens33 。
如果网卡设备信息中没有显示IP,则需要配置配置文件
cd /etc/sysconfig/network-scripts/

 

 ifcfg-xxx 中的xxx 与网卡名相同后,配置ifcfg-xxx 文件
如果想一次删除所有内容可以先将光标 G 固定在最后一行 然后使用 :1,. d 的方式删除全部内容
TYPE="Ethernet"
BOOTPROTO="static"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="ens33"
UUID="fbe09adb-60e9-4e66-be20-9104c63a50c2"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=192.168.92.131
PREFIX=24
GATEWAY=192.168.92.2
DNS=192.168.92.2

需要修改的内容,配置完的网卡文件

 

 配置完后,用systemctl restart network.service重启网络服务,当前的ssh就连接不上了,是因为网络IP被改变成你自己设置的静态IP。

用 ip add 查看网卡信息

用 ping  www.baidu.com 看是否能连接外网。
如果上不了网执行以下操作。

2.11.1.2 配置 /etc/resolv.conf  的 nameserver

cat /etc/resolv.conf    查看nameserver是否被设置正确
 vim /etc/resolv.conf  修改文件,如果不存在nameserver就在文件下面添加,如果存在就修改,把nameserver 设置成自己对应的DNS。

2.11.1.3 停止掉NetworkManager服务

systemctl stop NetworkManager.service  停止NetworkManager服务
systemctl disable NetworkManager.service   并设置成开机不启动
systemctl restart network.service            之后重启网络服务

2.11.2 修改每个机器的主机名

修改4台的主机名
hostnamectl set-hostname nn2.hadoop
hostnamectl set-hostname s1.hadoop
hostnamectl set-hostname s2.hadoop
hostnamectl set-hostname s3.hadoop

 

Guess you like

Origin www.cnblogs.com/yoyowin/p/12008773.html