zoukankan      html  css  js  c++  java
  • 运维自动化之1

    2000 - 2016 年,维护的小型机、linux刚开始的2台增加到上千台,手工检查、日常版本升级需要管理太多设备,必须通过运维自动化实现

    特别是版本升级,需要到同类机器部署代码、起停设备,必须在一台主控机上完成代码分发、远程服务起停、服务验证验证

    2016年开始使用 pssh ,后改用 ansible ,ansible 配置如下

    一、配置ssh免密码登录

    #cd /root/.ssh

    免交互生成密钥

    #echo -e " " |ssh-keygen -t rsa -N ""

    发送锁头给 web1机器

    #ssh-copy-id -i /root/.ssh/id_rsa.pub root@web1 ,如下

    [root@fox .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@web1
    The authenticity of host 'web1 (192.168.80.131)' can't be established.
    RSA key fingerprint is 9c:c0:e2:2b:6f:88:c8:b1:25:47:f6:4b:fa:8f:cd:00.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'web1,192.168.80.131' (RSA) to the list of known hosts.
    root@web1's password:

    [root@fox ~]# sed -i 's#fox#web01#g' /etc/sysconfig/network
    [root@fox ~]# more /etc/sysconfig/network

    注:如果机器不同,需要自动应答时,可采用 expect 软件实现 ,expect 用法查见

    https://www.cnblogs.com/yangmingxianshen/p/7967040.html

    二、安装ansible

    1. Master端安装EPEL第三方yum源
    # rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/i386/epel-release-6-8.noarch.rpm
    2.安装Ansible
    # yum install ansible -y
    出现 Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
    解决方法: 一句话:把/etc/yum.repos.d/epel.repo,文件第3行注释去掉,把第四行注释掉。
    打开/etc/yum.repos.d/epel.repo,将
    [epel]
    name=Extra Packages for Enterprise Linux 6 - $basearch
    #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
    mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
    修改为
    [epel]
    name=Extra Packages for Enterprise Linux 6 - $basearch
    baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
    #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
    3。再清理源,重新安装
    yum clean all
    这一次安装成功
    # yum install ansible -y

    注:问题解决参考了https://www.cnblogs.com/dadong616/p/5062727.html

    三、ansible 使用

    1.远程命令模块   command: 执行远程主机SHELL命令 (这是在远程机器上执行命令)

    # ansible webservers -m command -a "free -m"

    2.script: 远程执行MASTER本地SHELL脚本.(类似scp+shell) 注意,这个脚本要放在 MASTER ,很实用的命令

    #echo "hostname" > /tmp/test1.sh
    #chmod 700 /tmp/test1.sh

    # ansible web -m script -a "/tmp/test1.sh"

    web1 | SUCCESS => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to web1 closed.
    ", 
    "stderr_lines": [
    "Shared connection to web1 closed."
    ], 
    "stdout": "web01
    ", 
    "stdout_lines": [
    "web01"
    ]
    }

    其他模块和用法,详见 https://www.cnblogs.com/cheyunhua/p/8151603.html

    总结:

    1.工具使用提高效率

    2 脚本整理好,随时使用

    3 用于日常版本升级,一键部署环境、快速定位诊断等场合

  • 相关阅读:
    新型监控告警工具prometheus(普罗米修斯)入门使用(附视频讲解)
    Nginx、OpenResty和Kong的基本概念与使用方法
    Kubernetes网络方案Flannel的学习笔记
    新型监控告警工具prometheus(普罗米修斯)的入门使用(附视频讲解)
    超级账本HyperLedger:Fabric nodejs SDK的使用(附视频讲解)
    超级账本HyperLedger:Fabric使用kafka进行区块排序(共识,附视频讲解)
    超级账本HyperLedger:Fabric Golang SDK的使用(附视频)
    超级账本HyperLedger:Fabric的Chaincode(智能合约、链码)开发、使用演示
    超级账本HyperLedger:Fabric源码走读(一):源代码阅读环境准备
    超级账本HyperLedger:Fabric从1.1.0升级到1.2.0
  • 原文地址:https://www.cnblogs.com/micfox/p/10992999.html
Copyright © 2011-2022 走看看