2.修改/etc/hosts文件 /安装SSH、配置SSH无密码登陆(全程切换到hadoop用户下操作)
生活随笔
收集整理的這篇文章主要介紹了
2.修改/etc/hosts文件 /安装SSH、配置SSH无密码登陆(全程切换到hadoop用户下操作)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
修改/etc/hosts文件
sudo gedit /etc/hosts127.0.0.1 localhost 192.168.222.129 master 下面分別對應(yīng)三個機器的IP地址,用ifconfig查看 192.168.222.130 slave1 192.168.222.131 slave2# The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters測試是否能ping通ping master/slave1/slave2==========
分別給3臺機器都創(chuàng)建hadoop用戶,方便進行管理
二、 建立hadoop運行帳號 即為hadoop集群專門設(shè)置一個用戶組及用戶 (1)創(chuàng)建hadoop用戶組 (2)創(chuàng)建hadoop用戶sudo adduser -ingroup hadoop hadoop回車后會提示輸入新的UNIX密碼,這是新建用戶hadoop的密碼,輸入回車即可。 最后確認信息是否正確,如果沒問題,輸入 Y,回車即可。 (3)為hadoop用戶添加權(quán)限(給hadoop用戶賦予和root用戶同樣的權(quán)限) 輸入:sudo gedit /etc/sudoers~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~================================================
用新增加的hadoop用戶登錄Ubuntu系統(tǒng),進行SSH的配置
================================================
配置ssh免密碼登錄hadoop工作時,各節(jié)點要相互通訊,正常情況下linux之間通訊要提供用戶名、密碼(目的是保證通訊安全),如果 需要人工干預(yù)輸入密碼,顯然不方便,做這一步的目的,是讓各節(jié)點能自動通過安全認證,不影響正常通訊。安裝ssh: sudo apt-get install openssh-server 安裝完成后,啟動服務(wù):sudo /etc/init.d/ssh start 查看服務(wù)是否正確啟動:ps -e | grep ssh一.使用SSH使每一臺機器免密碼登錄自己本機
//下面以mster機器為例:1.使登錄身份始終是hadoop,操作目錄始終是/home/master master@master:~$ su hadoop #切換成hadoop(以hadoop身份登錄到系統(tǒng)) hadoop@master:~$cd /home/hadoop(進入個人主目錄,默認為/home/hadoop)2.生成公鑰私鑰id_rsa id_rsa.pub hadoop@master:~$ ssh-keygen -t rsa -P '' (注:最后是二個單引號,生成公鑰私鑰) Generating public/private rsa key pair. Enter file in which to save the key (/home/hadoop/.ssh/id_rsa): Created directory '/home/hadoop/.ssh'. Your identification has been saved in /home/hadoop/.ssh/id_rsa. Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub. The key fingerprint is: cd:67:f5:0f:15:a1:42:ad:7a:29:78:3b:ca:8c:3a:b7 hadoop@slave1 The key's randomart image is: +--[ RSA 2048]----+ | .. o.| | . .. .| | .... .| | o ... o | | S + + . .| | . + = ..| | . + .| | . .+ o | | .+E.+. . | +-----------------+解釋:以rsa算法,生成公鑰、私鑰對,-P ''表示空密碼。該命令 運行完后,會在個人主目錄/home/hadoop下生成.ssh目錄,里面會 有二個文件id_rsa(私鑰) ,id_rsa.pub(公鑰),即: hadoop@master:~$ ls .ssh #查看是否生成公鑰私鑰 id_rsa id_rsa.pub3.導(dǎo)入公鑰hadoop@master:cat .ssh/id_rsa.pub >> .ssh/authorized_keys 解釋:會在個人主目錄/home/hadoop/.ssh目錄下生成authorized_keys,即 hadoop@master:~$ ls .ssh #查看是否生成authorized_keys authorized_keys id_rsa id_rsa.pub4.修改文件權(quán)限 hadoop@master:chmod 600 .ssh/authorized_keys5.進行SSH測試是否能免密碼連接本機執(zhí)行完以后,可以在本機上測試下,用ssh連接自己,即:ssh localhost (或ssh master)【注解】廢話不多說,直接上下面中3個中括號中的命令 【hadoop@master:~$ ssh localhost】 #連接自己 The authenticity of host 'localhost (127.0.0.1)' can't be established. ECDSA key fingerprint is d5:f7:47:44:7b:9f:55:ac:e7:ed:6c:8d:f6:98:68:72. Are you sure you want to continue connecting (yes/no)? yes #輸入yes Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts. Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)* Documentation: https://help.ubuntu.com/New release '16.04.3 LTS' available. Run 'do-release-upgrade' to upgrade to it.The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.【hadoop@master:~$ exit】 #連接成功后,退出exit 注銷 Connection to localhost closed.【hadoop@master:~$ ssh localhost】 #重新鏈接,不需要密碼,此時成功配置了master機器的SSH Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)* Documentation: https://help.ubuntu.com/281 packages can be updated. 193 updates are security updates.New release '16.04.3 LTS' available. Run 'do-release-upgrade' to upgrade to it.Last login: Fri Aug 11 10:22:27 2017 from localhosthadoop@master:~$ 【終于】到此位置,成功搞定一臺機器:master,下面我們再進行slave1,slave2機器的SSH免密碼登錄的配置。(配置方法同上)二. 將slave公鑰文件復(fù)制到master(只操作slave機器,不操作master)
a)用scp命令,把公鑰文件發(fā)放給master(即:剛才已經(jīng)搞定的那臺機器) #在slave1上: scp .ssh/id_rsa.pub hadoop@master:/home/hadoop/id_rsa_01.pub#在slave2上: scp .ssh/id_rsa.pub hadoop@master:/home/hadoop/id_rsa_02.pubb)這二行執(zhí)行完后,回到master中,查看下/home/hadoop目錄,應(yīng)該有二個新文 件id_rsa_01.pub、id_rsa_02.pub,然后在master上,導(dǎo)入這二個公鑰cat id_rsa_01.pub >> .ssh/authorized_keys cat id_rsa_02.pub >> .ssh/authorized_keys這樣,master這臺機器就有所有3臺機器的公鑰了。三. 將master上的“最全”公鑰,復(fù)制到其它機器slave1.slave2
a) 繼續(xù)保持在master上,scp .ssh/authorized_keys hadoop@slave1:/home/hadoop/.ssh/authorized_keysscp .ssh/authorized_keys hadoop@slave2:/home/hadoop/.ssh/authorized_keysb) 修改其它機器上authorized_keys文件的權(quán)限slave1以及slave2機器上,均執(zhí)行命令chmod 600 .ssh/authorized_keys四. 驗證能否通過SSH無密碼連接其他機器
在每個虛擬機上,均用 ssh 其它機器的hostname 驗證下,如果能正常無密碼連接成功,表示ok以master機器,連接slave1,slave2機器為例: (1)切換到hadoop用戶 master@master:~$ su hadoop (2)測試無密碼連接slave1 hadoop@master:/home/master$ ssh slave1 Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)* Documentation: https://help.ubuntu.com/281 packages can be updated. 193 updates are security updates.New release '16.04.3 LTS' available. Run 'do-release-upgrade' to upgrade to it.Last login: Fri Aug 11 11:02:00 2017 from slave2 (3)測試無密碼連接slave2 hadoop@slave1:~$ ssh slave2 Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)* Documentation: https://help.ubuntu.com/281 packages can be updated. 193 updates are security updates.New release '16.04.3 LTS' available. Run 'do-release-upgrade' to upgrade to it.Last login: Fri Aug 11 11:02:11 2017 from slave2【發(fā)現(xiàn)】master可以無密碼連接slave1,slave2,同理,下面 分別進行測試slave1,slave2~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~【重點】非常容易犯的錯誤配置SSH成功后,每次都要"先切換到hadoop用戶"下,才可以SSH成功(1)切換到用戶hadoop master@master:~$ su hadoop 密碼: (2)SSH本機器 hadoop@master:/home/master$ ssh master Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)* Documentation: https://help.ubuntu.com/New release '16.04.3 LTS' available. Run 'do-release-upgrade' to upgrade to it.Last login: Fri Aug 11 18:12:54 2017 from master hadoop@master:~$ (3)SSH slave1機器 hadoop@master:~$ ssh slave1 Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)* Documentation: https://help.ubuntu.com/New release '16.04.3 LTS' available. Run 'do-release-upgrade' to upgrade to it.Last login: Fri Aug 11 18:16:14 2017 from master hadoop@slave1:~$ (3)SSH slave2機器 hadoop@slave1:~$ ssh slave2 Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)* Documentation: https://help.ubuntu.com/New release '16.04.3 LTS' available. Run 'do-release-upgrade' to upgrade to it.Last login: Fri Aug 11 17:35:47 2017 from slave1 hadoop@slave2:~$[小結(jié)]
小結(jié):該步驟非常重要,主要思路是在各節(jié)點上生成公鑰、私鑰,然后將公鑰發(fā)放其它所有節(jié)點。RSA算法是非 對稱加密算法,僅公布“公鑰”,只要私鑰不外泄,還是不能解密的,所以安全性依然有保障。如果本步驟失敗,根據(jù)我個人經(jīng)驗,多半是權(quán)限問題,請檢查hadoop是否具有足夠權(quán)限,建議將hadoop加 入sudoers列表及root用戶組。另外,這里也整理了一些SSH免密碼設(shè)置失敗的原因,請移步 ssh 免密碼設(shè)置失敗原因總結(jié)Hadoop集群安裝配置教程_Hadoop2.6.0_Ubuntu/CentOShttp://dblab.xmu.edu.cn/blog/285/
總結(jié)
以上是生活随笔為你收集整理的2.修改/etc/hosts文件 /安装SSH、配置SSH无密码登陆(全程切换到hadoop用户下操作)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 18.图像用户界面入门:EasyGui
- 下一篇: 3.在slave1机器下载3个安装包解压