zoukankan      html  css  js  c++  java
  • CMDB资产采集

    Paramiko

    import paramiko
     
    private_key = paramiko.RSAKey.from_private_key_file('/home/auto/.ssh/id_rsa')
     
    # 创建SSH对象
    ssh = paramiko.SSHClient()
    # 允许连接不在know_hosts文件中的主机
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    # 连接服务器
    ssh.connect(hostname='c1.salt.com', port=22, username='maple', key=private_key)
     
    # 执行命令
    stdin, stdout, stderr = ssh.exec_command('df')
    # 获取命令结果
    result = stdout.read()
     
    # 关闭连接
    ssh.close()
    paramiko

    SaltStack

    1. 安装和配置

    """
    1. 安装salt-master
        yum install salt-master
    2. 修改配置文件:/etc/salt/master
        interface: 0.0.0.0    # 表示Master的IP 
    3. 启动
        service salt-master start
    """
    Master
    """
    1. 安装salt-minion
        yum install salt-minion
    
    2. 修改配置文件 /etc/salt/minion
        master: 10.211.55.4           # master的地址
        或
        master:
            - 10.211.55.4
            - 10.211.55.5
        random_master: True
    
        id: c2.salt.com                    # 客户端在salt-master中显示的唯一ID
    3. 启动
        service salt-minion start
    """
    Slave

    2. 授权

    """
    salt-key -L                # 查看已授权和未授权的slave
    salt-key -a  salve_id      # 接受指定id的salve
    salt-key -r  salve_id      # 拒绝指定id的salve
    salt-key -d  salve_id      # 删除指定id的salve
    """
    Master

    3. 执行命令

    在master服务器上对salve进行远程操作

    salt 'c2.salt.com' cmd.run  'ifconfig'
    基于shell命令
    import salt.client
    local = salt.client.LocalClient()
    result = local.cmd('c2.salt.com', 'cmd.run', ['ifconfig'])
    基于Salt的API
  • 相关阅读:
    codevs 3971 航班
    2015山东信息学夏令营 Day4T3 生产
    2015山东信息学夏令营 Day5T3 路径
    Tyvj 1221 微子危机——战略
    清北学堂模拟赛 求和
    NOIP2012同余方程
    NOIP2009 Hankson的趣味题
    bzoj1441 MIN
    国家集训队论文分类
    贪心 + DFS
  • 原文地址:https://www.cnblogs.com/maple-shaw/p/7900950.html
Copyright © 2011-2022 走看看