# deploy-tools **Repository Path**: rancher_cn/deploy-tools ## Basic Information - **Project Name**: deploy-tools - **Description**: golang编写的跨平台的SSH工具 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2024-11-24 - **Last Updated**: 2025-04-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # golang实现的SSH工具 ## 开发计划 [ ] 配置文件搜索路径优化,先本地config.local.yaml,config.yaml(已实现),如没有,则取 ~/.deploy/config.yaml (未实现) ## 主要功能 - 执行命令 - 复制文件 ## 配置文件 配置文件定义了主机信息和任务信息,默认为当前路径下的config.local.yaml 或者config.yaml,config.local.yaml优先级更高。
-c 可指定配置文件 ```yaml version: 0.1 ## 加密秘钥,重要信息加密,当前只支持主机密码 ## 加密方式写法 ENC(xxx) ## 获取加密后的密文信息 ./deploy-tools --encrypt 123 --key 123456 ## --key非必须,默认去本地配置文件的配置值 ## 非必填,可用动态参数注入 encrypt_key: '' # 当前主机的IP localhost: 127.0.0.1 # 全局配置 ssh_port: 22 ssh_user: root ssh_password: 123456 ssh_sudo: true # 主机信息 hosts: - name: master1 host: 192.168.0.2 port: 22 user: root password: 123456 # 主机连接超时时长,秒,默认20 timeout: 10 - name: master2 host: 192.168.0.3 - name: master3 host: 192.168.0.4 # 任务信息 jobs: - name: job1 timeout: 30 parallel: true hosts: - master1 tasks: - name: ls command: ls -l timeout: 5 allow_fail: true - name: send file src: ./README.md dst: test/ - name: fetch file src: test/README.md dst: ./ fetch: true ``` ## 使用方法 ### 参数说明 - -c : 指定配置文件路径 - -h : 指定主机名称(配置文件内定义) - --fetch: 文件拉取模式,默认为发送,即复制到远程 - --cmd: 指定命令内容 - --jobs: 指定编排任务,默认为false,当未指定--cmd时默认为true - --job: 执行执行的任务名称 - --encrypt: 指定要加密的文本 - --key: 指定加密秘钥 - jobfile: 指定任务编排文件 ### 加密文本 ```shell ./deploy-tools --decrypt 123456 --key 123456 ``` ### 执行远程命令 ```shell ## -c 指定配置文件,默认为config.local.yaml,config.yaml ## windows下deploy-tools替换成deploy-tools.exe ./deploy-tools -h master1 -cmd "cd ~/ && ls -l" ``` ### 发送文件 ```shell # 传输单个文件 ## --dst 参数写法会影响远程服务器上文件位置,以/结尾,则表示将当前文件,复制到远程文件夹内,否则,则表示复制到指定的文件 ./deploy-tools -h master1 --src README.md --dst test # 传输文件夹,--dst必须以/结尾 ./deploy-tools -h master1 --src build/ --dst tools/ ``` ### 从远程服务器拉取文件 ```shell # 传输单个文件 ./deploy-tools -h master1 --src README.md --dst test --fetch # 传输文件夹 ./deploy-tools -h master1 --src build/ --dst tools/ --fetch ``` ## 打包 ```shell ## windows,默认就是,但是要注意 set GOOS=windows set GOARCH=amd64 go build -o ./build/deploy-tools.exe ## linux set GOOS=linux set GOARCH=amd64 set CGO_ENABLED=0 go build -o ./build/deploy-tools ```