Ansible安装

一、完成虚拟机的安装和配置

1.对三台虚拟机设置静态IP

1).编辑配置文件

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=b583f4e3-390a-400a-a336-45390baf1fac
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.51.133
GATEWAY=192.168.51.2
NETMASK=255.255.255.0
DNS1=8.8.8.8
DNS2=8.8.4.4

2).重启网络

[root@localhost ~]# systemctl restart network

二、开始安装Ansible

1.安装EPEL源

[root@localhost ~]# yum install epel-release

EPEL源安装完成之后,方可安装Ansible。在安装之前需要关闭防火墙与SELinux,命令如下:

1).关闭防火墙

[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

2).查看防火墙状态

[root@localhost ~]# systemctl status firewalld

显示为dead则就是关闭防火墙了。

3).关闭SELinux

(1)查看状态

[root@localhost ~]# getenforce Enforcing

该命令有三种状态结果

Enforcing (1) 强制模式 ---安全级别最高,相对的操作权限更低

Permissive (0) 自由模式 ---安全级别较低,操作权限稍高

Disabled 关闭模式 ---永久关闭模式,安全级别没有,操作权限最高

(2)开启自由模式/临时关闭:setenforce 0 (其实就相当于将状态改为上面的Permissive 模式)

[root@localhost ~]# setenforce 0

(3)切换为强制模式:setenforce 1 (将状态切回到Enforcing模式)

[root@localhost ~]# setenforce 1

(4)永久关闭Selinux

修改/etc/sysconfig/selinux 文件中的配置并且重启服务器

[root@localhost ~]# vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

2.安装Ansible

1.安装Ansible

[root@localhost ~]# yum install ansible

2.查看Ansible的版本

[root@localhost ~]# ansible --version
ansible 2.9.25
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Oct 14 2020, 14:45:30) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

3.配置免密登录

1.在安装Ansible的机器上配置

[root@localhost ~]# ssh-keygen -t rsa

2.将公钥下发到各个节点,包括本节点

[root@localhost ~]# ssh-copy-id 192.168.51.131

[root@localhost ~]# ssh-copy-id 192.168.51.132

[root@localhost ~]# ssh-copy-id 192.168.51.133

3.将.ssh文件发送至其余的节点

[root@localhost ~]# scp -r /root/.ssh/* root@192.168.51.131:/root/.ssh

[root@localhost ~]# scp -r /root/.ssh/* root@192.168.51.132:/root/.ssh

完成免密登录

4.查看安装是否完成

[root@localhost ~]# ansible-doc -l

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值