1.三台机分别生成rsa非对称秘钥
# master [wadeyu@master ~]$ su root Password: [root@master wadeyu]# ssh-keygen # slave1 [wadeyu@slave1 ~]$ su root Password: [root@slave1 wadeyu]# ssh-keygen # slave2 [wadeyu@slave2 ~]$ su root Password: [root@slave2 wadeyu]# ssh-keygen2.保存公钥到~/.ssh/authorized_keys文件中
# master机器操作 [root@master wadeyu]# cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys 追加slave1和slave2的公钥到这个文件中 [root@master wadeyu]# scp slave1:~/.ssh/id_rsa.pub ~/slave1_id_rsa.pub [root@master wadeyu]# scp slave2:~/.ssh/id_rsa.pub ~/slave2_id_rsa.pub [root@master wadeyu]# cat ~/slave1_id_rsa.pub >> ~/.ssh/authorized_keys [root@master wadeyu]# cat ~/slave2_id_rsa.pub >> ~/.ssh/authorized_keys 复制文件~/.ssh/authorized_keys到slave1,slave2 [root@master wadeyu]# scp ~/.ssh/authorized_keys slave1:~/.ssh root@slave1\'s password: authorized_keys 100% 1179 458.2KB/s 00:00 [root@master wadeyu]# scp ~/.ssh/authorized_keys slave2:~/.ssh root@slave2\'s password: authorized_keys 其它操作(每台虚拟机)为了减少系统配置对集群的影响,学习环境关闭防火墙和selinux
1.关闭防火墙
[root@master wadeyu]# systemctl stop firewalld [root@master wadeyu]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: inactive (dead) since Sat 2018-09-01 11:26:29 CST; 5s ago Docs: man:firewalld(1) Process: 635 ExecStart=http://www.likecs.com/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS) Main PID: 635 (code=exited, status=0/SUCCESS) Sep 01 10:23:16 master systemd[1]: Starting firewalld - dynamic firewall daemon... Sep 01 10:23:18 master systemd[1]: Started firewalld - dynamic firewall daemon. Sep 01 11:26:21 master systemd[1]: Stopping firewalld - dynamic firewall daemon... Sep 01 11:26:29 master systemd[1]: Stopped firewalld - dynamic firewall daemon.关闭selinux
[root@master wadeyu]# getenforce Enforcing [root@master wadeyu]# setenforce 0 [root@master wadeyu]# getenforce Permissive 启动集群master节点操作,进入hadoop/bin目录
第一次启动需要对hadoop格式化
[root@master wadeyu]# cd /usr/local/src/hadoop-1.2.1 hadoop-1.2.1/ hadoop-1.2.1-bin.tar.gz [root@master wadeyu]# cd /usr/local/src/hadoop-1.2.1 [root@master hadoop-1.2.1]# cd /usr/local/src/hadoop-1.2.1/bin [root@master bin]# ./hadoop namenode -format 18/09/01 11:37:07 INFO namenode.NameNode: STARTUP_MSG: /************************************************************ STARTUP_MSG: Starting NameNode STARTUP_MSG: host = master/192.168.1.15 STARTUP_MSG: args = [-format] STARTUP_MSG: version = 1.2.1 STARTUP_MSG: build = https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1.2 -r 1503152; compiled by \'mattf\' on Mon Jul 22 15:23:09 PDT 2013 STARTUP_MSG: java = 1.8.0_181 ************************************************************/ 18/09/01 11:37:08 INFO util.GSet: Computing capacity for map BlocksMap 18/09/01 11:37:08 INFO util.GSet: VM type = 64-bit 18/09/01 11:37:08 INFO util.GSet: 2.0% max memory = 1013645312 18/09/01 11:37:08 INFO util.GSet: capacity = 2^21 = 2097152 entries 18/09/01 11:37:08 INFO util.GSet: recommended=2097152, actual=2097152 18/09/01 11:37:08 INFO namenode.FSNamesystem: fsOwner=root 18/09/01 11:37:08 INFO namenode.FSNamesystem: supergroup=supergroup 18/09/01 11:37:08 INFO namenode.FSNamesystem: isPermissionEnabled=true 18/09/01 11:37:08 INFO namenode.FSNamesystem: dfs.block.invalidate.limit=100 18/09/01 11:37:08 INFO namenode.FSNamesystem: isAccessTokenEnabled=false accessKeyUpdateInterval=0 min(s), accessTokenLifetime=0 min(s) 18/09/01 11:37:08 INFO namenode.FSEditLog: dfs.namenode.edits.toleration.length = 0 18/09/01 11:37:08 INFO namenode.NameNode: Caching file names occuring more than 10 times 18/09/01 11:37:09 INFO common.Storage: Image file /usr/local/src/hadoop-1.2.1/tmp/dfs/name/current/fsimage of size 110 bytes saved in 0 seconds. 18/09/01 11:37:09 INFO namenode.FSEditLog: closing edit log: position=4, editlog=http://www.likecs.com/usr/local/src/hadoop-1.2.1/tmp/dfs/name/current/edits 18/09/01 11:37:09 INFO namenode.FSEditLog: close success: truncate to 4, editlog=http://www.likecs.com/usr/local/src/hadoop-1.2.1/tmp/dfs/name/current/edits 18/09/01 11:37:09 INFO common.Storage: Storage directory /usr/local/src/hadoop-1.2.1/tmp/dfs/name has been successfully formatted. 18/09/01 11:37:09 INFO namenode.NameNode: SHUTDOWN_MSG: /************************************************************ SHUTDOWN_MSG: Shutting down NameNode at master/192.168.1.15 ************************************************************/2.启动所有节点
[root@master bin]# ./start-all.sh starting namenode, logging to /usr/local/src/hadoop-1.2.1/libexec/../logs/hadoop-wadeyu-namenode-master.out slave2: starting datanode, logging to /usr/local/src/hadoop-1.2.1/libexec/../logs/hadoop-root-datanode-slave2.out slave1: starting datanode, logging to /usr/local/src/hadoop-1.2.1/libexec/../logs/hadoop-root-datanode-slave1.out The authenticity of host \'master (192.168.1.15)\' can\'t be established. ECDSA key fingerprint is SHA256:8DvdHBlcz1qInlLa9k2iYyd4Ip7auPhcb0mjHbEwZmo. ECDSA key fingerprint is MD5:9e:33:01:d2:fb:9c:dc:4f:40:30:90:fe:37:6e:1f:33. Are you sure you want to continue connecting (yes/no)? yes master: Warning: Permanently added \'master,192.168.1.15\' (ECDSA) to the list of known hosts. master: starting secondarynamenode, logging to /usr/local/src/hadoop-1.2.1/libexec/../logs/hadoop-root-secondarynamenode-master.out starting jobtracker, logging to /usr/local/src/hadoop-1.2.1/libexec/../logs/hadoop-wadeyu-jobtracker-master.out slave1: starting tasktracker, logging to /usr/local/src/hadoop-1.2.1/libexec/../logs/hadoop-root-tasktracker-slave1.out slave2: starting tasktracker, logging to /usr/local/src/hadoop-1.2.1/libexec/../logs/hadoop-root-tasktracker-slave2.out