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='wupeiqi', key=private_key)
     
    # 执行命令
    stdin, stdout, stderr = ssh.exec_command('df')
    # 获取命令结果
    result = stdout.read()
     
    # 关闭连接
    ssh.close()
    View Code

    StaltStack

    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 """
     2 1. 安装salt-minion
     3     yum install salt-minion
     4 
     5 2. 修改配置文件 /etc/salt/minion
     6     master: 10.211.55.4           # master的地址
     7  8     master:
     9         - 10.211.55.4
    10         - 10.211.55.5
    11     random_master: True
    12 
    13     id: c2.salt.com                    # 客户端在salt-master中显示的唯一ID
    14 3. 启动
    15     service salt-minion start
    16 """
    Slave

    2.授权

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

    3.执行命令

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

    salt 'c2.salt.com' cmd.run  'ifconfig'ji
    基于shell命令
    import salt.client
    local = salt.client.LocalClient()
    result = local.cmd('c2.salt.com', 'cmd.run', ['ifconfig'])
    基于Salt的API

    #补充saltstack的安装

    1.执行命令:rpm --import https://repo.saltstack.com/yum/redhat/7/x86_64/latest/SALTSTACK-GPG-KEY.pub
    
    2.在/etc/yum.repos.d/这个目录下创建一个文件:saltstack.repo
    touch saltstack.repo
    
    3.在文件中粘贴下面的代码:
    [saltstack-repo]
    name=SaltStack repo for RHEL/CentOS $releasever
    baseurl=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest
    enabled=1
    gpgcheck=1
    gpgkey=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest/SALTSTACK-GPG-KEY.pub
    View Code
  • 相关阅读:
    rz/sz yum install
    MyEclipse使用总结——MyEclipse10安装SVN插件
    报错:1130-host ... is not allowed to connect to this MySql server
    linux(centos)搭建svn
    eclipse Ctrl +左键查看源代码Source not found
    win7环境下配置Java环境
    运行phpize失败排查
    lamp环境centos5.10,phpprotobuf模块安装,及简单应用
    阿里云服务器centos5.10安装lamp环境
    php 面向对象知识点
  • 原文地址:https://www.cnblogs.com/zhaochangbo/p/7510492.html
Copyright © 2011-2022 走看看