一、ansible-01準備階段
阿新 • • 發佈:2021-08-02
1.1 建立6臺主機
序號 | 主機名 | ip地址 | 主機型別 |
1 | ansible | 192.168.0.10 | 管理主機 |
2 | web1 | 192.168.0.11 | 託管主機 |
3 | web2 | 192.168.0.12 | 託管主機 |
4 | db1 | 192.168.0.21 | 託管主機 |
5 | db2 | 192.168.0.22 | 託管主機 |
6 | cache | 192.168.0.33 | 託管主機 |
1.2 按要求配置6臺主機(這裡以管理主機為例)
1.2.1 主機名配置
[root@localhost ~]# echo ansible > /etc/hostname
1.2.2 ip配置
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
DEVICE="eth0"
ONBOOT="yes"
IPV6INIT="no"
BOOTPROTO="static"
IPADDR="192.168.0.10"
NETMASK="255.255.255.0"
GATEWAY="192.168.0.254"
TYPE="Ethernet"
*其餘主機參照以上配置
1.2.3 hosts檔案的配置
ansible:主機上配置ip與主機名對應關係,配置檔案:/etc/hosts
[root@host2 ~]# vim /etc/hosts
192.168.0.10 ansible
192.168.0.11 web1
192.168.0.12 web2
192.168.0.21 db1
192.168.0.22 db2
192.168.0.33 cache
1.2.4 免密碼登入
管理主機可以登入其他託管主機,無需密碼
[root@ansible ~]# ssh-keygen -t rsa -b 2048 -N ' '
[root@ansible .ssh]# cd /root/.ssh/
[root@ansible .ssh]# for i in web1 web2 db1 db2 cache; do ssh-copy-id -i id_rsa.pub ${i}; done