zoukankan      html  css  js  c++  java
  • python运维之saltstack方式

    # 1. 安装saltstack
    #       rpm --import https://repo.saltstack.com/yum/redhat/6/x86_64/latest/SALTSTACK-GPG-KEY.pub
    #
    #
    """
            Master: yum install salt-master
           Master准备:
                a. 配置文件,监听本机IP
                    vim /etc/salt/master
                    interface: 本机IP地址
                b. 启动master
                    /etc/init.d/salt-master start
    
    
            Slave:  yum install salt-minion
            Slave准备:
                a. 配置文件,连接那个master
                    vim /etc/salt/minion
                    master: 远程master地址
                b. 启动slave
                    /etc/init.d/salt-minion start
    
    2. 创建关系
        查看
        Master:salt-key -L
            Accepted Keys:
            Denied Keys:
            Unaccepted Keys:
                c1.com
                c2.com
                c3.com
            Rejected Keys:
        接受
        Master:salt-key -a c1.com
            Accepted Keys:
                c1.com
                c2.com
            Denied Keys:
            Unaccepted Keys:
                c3.com
            Rejected Keys:
    
    
    3. 执行命令
        master:
            salt 'c1.com' cmd.run  'ifconfig'
    
        import salt.client
        local = salt.client.LocalClient()
        result = local.cmd('c2.salt.com', 'cmd.run', ['ifconfig'])
    
    """
    # ################## 获取今日未采集主机名 ##################
    #result = requests.get('http://www.127.0.0.1:8000/assets.html')
    # result = ['c1.com','c2.com']
    
    
    # ################## 远程服务器执行命令 ##################
    # import subprocess
    # result = subprocess.getoutput("salt 'c1.com' cmd.run  'ifconfig'")
    #
    # import salt.client
    # local = salt.client.LocalClient()
    # result = local.cmd('c2.salt.com', 'cmd.run', ['ifconfig'])
    
    
    # ##################  发送数据 ##################
    # requests.post('http://www.127.0.0.1:8000/assets.html',data=data_dict)
  • 相关阅读:
    scp 跨服务器传数据
    Mongo启动失败解决方案
    centos7 NET模式配置虚拟机
    centos7虚拟机配置桥接模式
    Linux centos7 查看cpu 磁盘 内存使用情况
    centos7修改时间和时区
    fiddler培训
    docker学习笔记
    docker-ce安装官翻
    Nginx+Tomcat简单负载均衡
  • 原文地址:https://www.cnblogs.com/GodLv/p/9842351.html
Copyright © 2011-2022 走看看