• ansible 开源批量管理服务器工具


    Ansible 是一款基于 Python 开发的自动化运维工具,可以进行配置管理、批量部署等功能。对于机器较多的场景,可以使用 Ansible 来免去重复敲命令的烦恼。

    1. 安装ansible
      yum -y install ansible
      配置文件路径/etc/ansible/ansible.cfg
      修改配置参数无需重启ansible
      修改参数:host_key_checking = False (不修改可能出现无法连接服务器的情况)
      提示:Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host.
    2. 创建需要管理的服务器列表iplist
      默认的iplist为:/etc/ansible/hosts
      [group] 是组的别名,可以通过该组名对其下的所有机器进行控制
      每一行内容分别是:机器别名、机器 IP、ssh 访问时使用的用户名、ssh 访问时使用的端口、ssh 访问时使用的密码
      格式如下:
      [web]
      web_Server_0001 ansible_ssh_host=127.0.0.1 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass='passwd'
      web_Server_0002 ansible_ssh_host=127.0.0.1 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass='passwd'
      [db]
      db_Server_0001 ansible_ssh_host=127.0.0.1 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass='passwd'
      分别创建1组web服务器,1组db服务器,若密码有特殊字符,一定要使用单引号引起来,否则可能出现无法登陆服务器
    3. 日常脚本使用介绍
      eg:显示列表下所有服务器的hostname
      ansible all -i iplist -m shell -a "hostname"
      all 代表所有组,也可指定组名
      -i 指定iplist文件
      -m 指定运行模块名称,如shell
      -a 模块下可调用的命令
      eg:给列表下服务器安装程序
      ansible all -i iplist -m yum -a "name=vim"
      命令可嵌套,可使用管道符
      eg:

      使用ansible分发文件
      ansible all -i iplist -m copy -a "src=/home/file dest=/home/"

  • 相关阅读:
    Angular Chart 使用说明(基于angular工程)
    文件系统(node.js学习笔记)
    错误名称:Uncaught SyntaxError: Unexpected token <
    错误名称:Uncaught SyntaxError: Unexpected identifier
    CSS自定义滚动条样式
    AngularJS directive简述
    Angular.forEach用法
    AngularJS操作DOM——angular.element
    vue自定义过滤器的创建和使用
    了解MIP(Mobile Instant Pages)
  • 原文地址:https://www.cnblogs.com/Mrhuangrui/p/6698795.html
Copyright © 2020-2023  润新知