首页 > 其他分享 >satlstack常用命令

satlstack常用命令

时间:2023-06-02 11:45:19浏览次数:34  
标签:get root cmd file 常用命令 satlstack cp salt

查看解压和压缩命令支持的格式和命令

[root@host106 salt]# salt '*' sys.list_functions archive
host104:
    - archive.cmd_unzip
    - archive.cmd_zip
    - archive.gunzip
    - archive.gzip
    - archive.is_encrypted
    - archive.list
    - archive.rar
    - archive.tar
    - archive.unrar
    - archive.unzip
    - archive.zip
host105:
    - archive.cmd_unzip
    - archive.cmd_zip
    - archive.gunzip
    - archive.gzip
    - archive.is_encrypted
    - archive.list
    - archive.rar
    - archive.tar
    - archive.unrar
    - archive.unzip
    - archive.zip

salt远程压缩文件命令

[root@host106 ~]# salt '*' archive.zip /opt/t.zip /tmp/t1,/tmp/t2
host104:
    - tmp/t1
    - tmp/t2
host105:
    - tmp/t1
    - tmp/t2

salt远程解压命令

[root@host106 ~]# salt '*' archive.unzip /opt/t.zip /tmp/
host104:
    - tmp/t1
    - tmp/t2
host105:
    - tmp/t1
    - tmp/t2

 

二、cmd模块命令

查看cmd模块支持的命令

[root@host106 ~]# salt '*' sys.list_functions cmd
host104:
    - cmd.exec_code
    - cmd.exec_code_all
    - cmd.has_exec
    - cmd.powershell
    - cmd.retcode
    - cmd.run
    - cmd.run_all
    - cmd.run_bg
    - cmd.run_chroot
    - cmd.run_stderr
    - cmd.run_stdout
    - cmd.script
    - cmd.script_retcode
    - cmd.sdecode
    - cmd.shell
    - cmd.shell_info
    - cmd.shells
    - cmd.tty
    - cmd.which
    - cmd.which_bin
host105:
    - cmd.exec_code
    - cmd.exec_code_all
    - cmd.has_exec
    - cmd.powershell
    - cmd.powershell_all
    - cmd.retcode
    - cmd.run
    - cmd.run_all
    - cmd.run_bg
    - cmd.run_chroot
    - cmd.run_stderr
    - cmd.run_stdout
    - cmd.script
    - cmd.script_retcode
    - cmd.shell
    - cmd.shell_info
    - cmd.shells
    - cmd.tty
    - cmd.which
    - cmd.which_bin

 

salt '*' cmd.run 'free -m'  # 命令cmd.run

salt '*' cmd.script /tmp/t.sh  # cmd.script

salt 'host105' cmd.shell 'rm /tmp/lsfz* -rf' # cmd.shell

三、cp模块

[root@host106 ~]# salt '*' sys.list_functions cp
host104:
    - cp.cache_dir
    - cp.cache_file
    - cp.cache_files
    - cp.cache_local_file
    - cp.cache_master
    - cp.get_dir
    - cp.get_file
    - cp.get_file_str
    - cp.get_template
    - cp.get_url
    - cp.hash_file
    - cp.is_cached
    - cp.list_master
    - cp.list_master_dirs
    - cp.list_master_symlinks
    - cp.list_minion
    - cp.list_states
    - cp.push
    - cp.push_dir
    - cp.recv
    - cp.recv_chunked
    - cp.stat_file
host105:
    - cp.cache_dest
    - cp.cache_dir
    - cp.cache_file
    - cp.cache_files
    - cp.cache_local_file
    - cp.cache_master
    - cp.envs
    - cp.get_dir
    - cp.get_file
    - cp.get_file_str
    - cp.get_template
    - cp.get_url
    - cp.hash_file
    - cp.is_cached
    - cp.list_master
    - cp.list_master_dirs
    - cp.list_master_symlinks
    - cp.list_minion
    - cp.list_states
    - cp.push
    - cp.push_dir
    - cp.recv
    - cp.recv_chunked
    - cp.stat_file
View Code

cp.cache_local_file
将master端的/etc/hosts文件复制到minion端的salt cache目录(/var/cache/salt/minion/localfiles/)

[root@host106 ~]# salt '*' cp.cache_local_file /etc/hosts
host104:
    /var/cache/salt/minion/localfiles/etc/hosts
host105:
    /var/cache/salt/minion/localfiles/etc/hosts

cp.get_dir
将master端salt主目录下面的目录复制到minion端的/opt目录下

[root@host106 ~]# ls /srv/salt/
apache.sls  _modules  nginx  top.sls
[root@host106 ~]# salt '*' cp.get_dir salt://nginx/ /opt/
host104:
    - /opt//nginx/files/nginx-1.25.0.tar.gz
    - /opt//nginx/files/nginx.conf
    - /opt//nginx/files/nginx.service
    - /opt//nginx/init.sls
host105:
    - /opt//nginx/files/nginx-1.25.0.tar.gz
    - /opt//nginx/files/nginx.conf
    - /opt//nginx/files/nginx.service
    - /opt//nginx/init.sls
View Code

cp.get_url
下载URL内容到被控主机指定位置(/tmp/index.html)

[root@host106 ~]# salt '*' cp.get_url https://www.cyy123.com /tmp/index.html
host105:
    /tmp/index.html
host104:
    /tmp/index.html

DNS模块

功能:实现被控主机通用DNS操作

添加minion端的hosts域名解析信息

[root@host106 ~]# salt '*' dnsutil.hosts_append /etc/hosts 10.1.1.1 www.baidu.com
host104:
    The following line was added to /etc/hosts:
    10.1.1.1 www.baidu.com
host105:
    The following line was added to /etc/hosts:
    10.1.1.1 www.baidu.com

删除minion端的hosts域名解析信息

[root@host106 ~]# salt '*' dnsutils.hosts_remove /etc/hosts www.baidu.com

 

四、file模块

功能:被控主机常见的文件操作,包括文件读写、权限、查找、校验

首先查看帮助文档,看看支持什么命令

[root@host106 ~]# salt '*' sys.list_functions file
host104:
    - file.access
    - file.append
    - file.apply_template_on_contents
    - file.basename
    - file.blockreplace
    - file.check_file_meta
    - file.check_hash
    - file.check_managed
    - file.check_managed_changes
    - file.check_perms
    - file.chgrp
    - file.chown
    - file.comment
    - file.comment_line
    - file.contains
    - file.contains_glob
    - file.contains_regex
    - file.copy
    - file.delete_backup
    - file.directory_exists
    - file.dirname
    - file.diskusage
    - file.extract_hash
    - file.file_exists
    - file.find
    - file.get_devmm
    - file.get_diff
    - file.get_gid
    - file.get_group
    - file.get_hash
    - file.get_managed
    - file.get_mode
    - file.get_selinux_context
    - file.get_source_sum
    - file.get_sum
    - file.get_uid
    - file.get_user
    - file.gid_to_group
    - file.grep
    - file.group_to_gid
    - file.is_blkdev
    - file.is_chrdev
    - file.is_fifo
    - file.is_link
    - file.join
    - file.lchown
    - file.line
    - file.link
    - file.list_backup
    - file.list_backups
    - file.list_backups_dir
    - file.lstat
    - file.makedirs
    - file.makedirs_perms
    - file.manage_file
    - file.mkdir
    - file.mknod
    - file.mknod_blkdev
    - file.mknod_chrdev
    - file.mknod_fifo
    - file.move
    - file.normpath
    - file.open_files
    - file.pardir
    - file.patch
    - file.path_exists_glob
    - file.prepend
    - file.psed
    - file.read
    - file.readdir
    - file.readlink
    - file.remove
    - file.remove_backup
    - file.rename
    - file.replace
    - file.restore_backup
    - file.restorecon
    - file.rmdir
    - file.search
    - file.sed
    - file.sed_contains
    - file.seek_read
    - file.seek_write
    - file.set_mode
    - file.set_selinux_context
    - file.source_list
    - file.stats
    - file.statvfs
    - file.symlink
    - file.touch
    - file.truncate
    - file.uid_to_user
    - file.uncomment
    - file.user_to_uid
    - file.write
host105:
    - file.access
    - file.append
    - file.apply_template_on_contents
    - file.basename
    - file.blockreplace
    - file.chattr
    - file.check_file_meta
    - file.check_hash
    - file.check_managed
    - file.check_managed_changes
    - file.check_perms
    - file.chgrp
    - file.chown
    - file.comment
    - file.comment_line
    - file.contains
    - file.contains_glob
    - file.contains_regex
    - file.copy
    - file.delete_backup
    - file.directory_exists
    - file.dirname
    - file.diskusage
    - file.extract_hash
    - file.file_exists
    - file.find
    - file.get_devmm
    - file.get_diff
    - file.get_gid
    - file.get_group
    - file.get_hash
    - file.get_managed
    - file.get_mode
    - file.get_selinux_context
    - file.get_source_sum
    - file.get_sum
    - file.get_uid
    - file.get_user
    - file.gid_to_group
    - file.grep
    - file.group_to_gid
    - file.is_blkdev
    - file.is_chrdev
    - file.is_fifo
    - file.is_hardlink
    - file.is_link
    - file.join
    - file.lchown
    - file.line
    - file.link
    - file.list_backup
    - file.list_backups
    - file.list_backups_dir
    - file.lsattr
    - file.lstat
    - file.makedirs
    - file.makedirs_perms
    - file.manage_file
    - file.mkdir
    - file.mknod
    - file.mknod_blkdev
    - file.mknod_chrdev
    - file.mknod_fifo
    - file.move
    - file.normpath
    - file.open_files
    - file.pardir
    - file.patch
    - file.path_exists_glob
    - file.prepend
    - file.psed
    - file.read
    - file.readdir
    - file.readlink
    - file.remove
    - file.remove_backup
    - file.rename
    - file.replace
    - file.restore_backup
    - file.restorecon
    - file.rmdir
    - file.search
    - file.sed
    - file.sed_contains
    - file.seek_read
    - file.seek_write
    - file.set_mode
    - file.set_selinux_context
    - file.source_list
    - file.stats
    - file.statvfs
    - file.symlink
    - file.touch
    - file.truncate
    - file.uid_to_user
    - file.uncomment
    - file.user_to_uid
    - file.write
View Code
file.chown 修改文件权限

[root@host106 ~]# salt '*' file.chown /etc/passwd root root
host104:
None
host105:
None

[root@host106 ~]# salt '*' file.copy /tmp/t.sh /opt/t.sh
host104:
    True
host105:
    True
[root@host106 ~]# salt '*' file.copy /root/test /opt/test recurse=True
host104:
    True
host105:
    True
[root@host106 ~]# salt '*' file.directory_exists /tmp
host104:
    True
host105:
    True
[root@host106 ~]# salt '*' file.stats /etc/passwd
host104:
    ----------
    atime:
        1685606591.579007
    ctime:
        1685520187.770625
    gid:
        0
    group:
        root
    inode:
        3149087
    mode:
        0o644
    mtime:
        1685520187.6146245
    size:
        3007
    target:
        /etc/passwd
    type:
        file
    uid:
        0
    user:
        root
host105:
    ----------
    atime:
        1685675456.4029915
    ctime:
        1685589056.2419565
    gid:
        0
    group:
        root
    inode:
        68500246
    mode:
        0644
    mtime:
        1685589056.1539576
    size:
        1505
    target:
        /etc/passwd
    type:
        file
    uid:
        0
    user:
        root
[root@host106 ~]# salt '*' file.get_mode /etc/passwd
host104:
    0o644
host105:
    0644
[root@host106 ~]# salt '*' file.set_mode /etc/passwd 0644
host104:
    0o644
host105:
    0644
[root@host106 ~]# salt '*' file.mkdir /tmp/test
host104:
    True
host105:
    True
[root@host106 ~]# salt '*' file.sed /opt/t.sh 'ls' 'ls -la'
host104:
    ----------
    pid:
        8754
    retcode:
        0
    stderr:
    stdout:
host105:
    ----------
    pid:
        6309
    retcode:
        0
    stderr:
    stdout:
[root@host106 ~]# salt '*' file.append /tmp/t.sh 'ls /root/test'
host104:
    Wrote 1 lines to "/tmp/t.sh"
host105:
    Wrote 1 lines to "/tmp/t.sh"
[root@host106 ~]# salt '*' file.remove /opt/t.sh
host104:
    True
host105:
    True
[root@host106 ~]# salt '*' file.touch /opt/t.sh
host104:
    True
host105:
    True
[root@host106 ~]# salt '*' file.move /opt/t.sh /opt/t1.sh
host104:
    ----------
    comment:
        '/opt/t.sh' moved to '/opt/t1.sh'
    result:
        True
host105:
    ----------
    comment:
        '/opt/t.sh' moved to '/opt/t1.sh'
    result:
        True
[root@host106 ~]# salt '*' file.rename /opt/t1.sh /opt/t2.sh
host104:
    True
host105:
    True
[root@host106 ~]# salt '*' file.find /root/ type=f name=\*.tar.gz size=+200m
host104:
    - /root/pkg/mysql-8.0.26.tar.gz
host105:
    - /root/soft/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
[root@host106 ~]# salt '*' file.find /root/ mtime=-30d size=+100m print=path.size,mtime 
host104:
    - 1683167746
    - 1683252009
    - 1683507314
    - 1684812540
host105:

 

标签:get,root,cmd,file,常用命令,satlstack,cp,salt
From: https://www.cnblogs.com/mjxi/p/17451292.html

相关文章

  • Linux常用命令-unzip命令详解!
    在Linux系统中命令有很多,可进行磁盘管理、文件管理、文件传输、文档编辑等,而且相同功能的命令也有很多,比如解压缩命令,常用的有:tar、gzip、bzip2、zip、unzip、rar、unrar等,本文为大家详细介绍一下unzip命令,一起来看看吧。Linuxunzip命令用于解压缩zip文件。unzip为.zi......
  • Git常用命令
    Git常用命令本地仓库gitstatus查看文件状态gitadd将文件的修改加入暂存区gitreset将暂存区的文件取消暂存或者是切换到指定版本gitcommit将暂存区的文件修改提交到版本库gitlog查看日志远程仓库gitremote查看远程仓库gitremoteadd添加远......
  • Docker 的安装及常用命令
    CentOSDocker安装参看链接Windows安装DockerDesktop官方下载地址:https://hub.docker.com/editions/community/docker-ce-desktop-windows安装之后,可以打开PowerShell并运行以下命令检测是否运行成功:dockerrunhello-worldMac安装Linux安装使用官方安装脚本自动安......
  • elasticsearch常用命令总结
    目录#查看集群状态curlhttp://*:9200/_cluster/health?pretty#查看所有索引状态curl"http://*:9200/_cat/indices?pretty"#查看异常索引状态curl"http://*:9200/_cat/indices?v&health=red"#查看异常索引分片分配状态curl"http://*:9200/_cat/shards/your_inde......
  • Docker 常用命令简单总结
    1、安装docker1.1、安装docker:sudoapt-getinstall-ydocker.io1.2、启动docker服务:systemctlstartdocker1.3、设置开机启动:systemctlenabledocker1.4、查看docker版本:docker--version1.5、查看Dockercpu/内存占用状态:dockerstats--help1.6、查看Docker状态:systemctlsta......
  • 续集---网络管理常用命令
    网络查看ifconfig :查看与临时配置网络ifdown网卡设备名 :关闭网卡ifup网卡设备名 :启用网卡netstat网络状态查询-t列出TCP协议端口-u列出UDP协议端口-n不适用域名与服务名,而是用ip地址和端口号-l仅列出在监听端口-a所有的连接-r路由表常用的组合: -a......
  • Docker常用命令
    原文:Docker常用命令-DeepInThought-博客园(cnblogs.com) 1、Docker容器信息##查看docker容器版本dockerversion##查看docker容器信息dockerinfo##查看docker容器帮助docker--help 2、镜像操作提示:对于镜像的操作可使用镜像名、镜像长ID和短ID。2.1、镜......
  • git常用命令
    git基本提交命令查看gitconfiguser.name修改gitconfiguser.name"xxx"gitconfiguser.emailgitinit初始化一个新的git仓库,创建.git隐藏文件夹gitpull拉取gitadd.将文件添加到暂存区gitcommit-m"添加描述"gitremoteaddorigin仓库地址关联远程......
  • git常用命令
    #查看变更内容$gitstatus#添加所有$gitadd-A#添加备注$gitcommit-m "XXXX"#代码push$gitpushoriginmaster#查看远程地址$gitremote-v #如果你的提交信息(commitmessage)写错了且这次提交(commit)还没有推(push),你可以通过下面的方法来修改......
  • kubectl常用命令
    通过yaml文件创建podkubectlcreate-fpod.yaml停止podkubectldeletepod<pod-name>查看pod日志kubectllogs<pod-name>实时查看pod日志kubectllogs-f<pod-name>进入pod容器kubectlexec-it<pod-name>--/bin/bash......