二 进击消息中间件系列:Kafka 单机与集群部署实践( 三 )


#修改脚本 xsync 具有执行权限[root@hadoop102 bin]# chmod 777 xsync
#执行脚本[root@hadoop102 ~]# xsync /opt/module/kafka_2.12-3.0.0/执行完后,hadoop102、hadoop103、hadoop104上都会有kafka_2.12-3.0.0文件
SSH 无密登录配置
由于每向一个服务器进行同步时,都需要输入密码 。为了不用每次输密码,所以可以进行SSH无密登录配置 。
① 配置 ssh
基本语法
#ssh 另一台电脑的 IP 地址,例如:hadoop102登录到hadoop103[root@hadoop102 ~]# ssh hadoop103#hadoop103 退回到 hadoop102[atguigu@hadoop103 ~]$ exit
② 无密钥配置
首先在A服务器生成密钥对,只将公钥拷贝给B服务器,B服务器会将公钥放在授权key的文件中
#进入.ssh目录,该目录下有个known_hosts文件,再查看known_hosts文件[root@hadoop102 ~]# cd .ssh/[root@hadoop102 .ssh]# lltotal 4-rw-r--r--. 1 root root 558 Nov 28 00:11 known_hosts[root@hadoop102 .ssh]# cat known_hostshadoop103,192.168.10.103 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIW8j1y/nhu5Q4K+3VGjTnChzq9cbIjzozabQQcjUCU9PdVFBIdD8PleMmDBEK6NCHzF7EW1m6n6iA1S4ihC3GM=hadoop104,192.168.10.104 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIW8j1y/nhu5Q4K+3VGjTnChzq9cbIjzozabQQcjUCU9PdVFBIdD8PleMmDBEK6NCHzF7EW1m6n6iA1S4ihC3GM=hadoop102,192.168.10.102 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIW8j1y/nhu5Q4K+3VGjTnChzq9cbIjzozabQQcjUCU9PdVFBIdD8PleMmDBEK6NCHzF7EW1m6n6iA1S4ihC3GM=说明hadoop102访问过hadoop102、hadoop103、hadoop104
#输入ssh-keygen -t rsa后,一直点击回车键,直到出现以下结果[root@hadoop102 .ssh]# ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa):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:NIVyD44Gsv0U5nVOiN5KA79KFCl4sQvlVO7hlQdhFZA root@hadoop102The key's randomart image is:+---[RSA 2048]----+| .+o..=*o+.||.++o=.Eo*.o||..o=oOoO+*|| ..+ooXoo.o||..o= +S||. +||. .||.|||+----[SHA256]-----+
# 再次查看.ssh目录,此时生成了公钥和私钥id_rsa、id_rsa.pub[root@hadoop102 .ssh]# lltotal 12-rw-------. 1 root root 1675 Nov 28 00:54 id_rsa-rw-r--r--. 1 root root396 Nov 28 00:54 id_rsa.pub-rw-r--r--. 1 root root558 Nov 28 00:11 known_hosts
# 查看公钥[root@hadoop102 .ssh]# cat id_rsa.pubssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDC6TzfM8ZEZQ8X0u9zFyWQ65cMuBk8YB3yqEjyEjVYtAHijSg0EpTh3NVrEmWaPaSv+6tCziPYjsdWdIQ1k+h8CgyRnV1vc4UTH+YETcl78ScoLWfDxiEBVmKS4aPMYt21yvExGQ/3wZYGFpGVoiUdpHU/QVbpXPjQZ5KjIkOZxzuqsDx5pUbuLT/TLxB5d0ZGYl5mMmVpFIyPlr+btozGNe23h1KAI/rniIrAqU/jYaeoWcrpFLgmiuoG4DPpPqev+GjBe3CS6ow+2i0UwX9czul+cZMWF58EJrhXX/zD6lC+nr6qX5mUTzuhoQpquYy9YetjhpD4iHOAjwT6sbiX root@hadoop102# 将hadoop102的公钥复制给hadoop102、hadoop103、hadoop104[root@hadoop102 .ssh]# ssh-copy-id hadoop102[root@hadoop102 .ssh]# ssh-copy-id hadoop103[root@hadoop102 .ssh]# ssh-copy-id hadoop104# hadoop102再次访问hadoop103时,将不再输入hadoop103的密码[root@hadoop102 .ssh]# ssh hadoop103Last login: Mon Nov 28 00:24:06 2022 from hadoop102[root@hadoop103 ~]## 查看hadoop103中的.ssh目录,多了一个authorized_keys文件,该文件尾部有一行root@hadoop102表示允许hadoop102免密登录[root@hadoop103 .ssh]# lltotal 8-rw-------. 1 root root 396 Nov 28 00:59 authorized_keys-rw-r--r--. 1 root root 372 Nov 28 00:51 known_hosts[root@hadoop103 .ssh]# cat authorized_keysssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDC6TzfM8ZEZQ8X0u9zFyWQ65cMuBk8YB3yqEjyEjVYtAHijSg0EpTh3NVrEmWaPaSv+6tCziPYjsdWdIQ1k+h8CgyRnV1vc4UTH+YETcl78ScoLWfDxiEBVmKS4aPMYt21yvExGQ/3wZYGFpGVoiUdpHU/QVbpXPjQZ5KjIkOZxzuqsDx5pUbuLT/TLxB5d0ZGYl5mMmVpFIyPlr+btozGNe23h1KAI/rniIrAqU/jYaeoWcrpFLgmiuoG4DPpPqev+GjBe3CS6ow+2i0UwX9czul+cZMWF58EJrhXX/zD6lC+nr6qX5mUTzuhoQpquYy9YetjhpD4iHOAjwT6sbiX root@hadoop102