大数据 配置java环境,添加用户与免密登录
1. 将 /opt/software 目录下将文件 jdk-8u191-linux-x64.tar.gz 安装包(若 slave1、slave2 节点不存在以上文件则需从master 节点复制)解压到/opt/module 路径中(若路径不存在,则需新建)。
从指定目录解压jdk-8u191-linux-x64.tar.gz
tar -xzvf /opt/software/jdk-8u191-linux-x64.tar.gz -C /opt/module/
tar选项说明如下
| 参数 | 说明 |
|---|---|
| c | 创建压缩文件 |
| x | 解压文件 |
| v | 显示进度 |
| f | 后接文件名 |
| t | 查看压缩文件内容 |
在上条命令中 tar后跟了xzvf选项,f选项后接文件名称。在最后面加上了-C选项指定解压到那个目录里。
解压完成可以使用ll命令查看解压出来的文件。
[root@master ~]# ll /opt/module/
total 0
drwxr-xr-x. 7 10 143 245 Oct 6 2018 jdk1.8.0_191
[root@master ~]# ll /opt/module/jdk1.8.0_191/
total 25976
drwxr-xr-x. 2 10 143 4096 Oct 6 2018 bin
-r--r--r--. 1 10 143 3244 Oct 6 2018 COPYRIGHT
drwxr-xr-x. 3 10 143 132 Oct 6 2018 include
-rw-r--r--. 1 10 143 5207154 Sep 12 2018 javafx-src.zip
drwxr-xr-x. 5 10 143 185 Oct 6 2018 jre
drwxr-xr-x. 5 10 143 245 Oct 6 2018 lib
-r--r--r--. 1 10 143 40 Oct 6 2018 LICENSE
drwxr-xr-x. 4 10 143 47 Oct 6 2018 man
-r--r--r--. 1 10 143 159 Oct 6 2018 README.html
-rw-r--r--. 1 10 143 424 Oct 6 2018 release
-rw-r--r--. 1 10 143 21101479 Oct 6 2018 src.zip
-rw-r--r--. 1 10 143 108062 Sep 12 2018 THIRDPARTYLICENSEREADME-JAVAFX.txt
-r--r--r--. 1 10 143 155003 Oct 6 2018 THIRDPARTYLICENSEREADME.txt
[root@master ~]#可以看到在/opt/module/目录下出现了jdk1.8.0_191文件夹。文件夹内的bin文件夹存放的及是jdk的二进制可执行文件。我们需要先记下bin文件夹的绝对路径/opt/module/jdk1.8.0_191/bin和java文件夹的绝对路径/opt/module/jdk1.8.0_191/ 为下题的添加环境变量做准备。
2. 在 /etc/profile 文件中配置 JDK 环境变量 JAVA_HOME 和 PATH 的值,并让配置文件立即生效。
使用vi编辑器 编辑/etc/profile文件vi /etc/profile
在最下方添加如下内容
export JAVA_HOME=/opt/module/jdk1.8.0_191
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH| 变量 | 说明 |
|---|---|
| JAVA_HOME | JAVA路径 |
| CLASSPATH | java类的路径 |
| PATH | 使得可直接执行java相关命令 |
使用source /etc/profile使环境变量生效。
执行java -version 如果配置没问题的话将会显示jdk版本,反之请检查JAVA_HOME路径是否有误,PATH 是否配置错误。
[root@master jdk1.8.0_191]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)3. 创建 hadoop 用户并设置密码,为 hadoop 用户添加管理员权限。
使用useradd hadoop添加用户,passwd hadoop设置密码。
[root@master jdk1.8.0_191]# useradd hadoop
[root@master jdk1.8.0_191]# passwd hadoop
Changing password for user hadoop.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.添加管理员权限
使用usermod -a -G root hadoop将用户添加到root组。
使用vi编辑/etc/sudoers添加如下内容
hadoop ALL=(ALL) ALL保存退出时需要加上!
将文件权限重新修改 chmod u-w /etc/sudoers
4. 关闭防火墙,设置开机不自动启动防火墙
关闭防火墙systemctl stop firewalld
开机不自启systemctl disable firewalld
查看状态systemctl status firewalld
5. 配置三个节点的 SSH 免密登录
使用ssh-keygen命令生成密钥对
使用ssh-copy-id root@slave1分别将密钥复制其他主机上 命令格式如下:ssh-copy-id {用户名}@{主机名/IP地址}每台主机执行以上操作。
[root@master ~]# ssh-copy-id root@slave1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'slave1 (192.168.123.147)' can't be established.
ECDSA key fingerprint is SHA256:48GncyxW4MySaPjr71npHGvWv79zq1ScOGilNT7Tz2U.
ECDSA key fingerprint is MD5:03:d3:7b:49:5d:1f:18:b4:ee:60:0b:0c:9b:f1:ab:36.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@slave1's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@slave1'"
and check to make sure that only the key(s) you wanted were added.在master主机上使用ssh root@slave1测试会发现不用填写密码即可登录主机。
[root@master ~]# ssh root@slave1
Last login: Sun Jan 14 08:42:07 2024 from master
[root@slave1 ~]# exit
logout
Connection to slave1 closed.
[root@master ~]# ssh root@slave2
Last login: Sun Jan 14 08:42:24 2024 from master
[root@slave2 ~]# exit
logout
Connection to slave2 closed.
[root@master ~]#本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。