Ansible自动化运维详细安装及使用

幸运草 2020年10月11日14:34:22运维评论阅读模式

wordpress主题底部页脚footer美化

底部页脚footer美化对于Wordpress用户,我们可以打开主题的footer.php文件进行修改。 在适当位置添加下列代码即可,使用知更鸟主题的用户可以将代码放到footer.php文件的第13和14行之间。

 Ansible简介

·Ansible是2013年推出的一款IT自动化和DevOps软件,2015年被RedHat收购,是基于Python语言开发

·— 只需要SSh和Python即可使用

·— 无客户端

·— Ansible功能强大,模块丰富

·— 基于Python开发,做二次开发容易

·— 使用公司较多,社区活跃

·Ansible实现批量操作系统配置、批量部署、批量运行命令等功能

   实验环境用机

1)实验用机为5台,一台为管理主机,其余4台位被管理主机

2)在管理主机上配置本地解析

[root@ansible ~]# vim /etc/hosts

192.168.0.25 web1

192.168.0.26 web2

192.168.0.27 web3

192.168.0.28 web4

3)在管理主机生成公私钥

[root@ansible ~]# ssh-keygen

4)将公钥传递到被管理节点

[root@ansible~]# for i in web1 web2 web3 web4

> do

> ssh-copy-id $i

> done

5)测试免密登录

[root@ansible ~]# ssh  web1

[root@ansible ~]# ssh  web2

[root@ansible ~]# ssh  web3

[root@ansible ~]# ssh  web4

    Ansible安装

1)配置YUM源,指定源地址为阿里源

[root@ansible~]#rm-rf /etc/yum.repos.d/*      //清空YUM仓库路径

[root@ansible~]#vim /etc/yum.repos.d/centso.repo//创键仓库文件并指定仓库地址

[centos_file]

name=centos7

baseurl=file:///root/centos7

enabled=1

gpgcheck=0

[epel]

name=ailiyun

baseurl=http://mirrors.aliyun.com/epel/7/x86_64/

enabled=1

gpgcheck=0

[centos]

name=cobbler

baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/

enabled=1

gpgcheck=0

2)安装Ansible

[root@ansible ~]# yum -y install ansible

3)查看Ansible版本

[root@ansible ~]# ansible --version

   定义主机分组

1)查看Ansible默认配置文件

[root@ansible ~]# vim /etc/ansible/ansible.cfg

Ansible自动化运维详细安装及使用
2)修改定义主机文件指定主机分组

[root@ansible ~]# vim /etc/ansible/hosts

.. ..

[webserver]//定义组名

192.168.0.25//组内主机

192.168.0.26

192.168.0.27

192.168.0.28

3)查看组内主机

[root@ansible ~]# ansible webserver --list-host

4)测试管理主机与被管理主机联通性

[root@ansible ~]# ansible webserver -m ping    //-m 调用模块,ping为模块名

    Ansible命令格式

命令格式:ansible  组名  -m 模块名 -a 模块参数…

-M    指定模块路径

-m    使用模块,默认为command模块

-a    or --args模块参数

-i    inventory 文件路径,或脚本文件

-k    使用交互式登录密码

-e    定义变量

-v    详细信息

Ansible模块

-ansible-doc-l     //模块手册,相当于shell的man

-ping     //测试ssh联通性,ping模块没有参数

-command     //默认模块,远程执行命令

-shell     //命令模块,和command模块类似,区别在于shell模块通过/bin/bash执行命令

-raw     //命令模块,和shell模块类似,区别在于raw没有chdir、create、remove参数

-script     //执行脚本模块

-copy     //复制模块,将本地文件复制到远程主机

-src       //复制远程主机文件到本地

-dest     //必须选,远程主机的绝对路径,如果源文件是目录,那改路径必须是目录

-yum     //软件包管理模块

   使用shell模块批量配置与管理

1)关闭防火墙

[root@ansible ~]# ansible webserver -m shell -a 'systemctl stop firewalld'

2)设置防火墙开机不自起

[root@ansible ~]# ansible webserver -m shell -a 'systemctl disable firewalld'

3)关闭SELinux

[root@ansible ~]# ansible webserver -m shell -a 'setenforce 0'

4)安装httpd服务

[root@ansible ~]# ansible webserver -m shell -a 'yum -y install httpd'

5)启动服务

[root@ansible ~]# ansible webserver -m shell -a 'systemctl start httpd'

6)在本地编写页面执行批量拷贝

[root@ansible ~]# echo "<marquee><font color=red><h1>新盟教育<marquee>" > index.html

7)使用copy模块远程拷贝

[root@ansible ~]# ansible webserver -m copy -a 'src=/root/index.html dest=/var/www/html/'

8)浏览器访问测试

192.168.0.25

  

什么是SEO,SEO能给企业带来多少收益

SEO汉译为搜索引擎优化,是一种方式。利用搜索引擎的规则提高网站在有关搜索引擎内的自然排名,目的是为网站提供生态式的自我营销解决方案,让其在行业内占据领先地位,获得品牌利益;SEO包含站外SEO和站内SEO两方面;为了从搜索引擎中获得更多的免费流量,从网站结构…

  • 赞助本站
  • 微信扫一扫
  • weinxin
  • 加入Q群
  • QQ扫一扫
  • weinxin
幸运草

发表评论