zoukankan      html  css  js  c++  java
  • Ansible

    参考

    setuptools安装出错参考  出错参考

     configure.ac:418: error: possibly undefined macro: AC_LIBTOOL_WIN32_DLL      If this token and others are legitimate, please use m4_pattern_allow.      See the Autoconf documentation.(解决方法:yum install install libtool)

    SaltStack详细部署

    1、yum源安装

    以centos为例,默认在源里没有ansible,不过在fedora epel源里有ansible,配置完epel 源后,可以直接通过yum 进行安装。这里以centos6.8为例:

     注意用root用户安装

    1. # yum install http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
    2. # yum install -y ansible

    Dependency Installed:安装了如下
    PyYAML.x86_64 0:3.10-3.1.el6 libyaml.x86_64 0:0.1.3-4.el6_6
    python-babel.noarch 0:0.9.4-5.1.el6 python-crypto.x86_64 0:2.0.1-22.el6
    python-crypto2.6.x86_64 0:2.6.1-2.el6 python-httplib2.noarch 0:0.7.7-1.el6
    python-jinja2-26.noarch 0:2.6-3.el6 python-keyczar.noarch 0:0.71c-1.el6
    python-paramiko.noarch 0:1.7.5-2.1.el6 python-pyasn1.noarch 0:0.0.12a-1.el6
    python-setuptools.noarch 0:0.6.10-3.el6 python-simplejson.x86_64 0:2.0.9-3.1.el6
    python-six.noarch 0:1.9.0-2.el6 sshpass.x86_64 0:1.05-1.el6

    默认/etc/ansible/hosts下的主机进行操作

    ansible -h 查看帮助

    [root@bogon ~]# ansible -i /etc/ansible/hosts zzx -u root -m command -a 'ls /home/' -k

    -i指定配置文件位置 zzx组下的主机 root账户 -k提示输入密码 -m输入模块 -a输入命令

    1)SSH免密钥登录设置(配置这个之后就不用-k)

    ## 生成公钥/私钥

    # ssh-keygen -t rsa -P ''

    wKioL1RsyCTC94M0AACbRu5nOSQ166.jpg

    ## 写入信任文件(将/root/.ssh/id_rsa.pub分发到其他服务器,并在所有服务器上执行如下指令):

    # cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys  (或者scp过来 [root@localhost ~]# scp 192.168.1.112:/root/.ssh/id_rsa.pub   /root/.ssh/authorized_keys)

    # chmod 600 /root/.ssh/authorized_keys

    注意生成id_rsa.pub时的登录账户名称和你登录的时候要一样 具体可以cat id_rsa.pub看看就知道了 你用root生成却用其他用户去登录就不能免密码

    ansible all -m setup -k        setup模块用于收集远程主机的一些基本信息。

     playbook

    vars_files

     1、test.yml如下 

    2、variables

    3、files/test1.text

    ansible-playbook test.yml

    正确运行会在其他机器下创建文件/tem/test1.txt

     vars_prompt 通过交换方式输入值

     test1.yml

    提示输入变量值,prompt是提示语,name就是输入的变量会赋值给http, private为yes时输入的内容不显示在屏幕上 就像隐藏密码输入一样,为no时输入内容显示在屏幕上

    files/test.txt

    这个变量没有值 需要交互输入值

    ansible-playbook test1.yml

    按提示输入值,最后其他机器就会生成/tmp/test.txt 内容为输入的值

     

    暂停模块,提示用户操作(回车继续,Ctril C就取消,   没有什么实际意义),

    等待五秒继续执行

    pause

     ansible-playbook memcached.yml  安装memcached并修改配置文件后启动

    hosts:主机组

    user:用户名

    name,yum:安装memcached

    name,set_fat: 设置参数 总内存/4

    name,template:拷贝配置文件

    notify:重启memcached(调用下面的handlers)

    files/memcached.j2内容如下:

    memcached_size如果存在就设为这个值 不存在就设为1024

     卸载memcached

    handlers不会执行 ,因为没有调用,如果卸载了再重启会报错的

     

     

    yum安装

    service启动

     wait_for 当8080端口开始监听的时候就代表启动完成

    运行报错结局

    [root@zzx ~]# ansible all -m ping
    192.168.1.116 | FAILED! => {
    "changed": false,
    "failed": true,
    "msg": "this module requires key=value arguments (['<<INCLUDE_ANSIBLE_MODULE_ARGS>>'])"

    一直报这个错误 重装了ansible也无法解决,最后把远程机器重装了再运行提示就正常如下

    paramiko: The authenticity of host '192.168.1.115' can't be established.
    The ssh-rsa key fingerprint is e3115012d436de121fd908e05aaab2f9.
    Are you sure you want to continue connecting (yes/no)?

    ,说明还是远程机器认证的key的问题导致的无法连接的问题,因为ansible主机没动

     template第12张图到第3张图 参数被替换了

    group_names代表当前ip所在的组;mts_node里面的ip只属于mts_node组属于in group_names的情况, 非mts_node组的机器就属于not in group_names的情况

    %是固定语法   for ip in ……  是指如果有多个ipv4地址 那就会循环全部打印出来  {{ ip }}会吧地址打印出来

    合并ssh的密钥文件

    file创建目录/opt/sshkeys

    copy复制文件到with_items的三台主机  {{ item }}就是那三个主机  keys.dan.pub  keys.kate.pub   keys.mal.pub  三个文件复制到/opt/sshkeys下 然后合并/opt/sshkeys下的文件到/root/.ssh/authorized_keys

     

     

    centos和Ubuntu 安装Apache的方式不同

     

     代理服务器下载 一般用wget就可以了 不用这个

  • 相关阅读:
    怎么把自己电脑上的文件传到服务器本地上
    查看hive中某个表中的数据、表结构及所在路径
    python2.7读汉字的时候出现乱码,如何解决
    如何连接服务器客户端
    java常用问题排查工具
    netty源码分析之一:server的启动
    java AQS 一:
    netty源码分析之二:accept请求
    java Resource
    二:基础概述netty
  • 原文地址:https://www.cnblogs.com/hanxing/p/5742307.html
Copyright © 2011-2022 走看看