1. YUM 更新
2. 主机名称修改
(1)查看当前主机名
$ hostnamectl statusStatic hostname: daygeek-Y700Icon name: computer-laptopChassis: laptopMachine ID: 31bdeb7b83230a2025d43547368d75bcBoot ID: 267f264c448f000ea5aed47263c6de7fOperating System: Manjaro LinuxKernel: Linux 4.19.20-1-MANJAROArchitecture: x86-64
(2)修改主机名
hostnamectl set-hostname [YOUR NEW HOSTNAME]
参考文章: Linux 中改变主机名的 4 种方法
3. 映射主机与IP
集群内的虚拟机都需要修改
[root@node-1 redis-cluster]# vim /etc/hosts192.168.0.1 master192.168.0.2 slave1192.168.0.3 slave2
保存后退出即可
[root@redis ~]# ping slave1PING slave1 (10.19.134.172) 56(84) bytes of data.64 bytes from slave1 (10.19.134.172): icmp_seq=1 ttl=64 time=1.34 ms64 bytes from slave1 (10.19.134.172): icmp_seq=2 ttl=64 time=0.752 ms64 bytes from slave1 (10.19.134.172): icmp_seq=3 ttl=64 time=0.369 ms^C--- slave1 ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2001msrtt min/avg/max/mdev = 0.369/0.820/1.341/0.401 ms
4. 免密SSH配置
4.1 生成密钥对
分别在三台虚拟机执行密钥生成命令,一路回车
[root@redis ~]# ssh-keygen -t rsaGenerating 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:SHA256:ArGj5KJEts60ufblXQz8H3xdsajEIhNfLOMgzgAaLQk root@statusThe key's randomart image is:+---[RSA 2048]----+|E+ . ||+.o o . ||.+..+. o o o . ||oo..+oo = = . o||.+o o.=S+ o . ..||*.o .* + . . .||.= . + + . . || .. o . . . o ||.... . . . |+----[SHA256]-----+
4.2 将从服务器公钥复制到主服务器上
分表在两台从服务器执行如下命令
从服务器1(slave1):
[root@redis ~]# scp .ssh/id_rsa.pub root@10.19.134.171:~/.ssh/id_rsa.pub.slave1
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.19.134.171' (ECDSA) to the list of known hosts.
root@10.19.134.171's password:
id_rsa.pub
从服务器2(slave2):
[root@redis ~]# scp .ssh/id_rsa.pub root@10.19.134.171:~/.ssh/id_rsa.pub.slave2
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.19.134.171' (ECDSA) to the list of known hosts.
root@10.19.134.171's password:
id_rsa.pub
切换到主服务器,查看复制结果
[root@redis .ssh]# ll
总用量 16
-rw------- 1 root root 1679 12月 2 17:06 id_rsa
-rw-r--r-- 1 root root 393 12月 2 17:06 id_rsa.pub
-rw-r--r-- 1 root root 393 12月 2 17:12 id_rsa.pub.slave1
-rw-r--r-- 1 root root 393 12月 2 17:11 id_rsa.pub.slave2
4.3 将公钥加入到被认证的公钥文件
在master主机上操作,将三台虚拟机生成的公钥文件都加入到被认证的公钥文件中
cat ~/.ssh/id_rsa.pub* >> ~/.ssh/authorized_keys
将被认证的公钥文件发送到另外两台从机器中(在master主机上操作)
[root@REDIS .ssh]# scp ~/.ssh/authorized_keys root@10.19.134.173:~/.ssh/
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.19.134.173' (ECDSA) to the list of known hosts.
root@10.19.134.173's password:
authorized_keys
查看两台从节点虚拟机
# ls .ssh/
authorized_keys id_rsa id_rsa.pub known_hosts
4.4 验证
在三台虚拟机上分别执行下面命令
ssh master
ssh slave1
ssh slave2
链接成功后,执行exit命令退出
参考文章:Centos-SSH免密码登录
5. 安装JAVA运行环境
yum install -y java-11-openjdk-devel.x86_64 java-11-openjdk.x86_64
6. 集群内文件传输脚本
#!/bin/bash
if [ $# -lt 1 ]
then
echo Not Enough Arguement!
exit;
fi
for host in hadoop102 hadoop103 hadoop104
do
echo ==================== $host ====================
for file in $@
do
if [ -e $file ]
then
pdir=$(cd -P $(dirname $file); pwd)
fname=$(basename $file)
scp $pdir/$fname $USER@$host:$pdir
else
echo $file does not exists!
fi
done
done
参考文章:https://blog.csdn.net/qq_41878532/article/details/107778763
