Post

Env(1) 大数据环境统一配置

Env(1) 大数据环境统一配置

参考文档:黑马资料:05-大数据环境配置统一.doc 原资料是在CentOS 7上配置,下面是在Ubuntu 22.04上配置

1 虚拟机基本配置

1.1 创建并克隆虚拟机

使用Ubuntu 22.04的iso镜像创建虚拟机,并安装Ubuntu系统,命名为node1: 预装vim, net-tools和openssh-server:

1
2
sudo apt update
sudo apt install vim net-tools openssh-server -y

克隆创建好的虚拟机,命名为node2、node3:

1.2 配置MAC地址

对于克隆的虚拟机,在设置中生成独特的MAC地址:

1.3 配置IP地址

(原本希望在此步骤配置静态IP地址,尝试了netplan,但配置之后无法ping www.baidu.com。且希望配置之后的虚拟机能和主机联通。虚拟机内DHCP地址似乎无变化,故暂时采用DHCP地址) 假设3台虚拟机的IP地址分别为192.168.233.129, 192.168.233.130, 192.168.233.131

提示:为了便于在Windows主机中访问3个节点的应用,可以在C:\Windows\System32\drivers\etc的hosts中添加如下内容:

1
2
3
192.168.233.129      node1
192.168.233.130      node2
192.168.233.131      node3

在cmd中刷新缓存使之生效:

1
ipconfig/[flushdns]

1.4 在MobaExterm中通过SSH控制各节点

1.5 配置各主机名

对每个主机进行如下操作:

1
2
3
4
5
6
7
8
9
10
vim /etc/hostname
# 修改各主机名称为ubuntu-node1, ubuntu-node2, ...

vim /etc/hosts
# 注释以下行:
# 127.0.1.1 ubuntu-node1
# 粘贴下面一段
192.168.233.129 node1 ubuntu-node1
192.168.233.130 node2 ubuntu-node2
192.168.233.131 node3 ubuntu-node3

由于Ubuntu采用127.0.1.1作为完全限定域名(Fully Qualified Domain Name, FQDN),这与下面要配置的192.168.233.129冲突,所以注释127.0.1.1 ubuntu-node1行。

添加后的/etc/hosts文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
user@ubuntu-node1:~/Work$ cat /etc/hosts
127.0.0.1       localhost
# 127.0.1.1     ubuntu-node1
192.168.233.129 node1 ubuntu-node1
192.168.233.130 node2 ubuntu-node2
192.168.233.131 node3 ubuntu-node3

# 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

重启之后,各主机的主机名即依次修改为ubuntu-node1, ubuntu-node2和ubuntu-node3。同时,指定了node1, node2, node3作为对应IP地址的域名。

1.6 关闭防火墙

1
2
sudo systemctl stop ufw
sudo systemctl disable ufw

Ubuntu没有SELinux,所以不需要设置。

1.7 配置各节点之间免密访问

可使用MobaExterm的MultiExec模式,同时向3个节点输入命令:

1
2
3
4
5
6
7
# 3个节点生成公钥与私钥
ssh-keygen -t rsa
# (等待所有窗口就绪, 按下3个回车)

# 3个节点公钥拷贝到节点1
ssh-copy-id node1
# 输入yes, 并输入node1的密码

将节点1的公钥拷贝到其他机器。在节点1执行:

1
2
3
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
scp ~/.ssh/authorized_keys user@node2:~/.ssh
scp ~/.ssh/authorized_keys user@node3:~/.ssh

注:上面是假设3个节点用户均为user。如果均为root,则执行如下命令:

1
2
3
cat ~/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
scp /root/.ssh/authorized_keys node2:/root/.ssh
scp /root/.ssh/authorized_keys node3:/root/.ssh

测试免密登录:

1
2
3
4
5
6
7
user@ubuntu-node1:~$ ssh node2
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 6.8.0-52-generic x86_64)
...
Last login: Sun Feb  2 20:09:27 2025 from 192.168.233.129
user@ubuntu-node2:~$ exit
logout
Connection to node2 closed.

1.8 时钟同步

(略,按需安装)

1.9 安装软件

1.9.2 安装JDK

安装较新的长期支持版JDK17:

1
sudo apt install openjdk-17-jdk

配置环境变量,sudo vim /etc/profile,添加:

1
JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64

使用echo命令验证:

1
2
$ echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64
This post is licensed under CC BY 4.0 by the author.