Ansible 入门 (1) - 安装和配置
本文参考 《Ansible 自动化运维和最佳实践》,这两天刚读这本书,写写总结。主控机环境是 centos 7,被控机均是 centos 6.8 。
确保 python 版本大于 2.6
[root@localhost ~]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
1、源码安装
可以从 github 下载源码后安装
cd /data1
git clone git://github.com/ansible/ansible.git --recursive
cd ./ansible
easy_install pip
yum -y install gcc gcc-c++ autoconf
pip install paramiko PyYAML Jinja2 httplib2 six
source ./hacking/env-setup
如果 github更新版本则需要更新 git 源码树和 git 中的 submodules,该模块是指向 Ansible 自身的模块
重启系统后可能会发现 ansible 命令出问题,这时候需要再次 source,暂时不知道怎么解决,推荐大家使用 yum 源安装。
2、yum 源安装 (推荐)
以下是 EPEL 的浙江大学 yum 源地址,经常更新,如果找不到则直接往上级目录找
- RHEL(centos 5)
rpm -Uvh http://mirrors.zju.edu.cn/epel/5/x86_64/epel-release-5-4.noarch.rpm
- RHEL(centos 6)
rpm -Uvh http://mirrors.zju.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
- RHEL(centos 7)
rpm -Uvh http://mirrors.zju.edu.cn/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
# yum clean all
# yum update -y
yum install ansible -y
yum 源更新一般会比较久,请耐心等待,如果不更新可能会遇到其他问题。
如果 rpm 安装错了,例如 centos6 安装了 centos7 的 yum 源, 则会出现 Error: xz compression not available 的错误,需要先卸载
yum remove epel-release
rm -rf /var/cache/yum/x86_64/6/epel/
然后重新执行正确命令
yum 源安装可能会导致 ansible 安装的路径是在 python2.6 下,如果是这种情况则可以将 python2.6/site-packages/ 中的 ansible 和 ansible-2.2.1.0-py2.6.egg-info/ 复制到 python2.7/site-packages/ 目录下,并修改 /usr/bin/ansible* 的 python 路径为 2.7,删掉 2.6 下的原来目录即可
3、验证版本
[root@localhost ansible]# ansible --version
ansible 2.3.0 (devel 72c96b3ac3) last updated 2017/03/04 12:07:12 (GMT +800)
config file =
configured module search path = Default w/o overrides
python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
4、配置文件 ansible.cfg
如果通过 yum 安装或者 pip 安装,那么 ansible.cfg 存放在 /etc/ansible 目录下,如果通过 github 安装则在仓库中的 examples 目录下找到 ansible.cfg 然后拷贝到 /etc/ansible 目录下即可
[defaults] # some basic default values... inventory = /etc/ansible/hosts
library = /usr/share/my_modules/
module_utils = /usr/share/my_module_utils/
remote_tmp = ~/.ansible/tmp
local_tmp = ~/.ansible/tmp
forks = 5
poll_interval = 15
sudo_user = root
#ask_sudo_pass = True
#ask_pass = True
transport = smart
remote_port = 22
module_lang = C
module_set_locale = False
log_path = /var/log/ansible.log
host_key_checking = True
[root@localhost examples]# ansible --version
ansible 2.3.0 (devel 72c96b3ac3) last updated 2017/03/04 12:07:12 (GMT +800)
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/usr/share/my_modules/']
python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
这时候发现 config file 已经有值了
5、配置 inventory
在步骤 [4] 中已经配置了 inventory = /etc/ansible/hosts,所以在主控机编写配置如下
[root@localhost ~]# vim /etc/ansible/hosts
[webserver]
192.168.34.129
192.168.34.130
6、配置 linux 主机 ssh 无密码访问
如果每台被控机密码都一样则没必要完成这一步,可以在命令行上增加 -k password 参数。
首先生成密钥对,然后将 id_rsa.pub 使用 ssh-copy-id 发送到所有的被控机即可。
ssh-keygen
/usr/bin/ssh-copy-id [-h|-?|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
[root@localhost ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.34.129
The authenticity of host '192.168.34.129 (192.168.34.129)' can't be established.
RSA key fingerprint is 0e:a7:fc:55:fe:91:fa:e8:c5:b6:44:f2:d0:08:a1:8f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.34.129's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@192.168.34.129'"
and check to make sure that only the key(s) you wanted were added.
Ansible 入门 (1) - 安装和配置的更多相关文章
- Redis入门 -- Redis安装与配置
Redis入门 -- Redis安装与配置 Redis的安装 Redis的安装,我这里使用的是虚拟机. 为了让主机和虚拟机之间可以顺利通信,按照以下步骤进行: 1. 将网络连接模式改为桥接 2. re ...
- Ansible 入门指南 - 安装及 Ad-Hoc 命令使用
安装及配置 ansible Ansilbe 管理员节点和远程主机节点通过 SSH 协议进行通信.所以 Ansible 配置的时候只需要保证从 Ansible 管理节点通过 SSH 能够连接到被管理的远 ...
- Redis快速入门:安装、配置和操作
本文是有关Redis的系列技术文章之一.在之前的文章中介绍了<Redis快速入门:初识Redis>,对Redis有了一个初步的了解.今天继续为大家介绍Redis如何安装.配置和操作. 系列 ...
- ansible介绍、安装与配置
一.ansible简介 (1)简介: Ansible是近年越来越火的一款自动化运维工具,其主要的功能是帮助运维实现IT工作的自动化,降低人为操作失误.提高业务自动化率,常用于软件部署.配置自动化.管理 ...
- MongoDB一:入门(安装与配置)
一.简介 MongoDB 是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. mongoDB MongoDB 是一个介于关系数据库和非关系数据库 ...
- 学习MongoDB 一:MongoDB 入门(安装与配置)
一.简介 MongoDB一种非关系型数据库(NoSql),是一种强大.灵活.可扩展的数据存储方式,因为MongoDB是文档模型,自由灵活很高,可以让你在开发过程中畅顺无比,对于大数据量.高并发.弱事务 ...
- jenkins入门-----(1)安装、配置
Jenkins概念 Jenkins是一个开源的.可扩展的持续集成.交付.部署(软件/代码的编译.打包.部署)的基于web界面的平台.允许持续集成和持续交付项目,无论用的是什么平台,可以处理任何类型的构 ...
- ansible之一:安装与配置
ansible特点: 1.不需要安装客户端,通过sshd去通信 2.基于模块工作,模块可以由任何语言开发 3.不仅支持命令行试用模块,也支持yaml格式得playbook 4.支持sudo 5.有提供 ...
- Ansible 笔记 (1) - 安装和配置
本文参考 <Ansible 自动化运维和最佳实践>,这两天刚读这本书,写写总结.主控机环境是 centos 7,被控机均是 centos 6.8 . 确保 python 版本大于 2.6 ...
随机推荐
- 连接linux主机
需要工具:putty PuTTY是一个Telnet.SSH.rlogin.纯TCP以及串行接口连接软件 远程连接Linux云服务器-命令行模式 1.远程连接工具.目前Linux远程连接工具有很多种,您 ...
- 1.1.2.托管对象模型(Core Data 应用程序实践指南)
托管对象模型即对象图,可以看成实体类的描述,规定了数据字段. 要想创建托管对象模型,需生成NSManagedObjectModel类的实例.
- HTML/CSS/Javascript调试入门(转)
推荐Chrome作为开发工具(FF可以使用FireBug,IE8和之后的版本也有自己的调试工具) 1.HTML的调试 将鼠标放在任意元素上,右键Inspect Element,即可查看该元素的HTML ...
- iframe截取网站部分内容实现思路及代码
使用iframe可以截取网站的部分内容,主要配合width.height.overflow等属性来实现的,具体示例如下,需要的朋友不要错过. <div style="width:630 ...
- jQuery插件Flot实战Demo
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- Struts1、WebWork、Struts2介绍
一.Struts1 1.Struts1原理简介 Struts1框架以ActionServlet作为控制器核心,整个应用由客户端请求驱动.当客户端向Web应用发送请求时,请求被Struts1的核心控制器 ...
- The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
skip-grant-tables下 GRANT ALL PRIVILEGES ON *.* TO helei IDENTIFIED BY 'MANAGER' WITH GRANT OPTION; 执 ...
- 数据库设计的误区—>CHAR与VARCHAR
字符型字段是数据库表中最常见的字段,而字符型字段又分为定长和变长两种.一般来说,VARCHAR类型用于存储内容长度变化较大的数据,CHAR类型用于存储内容长度没有变化或变化不大的数据. 在数据的内部存 ...
- Drawerlayou与ScrollView的介绍
Drawerlayout侧滑 Drawerlayout是Support Library包中实现了侧滑菜单效果的控件. 滚动条(ScrollView) ScrollView和HorizontalScro ...
- jQuery如何实现点击页面获得当前点击元素
获得jquery对象: function foo(e){ var obj = $(e.target); }