saltstack(主机改名)

时间:2023-03-08 22:19:18

已存在salt中的机器,为了规范,需要将这批主机改名

操作流程:在master把这批机器剔除;然修改这批机器的主机名、在/etc/salt目录下、用mv把minion_id和pki的目录重命名、重启salt-minion服务(在mster段能再次监控到这台主机后、可把上面重命名的文件删除)

环境:http://www.cnblogs.com/zzzhfo/p/6126223.html

把salt-client-01改名为salt-minion-01

  • 在salt-server上把salt-client-01剔除
[root@salt-server /]# salt-key -L
Accepted Keys:
salt-client-
salt-client-
Denied Keys:
Unaccepted Keys:
Rejected Keys: [root@salt-server /]# salt-key -d 'salt-client-01' -y
Deleting the following keys:
Accepted Keys:
salt-client-
Key for minion salt-client- deleted.
[root@salt-server /]# salt-key -L
Accepted Keys:
salt-client-
Denied Keys:
Unaccepted Keys:
salt-client-01
Rejected Keys:

修改主机名

[root@salt-client- /]# cat /etc/sysconfig/network  #重启生效
NETWORKING=yes
HOSTNAME=salt-minion-
[root@salt-client- /]# hostname salt-minion-
[root@salt-client- /]# bash

删除minion_id和pki(建议使用mv命令)

[root@salt-minion- /]# cd /etc/salt/
[root@salt-minion- salt]#mv minion_id minion_id.bak
[root@salt-minion- salt]# mv pki pki.bak
[root@salt-minion- salt]# /etc/init.d/salt-minion restart
Stopping salt-minion daemon: [ OK ]
Starting salt-minion daemon: [ OK ]
[root@salt-minion- salt]# ls
minion minion.d minion_id minion_id.bak pki pki.bak

查看minion的日志信息

error :salt主缓存节点的公钥,这盐奴才将等待10秒前试图认证

[root@salt-minion- salt]# tail /var/log/salt/minion
-- ::, [salt.crypt ][ERROR ][] The Salt Master has cached the public key for this node, this salt minion will wait for seconds before attempting to re-authenticate
-- ::, [salt.crypt ][ERROR ][] The Salt Master has cached the public key for this node, this salt minion will wait for seconds before attempting to re-authenticate
-- ::, [salt.crypt ][ERROR ][] The Salt Master has cached the public key for this node, this salt minion will wait for seconds before attempting to re-authenticate
-- ::, [salt.crypt ][ERROR ][] The Salt Master has cached the public key for this node, this salt minion will wait for seconds before attempting to re-authenticate
-- ::, [salt.crypt ][ERROR ][] The Salt Master has cached the public key for this node, this salt minion will wait for seconds before attempting to re-authenticate
-- ::, [salt.crypt ][ERROR ][] The Salt Master has cached the public key for this node, this salt minion will wait for seconds before attempting to re-authenticate
-- ::, [salt.crypt ][ERROR ][] The Salt Master has cached the public key for this node, this salt minion will wait for seconds before attempting to re-authenticate
-- ::, [salt.crypt ][ERROR ][] The Salt Master has cached the public key for this node, this salt minion will wait for seconds before attempting to re-authenticate
-- ::, [salt.crypt ][ERROR ][] The Salt Master has cached the public key for this node, this salt minion will wait for seconds before attempting to re-authenticate
-- ::, [salt.crypt ][ERROR ][] The Salt Master has cached the public key for this node, this salt minion will wait for seconds before attempting to re-authenticate

在master端重新认证(可能存在延迟、多刷新几次)

[root@salt-server master]# salt-key -L
Accepted Keys:
salt-client-
Denied Keys:
Unaccepted Keys:
salt-client-
salt-minion-
Rejected Keys:
[root@salt-server master]# salt-key -a 'salt-minion-01' -y
The following keys are going to be accepted:
Unaccepted Keys:
salt-minion-
Key for minion salt-minion- accepted.
[root@salt-server master]# salt-key -L
Accepted Keys:
salt-client-
salt-minion-
Denied Keys:
Unaccepted Keys:
salt-client-
Rejected Keys:
[root@salt-server master]# salt '*' test.ping
salt-minion-:
True
salt-client-:
True

上面用salt-key -L 查看到salt-client-01在等待认证,是因为缓存的原因

[root@salt-server master]# pwd
/etc/salt/pki/master
[root@salt-server master]# ll minions #通过认证的key
total
-rw-r--r--. root root Sep : salt-client-
-rw-r--r--. root root Sep : salt-minion-
[root@salt-server master]# ll minions_pre 等待认证的key
total
-rw-r--r--. root root Sep : salt-client-
[root@salt-server master]# cd minions_pre
[root@salt-server minions_pre]# ls
salt-client- #把它删除 再次查看就不会存在了
[root@salt-server minions_pre]# rm -rf salt-client-
[root@salt-server minions_pre]# ls
[root@salt-server minions_pre]# salt-key -L
Accepted Keys:
salt-client-
salt-minion-
Denied Keys:
Unaccepted Keys:
Rejected Keys:
[root@salt-server minions_pre]# salt-key -L
Accepted Keys:
salt-client-
salt-minion-
Denied Keys:
Unaccepted Keys:
Rejected Keys:
[root@salt-server minions_pre]# salt '*' test.ping
salt-minion-:
True
salt-client-:
True
[root@salt-server minions_pre]# salt '*' cmd.run 'df -h'
salt-minion-:
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 917M 16G % /
tmpfs 495M 12K 495M % /dev/shm
/dev/sda1 485M 31M 429M % /boot
salt-client-:
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 916M 16G % /
tmpfs 495M 12K 495M % /dev/shm
/dev/sda1 485M 31M 429M % /boot