1. 在VMware上安裝三臺Centos7虛擬機
請參考其他教程,如:http://www.linuxidc.com/Linux/2014-10/108013.htm
2. 配置網路(使用NAT模式)
設置VMware的ip(網關IP),此次將網段設置為192.168.88.0,三臺虛擬機的ip分別為201,202,203
Paste_Image.png
Paste_Image.png
將主機上的VMnet8虛擬網卡的ip設置為192.168.88.2
Paste_Image.png
3. 設置虛擬機靜態ip
此處以201為例,使用root身份登錄系統,使用vim打開配置文件/etc/sysconfig/network-scripts/ifcfg-ens33,將內容修改如下:
TYPE="Ethernet"
BOOTPROTO="static" #將dhcp改為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"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="8ae181fb-3e3e-4167-a157-687f2f1c71f4"
DEVICE="ens33"
ONBOOT="yes" #開機啟用本配置
IPADDR=192.168.88.201 #靜態IP地址
GATEWAY=192.168.88.1 #網管地址
NETMASK=255.255.255.0 #子網掩碼
DNS1=192.168.88.1 #DNS設置為網管一樣
重啟虛擬機即可生效
4. 設置虛擬機主機名
我們將主機名命名為以cluster+ip后綴的形式,此處三臺依次為:
192.168.88.201 cluster201
192.168.88.202 cluster202
192.168.88.203 cluster203
此處以201為例,查看當前主機名:
[root@localhost ~]# hostname
localhost.localdomain
# 修改hostname,這種修改方式重啟后會失效
[root@localhost ~]# hostname cluster201
[root@localhost ~]# hostname
cluster201
使用vim打開/etc/hostname文件,將內容修改如下:
cluster201
可重啟一下虛擬機
5. 修改hosts文件
三臺虛擬機執行同樣的操作,使用vim打開/etc/hosts文件,在文件末尾增加如下內容:
192.168.88.201 cluster201
192.168.88.202 cluster202
192.168.88.203 cluster203
6. 設置ssh免密登錄
此處以201和root用戶為例,在201上要用root用戶免密登錄到202與203上,其他用戶與IP虛擬機類似
在201上生成key:
# 執行如下命令生成key,一路回車即可
[root@cluster201 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ed:5f:6f:e0:84:a7:a4:4c:97:0a:e9:8e:a4:56:17:2c root@cluster201
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . |
| E o. |
| .So. o |
| . +.. = + |
| ..o +.= =.. |
| .o .. +......|
| .. ... . ..|
+-----------------+
#查看~/.ssh目錄下生成了兩個文件
[root@cluster201 ~]# ls .ssh/
id_rsa id_rsa.pub
# 將公鑰放入目標機器后執行,第一次ssh到202,此時就不需要密碼了
[root@cluster201 ~]# ssh cluster202
The authenticity of host 'cluster202 (192.168.88.202)' can't be established.
ECDSA key fingerprint is 7c:1f:06:3d:19:63:3a:c2:79:19:3f:02:ed:f7:49:cd.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'cluster202,192.168.88.202' (ECDSA) to the list of known hosts.
Last login: Thu Jun 1 17:39:52 2017 from 192.168.88.2
[root@cluster202 ~]#
將公鑰放入到登錄的目標機器上(202,203):
將生成key的機器上的/.ssh/id_rsa.pub內容追加到目標機器的/.ssh/authorized_keys的最后一行,
然后把三臺機器 .ssh/ 文件夾權限改為700,authorized_keys文件權限改為600(or 644)
[root@cluster201 ~]$ chmod 700 .ssh
[root@cluster201 ~]$ chmod 600 .ssh/authorized_keys
7. 安裝JAVA環境
請參考:http://www.lxweimin.com/p/288cf1bc3096
8. 添加hadoop用戶,設置免密登錄,添加應用安裝目錄/opt/bigdata
[root@cluster201 ~]# adduser hadoop
# 比如講秘密設置為123456
[root@cluster201 ~]# passwd hadoop
更改用戶 hadoop 的密碼 。
新的 密碼:
無效的密碼: 密碼少于 8 個字符
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
# 免密登錄參考6
#新建應用安裝目錄,并修改權限
[root@cluster202 ~]# mkdir /opt/bigdata
[root@cluster202 ~]# chown hadoop /opt/bigdata
[root@cluster202 ~]# chgrp hadoop /opt/bigdata