1. 配置主機(jī)名[1]
3臺(tái)主機(jī)各執(zhí)行一次
hostnamectl set-hostname master
//master、node1、node2
現(xiàn)在有3臺(tái)機(jī)器
| master | node2 | node3 |
|---|---|---|
| 192.168.206.201 | 192.168.206.202 | 192.168.206.203 |
2. SSH免密登陸[2]
-
($后代表命令)
- vim 編輯/etc/hosts, 先清空所有內(nèi)容( 可以用快捷鍵dd刪除 ),加入7個(gè)節(jié)點(diǎn)的ip以及主機(jī)名:
192.168.206.201 master 192.168.206.202 node1 192.168.206.203 node2
- 使用 scp命令拷貝免密登陸文件
首先,編輯/etc/ssh/ssh_config,去掉以下選項(xiàng)的注釋RSAAuthentication yes PubkeyAuthentication yes
保存后使用scp拷貝到2-7 node機(jī)器上,按提示輸入yes和密碼
$ vim scp_file.sh
#/bin/bash
if [ -n "$1" ]; then
echo "scp dir $1"
for a in {1..2}
do
scp $1 node$a:$1
done
else
echo "Usage: scp_file [filename]"
fi
$ chmod o+x scp_file.sh
$./scp_file.sh /etc/ssh/ssh_config

scp_file.png
/etc/hosts同樣拷貝
$ ./scp_file.sh /etc/hosts
- 在集群的
都需要輸入命令 ssh-keygen -t rsa -P '',生成 key,提示出來(lái)按全部都按回車(chē)鍵
ssh-keygen.png
- 將各個(gè)節(jié)點(diǎn)的秘鑰寫(xiě)入master的authorized_keys文件中,master上執(zhí)行
$ vim ops_command.sh
#/bin/bash
if [ -n "$1" ]; then
echo "exe command $1"
for a in {1..2}
do
ssh root@node$a $1
done
else
echo "Usage: ops_command [command]"
fi
---------------------------------------------------------------------
$ vim auth_write.sh
#/bin/bash
for a in {1..2}
do
ssh root@node$a cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
done
--------------------------------------------------------------------------------
$ chmod o+x ops_command.sh
$ chmod o+x auth_write.sh
$ ./auth_write.sh
$ ./scp_file.sh /root/.ssh/authorized_keys
$ systemctl restart sshd
$ ./ops_command.sh 'systemctl restart sshd'
- 測(cè)試
//node1上執(zhí)行
ssh root@node2
//各個(gè)機(jī)器上都可以試試
//第一次登陸會(huì)有一個(gè)yes的提示,正常現(xiàn)象
