Hadoop集羣搭建-02安裝配置Zookeeperlinux
整個搭建hadoop集羣的流程,包括vim
首先啓動一臺centos7的虛擬機,配置華爲雲yum源centos
[root@localhost ~]# cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak [root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo [root@localhost ~]# yum clean all [root@localhost ~]# yum makecache [root@localhost ~]# yum update -y
而後安裝一些亂七八糟的經常使用軟件安全
[root@localhost ~]# 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
[root@localhost ~]# firewall-cmd --state [root@localhost ~]# systemctl stop firewalld.service [root@localhost ~]# systemctl disable firewalld.service [root@localhost ~]# systemctl is-enabled firewalld.service
[root@localhost ~]# /usr/sbin/sestatus -v 查看selinux的狀態 [root@localhost ~]# vim /etc/selinux/config #修改狀態爲關閉 SELINUX=disabled [root@localhost ~]# reboot
下載地址http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htmlbash
[root@localhost ~]# rpm -ivh jdk-8u144-linux-x64.rpm [root@localhost ~]# vim /etc/profile #修改環境變量,在文件末尾添加以下 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
修改後只是對應這次用戶這次會話生效,但願永久全局生效,就要網絡
[root@localhost ~]# source /etc/profile
[root@localhost ~]# yum install -y ntp-tools [root@localhost ~]# ntpdate ntp1.aliyun.com
[root@localhost ~]# useradd hadoop [root@localhost ~]# passwd hadoop
只容許wheel組內用戶能夠經過su - root命令登陸root用戶,提升安全性
[root@localhost ~]# sed -i 's/#auth\t\trequired\tpam_wheel.so/auth\t\trequired\tpam_wheel.so/g' '/etc/pam.d/su' [root@localhost ~]# cp /etc/login.defs /etc/login.defs_bak [root@localhost ~]# echo "SU_WHEEL_ONLY yes" >> /etc/login.defs
添加hadoop用戶進wheel組
[root@localhost ~]# gpasswd -a hadoop wheel [root@localhost ~]# cat /etc/group | grep wheel 查看hadoop有沒有加入到wheel組
[root@localhost ~]# vim /etc/hosts 192.168.10.3 nn1.hadoop #這個是本機ip,主機名稍後一塊兒配置 192.168.10.4 nn2.hadoop 192.168.10.5 s1.hadoop 192.168.10.6 s2.hadoop 192.168.10.7 s3.hadoop
完成後_分別更改每一臺_的主機名並配置靜態ip,要求和上面hosts文件內的一致並對應
[root@localhost ~]# hostnamectl set-hostname nn1.hadoop [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="static" #這裏修改成static IPADDR="192.168.10.3" #這裏添加爲你的每臺虛擬機對應的ip NETMASK="255.255.255.0" #添加 GATEWAY="192.168.10.2" #添加爲你虛擬機內的網關 DNS="192.168.10.2" #添加 NM_CONTROLLED="no" #添加,必然改完文件自動生效,可能直接網絡就掛掉了 DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME="ens33" UUID="49f05112-b80b-45c2-a3ec-d64c76ed2d9b" DEVICE="ens33" ONBOOT="yes"
[root@localhost ~]# systemctl stop NetworkManager.service 中止網絡管理服務 [root@localhost ~]# systemctl disable NetworkManager.service 開機禁止自啓動 [root@localhost ~]# systemctl restart network.service 重啓網絡服務
至此咱們應該有五臺虛擬機,都按照以下ip和主機名配置對應好,五臺都設置好了hosts文件
192.168.10.3 nn1.hadoop
192.168.10.4 nn2.hadoop
192.168.10.5 s1.hadoop
192.168.10.6 s2.hadoop
192.168.10.7 s3.hadoop而後防火牆、selinux都已經關閉,都正確安裝jdk8並配置好環境變量,都正確新建了hadoop用戶組並將其添加進wheel組。
上邊的操做都是在root用戶下進行的,如今切換到hadoop用戶下進行之後的幾乎全部操做。
[root@nn1 ~]# su - hadoop 注意這裏的「-」,意味着用戶和環境變量同時切換 [hadoop@nn1 ~]$ 這時候表明進入到了hadoop用戶,還有#和$分別表明root用戶和普通用戶的身份區別
開始搭建ssh免密
思路是首先在每一臺機器上分別建立各自的key,最後把這些key.pub彙總到~/.ssh/authorized_keys文件中再一塊兒分發給全部機器,這時候就實現了五臺機器的互相免密ssh訪問。
[hadoop@nn1 ~]$ pwd 查看當前路徑,確保在hadoop用戶的home下 /home/hadoop [hadoop@nn1 ~]$ mkdir .ssh [hadoop@nn1 ~]$ chmod 700 ./.ssh [hadoop@nn1 ~]$ ll -a drwx------ 2 hadoop hadoop 132 7月 16 22:13 .ssh
[hadoop@nn1 ~]$ ssh-keygen -t rsa 建立key文件
這時候完成了nn1機器的設置(nn1做爲咱們之後的主要操做機器)。按照上邊的步驟把剩下的4臺機器也弄好,而後分別把其餘的4臺機器的./ssh/id_rsa.pub重命名(防止重複和之外替換),再發送到nn1的./ssh/下
[hadoop@nn2 ~]$ scp ~/.ssh/id_rsa.pub hadoop@nn1.hadoop ~/.ssh/id_rsa.pubnn2
這時候nn1的~/.ssh/下應該有包括本身在內的5個pub文件(不重名),而後把他們都_追加_到下邊的文件中
[hadoop@nn1 ~]$ touch authorized_keys [hadoop@nn1 ~]$ chmod 600 authorized_keys [hadoop@nn1 ~]$ cat ./ssh/id_rsa.pub >> authorized_keys [hadoop@nn1 ~]$ cat ./ssh/id_rsa.pubnn2 >> authorized_keys [hadoop@nn1 ~]$ cat ./ssh/id_rsa.pubs1 >> authorized_keys …………
而後最後把這個文件批量發送到其他4臺機器上(忘了寫批量腳本了,因此用scp命令依次發送吧)
至此5臺機器的ssh免密互相訪問配置結束,咱們能夠分別測試(略)。
由於有5臺機器啊,不少操做都要一塊兒動,因此須要批量執行腳本。
#文件名:ips "nn1.hadoop" "nn2.hadoop" "s1.hadoop" "s2.hadoop" "s3.hadoop"
#!/bin/bash #文件名:ssh_all.sh RUN_HOME=$(cd "$(dirname "$0")"; echo "${PWD}") NOW_LIST=(`cat ${RUN_HOME}/ips`) SSH_USER="hadoop" for i in ${NOW_LIST[@]}; do f_cmd="ssh $SSH_USER@$i \"$*\"" echo $f_cmd if eval $f_cmd; then echo "OK" else echo "FAIL" fi done
#!/bin/bash #文件名:ssh_root.sh RUN_HOME=$(cd "$(dirname "$0")"; echo "${PWD}") NOW_LIST=(`cat ${RUN_HOME}/ips`) SSH_USER="hadoop" for i in ${NOW_LIST[@]}; do f_cmd="ssh $SSH_USER@i ~/exe.sh \"$*\"" echo $f_cmd if eval $f_cmd; then echo "OK" else echo "FAIL" fi done
#文件名exe.sh cmd=$* su - <<EOF $cmd EOF
#!/bin/bash RUN_HOME=$(cd "(dirname "$0")"; echo "${PWD}") NOW_LIST=(`cat ${UN_HOME}/ips`) SSH_USER="hadoop" for i in ${NOW_LIST[@]}; do f_cmd="scp $1 $SSH_USER@i:$2" echo $f_cmd if eval $f_cmd; then echo "ok" else echo "FAIL" fi done
前期準備工做結束,下一篇開始安裝配置zookeeper