04-24 day 39

1.ssh-keygen非交互式创建秘钥对:

具体命令:ssh-keygen -f ~/.ssh/id_rsa  -P '' -q
参数讲解:
ssh-keygen:密钥对创建工具
        [-P old_passphrase]  密码
    [-f output_keyfile]  输出的秘钥文件
    [-q]       不输出信息      
    [-t dsa ]  指定秘钥类型。

2.ssh-copy-id不需要提示yes/no分发秘钥

具体命令:ssh-copy-id -f -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no 172.16.1.8

参数讲解:
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 ] ...] [user@]hostname
说明:
-f: force mode 强制
[-i [identity_file]] 指定秘钥文件
[[-o ] ...] 指定ssh参数选项。

3.sshpass工具:指定密码非人工交互分发秘钥

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

参数讲解:
-p password   Provide password as argument (security unwise)    #指定用户密码操作
分发密钥
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

一键分发

#!/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

实践

9.安装ansible

m01管理机:
yum install epel-release -y
yum install ansible -y

#如果有libselinux-python就不执行下面的命令了。
#rpm -qa |grep libselinux-python
#yum install libselinux-python -y

其他所有机器:
#rpm -qa |grep libselinux-python
#yum install libselinux-python -y

ansible命令参数

-m MODULE_NAME, 模块名字,默认command
-a MODULE_ARGS, 模块参数
-f FORKS        并发进程数,默认5个。
-i INVENTORY(default=/etc/ansible/hosts)指定主机列表文件

ansible模块查看和帮助

查找模块
ansible-doc -l   
查看某个模块的具体参数帮助
ansible-doc -s command 

command模块

1)功能说明:
command  Executes a command on a remote node 
功能说明:执行一个命令在远程节点上
操作实践:
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"

你可能感兴趣的:(04-24 day 39)