1.ssh-keygen非交互式創(chuàng)建秘鑰對(duì):
具體命令:ssh-keygen -f ~/.ssh/id_rsa -P '' -q
參數(shù)講解:
ssh-keygen:密鑰對(duì)創(chuàng)建工具
[-P old_passphrase] 密碼
[-f output_keyfile] 輸出的秘鑰文件
[-q] 不輸出信息
[-t dsa ] 指定秘鑰類型肴掷。
2.ssh-copy-id不需要提示yes/no分發(fā)秘鑰
具體命令:ssh-copy-id -f -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no 172.16.1.8
參數(shù)講解:
ssh-copy-id -f -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no root172.16.1.8
ssh-copy-id [-f] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
說明:
-f: force mode 強(qiáng)制
[-i [identity_file]] 指定秘鑰文件
[[-o <ssh -o options>] ...] 指定ssh參數(shù)選項(xiàng)。
3.sshpass工具:指定密碼非人工交互分發(fā)秘鑰
sshpass -p123456 ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.7
[root@web02 ~]# sshpass -help
Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
sshpass -p123456 ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.7
sshpass [-f|-d|-p|-e] [-hV] command parameters
參數(shù)講解:
-p password Provide password as argument (security unwise) #指定用戶密碼操作
分發(fā)密鑰
ssh-keygen -f ~/.ssh/id_rsa -P '' -q
ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.7
sshpass -p123456 ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.7
一鍵分發(fā)
#!/bin/bash
#yum install sshpass -y
ssh-keygen -f ~/.ssh/id_rsa -P '' -q
for ip in 7 61
do
sshpass -p123456 ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.$ip
done
實(shí)踐
9.安裝ansible
m01管理機(jī):
yum install epel-release -y
yum install ansible -y
#如果有l(wèi)ibselinux-python就不執(zhí)行下面的命令了罐农。
#rpm -qa |grep libselinux-python
#yum install libselinux-python -y
其他所有機(jī)器:
#rpm -qa |grep libselinux-python
#yum install libselinux-python -y
ansible命令參數(shù)
-m MODULE_NAME, 模塊名字崔拥,默認(rèn)command
-a MODULE_ARGS, 模塊參數(shù)
-f FORKS 并發(fā)進(jìn)程數(shù),默認(rèn)5個(gè)群发。
-i INVENTORY(default=/etc/ansible/hosts)指定主機(jī)列表文件
ansible模塊查看和幫助
查找模塊
ansible-doc -l
查看某個(gè)模塊的具體參數(shù)幫助
ansible-doc -s command
command模塊
1)功能說明:
command Executes a command on a remote node
功能說明:執(zhí)行一個(gè)命令在遠(yuǎn)程節(jié)點(diǎn)上
操作實(shí)踐:
ansible oldboy -m command -a "free -m"
ansible oldboy -m command -a "df -h"
ansible oldboy -m command -a "ls /root"
ansible oldboy -m command -a "cat redhat-release"
ansible oldboy -m command -a "cat /etc/redhat-release"