easyctl

command module
v0.7.4-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2021 License: MIT Imports: 16 Imported by: 0

README

easyctl

基于golang轻量级运维工具集

** 适用平台:** CentOS7

迭代计划

里程碑

  • v0.x.y-alpha: 添加常用指令集功能(x为一级指令集,如set;y为二级指令集,如set指令集中的dns子指令集)
  • v1.0.0-beta: bug修复、文档站点、集成github workflow
  • v1.0.0-release: 正式版本

v1已实现功能

  • deny
    • 防火墙
    • ping
    • selinux
  • set
    • 时区
    • dns
    • 主机互信
    • 主机host解析
    • 文件描述符数
    • 修改root口令

v2功能预览

  • windows GUI

安装

编译安装最新版
git clone https://github.com/weiliang-ms/easyctl.git
cd easyctl
go build -ldflags "-w -s" -o /usr/local/bin/easyctl

set指令集

配置主机间host解析

采集将多主机间的hostnameIP解析,过滤hostnamelocalhost的条例,配置到/etc/hosts

生成默认配置文件

easyctl set host-resolv

修改配置文件

config.yaml

server:
  - host: 10.10.1.[1:3]
    username: root
    password: 111111
    port: 22
excludes:
  - 192.168.235.132

配置host解析

--debug输出debug日志,可选参数

easyctl set host-resolv -c config.yaml --debug

查看解析

[root@scq-dc01 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

# easyctl hosts BEGIN
10.10.1.1 scq-dc01
10.10.1.2 scq-dc02
10.10.1.3 scq-dc03
# easyctl hosts END
配置主机间免密登录

多主机间配置免密ssh登录(基于密钥登录)

生成默认配置文件

easyctl set password-less

修改配置文件

config.yaml

server:
  - host: 10.10.1.[1:3]
    username: root
    password: 111111
    port: 22
excludes:
  - 192.168.235.132

配置免密登录

--debug输出debug日志,可选参数

easyctl set password-less -c config.yaml --debug

测试

10.10.1.2为主机列表内的主机

ssh 10.10.1.2
配置主机文件描述符

多主机配置文件描述符数量(65535)

生成默认配置文件

easyctl set ulimit

修改配置文件

config.yaml

server:
  - host: 10.10.1.[1:3]
    username: root
    password: 111111
    port: 22
excludes:
  - 192.168.235.132

配置免密登录

--debug输出debug日志,可选参数

easyctl set ulimit -c config.yaml --debug
配置主机时区

多主机配置时区(上海时区)

生成默认配置文件

easyctl set tz

修改配置文件

config.yaml

server:
  - host: 10.10.1.[1:3]
    username: root
    password: 111111
    port: 22
excludes:
  - 192.168.235.132

配置免密登录

--debug输出debug日志,可选参数

easyctl set tz -c config.yaml --debug

测试

date
修改主机root口令

生成默认配置文件

easyctl set new-password

修改配置文件

config.yaml

  • 调整主机信息,新root口令的值
server:
  - host: 10.10.10.[1:40]
    username: root
    password: 123456
    port: 22
excludes:
  - 192.168.235.132
newRootPassword: "3LEPnok84HxYc5"

运行

--debug输出debug日志,可选参数

easyctl set new-password -c config.yaml --debug

成功样例

[root@localhost ~]# ./easyctl set new-password -c config.yaml
I0926 15:14:56.431946  112411 log.go:184] 检测到配置文件中含有IP段,开始解析组装...
I0926 15:14:56.431999  112411 parse.go:113] 解析到IP子网网段为:10.10.1....
I0926 15:14:56.432021  112411 parse.go:117] 解析到IP区间为:1:2...
I0926 15:14:56.432026  112411 parse.go:121] 解析到起始IP为:10.10.1.1...
I0926 15:14:56.432031  112411 parse.go:125] 解析到末尾IP为:10.10.1.2...
I0926 15:14:56.432037  112411 exec.go:43] 开始并行执行命令...
I0926 15:14:56.432084  112411 exec.go:105] [10.10.1.2] 开始执行指令 ->
I0926 15:14:56.432114  112411 exec.go:105] [10.10.1.1] 开始执行指令 ->
I0926 15:14:56.634224  112411 log.go:184] <- 10.10.1.1执行命令成功...
I0926 15:14:56.634472  112411 log.go:184] <- 10.10.1.2执行命令成功...
| IP ADDRESS  |  CMD   | EXIT CODE | RESULT  |        OUTPUT        | EXCEPTION |
|-------------|--------|-----------|---------|----------------------|-----------|
| 10.10.1.1 | ****** |     0     | success | Changing password fo |           |
| 10.10.1.2 | ****** |     0     | success | Changing password fo |           |

测试

重新连接列表主机

多主机配置dns

生成默认配置文件

easyctl set dns

修改配置文件

config.yaml

  • 调整主机信息
  • 调整dns地址列表
server:
  - host: 10.10.10.[1:40]
    username: root
    privateKeyPath: "" # ~/.ssh/id_rsa,为空默认走password登录;不为空默认走密钥登录
    password: 123456
    port: 22
excludes:
  - 192.168.235.132
dns:
  - 114.114.114.114
  - 8.8.8.8

运行

--debug输出debug日志,可选参数

easyctl set dns -c config.yaml --debug

测试

任意主机列表内的主机执行:

cat /etc/hosts

deny指令集

配置主机禁Ping

配置主机禁Ping

生成默认配置文件

easyctl deny ping

修改配置文件

config.yaml

server:
  - host: 10.10.1.[1:3]
    username: root
    password: 111111
    port: 22
excludes:
  - 192.168.235.132

配置

--debug输出debug日志,可选参数

easyctl deny ping -c config.yaml --debug
配置主机禁用selinux

生成默认配置文件

easyctl deny selinux

修改配置文件

config.yaml

server:
  - host: 10.10.1.[1:3]
    username: root
    password: 111111
    port: 22
excludes:
  - 192.168.235.132

配置

--debug输出debug日志,可选参数

easyctl deny selinux -c config.yaml --debug
配置主机禁用防火墙

生成默认配置文件

easyctl deny firewall

修改配置文件

config.yaml

server:
  - host: 10.10.1.[1:3]
    username: root
    password: 111111
    port: 22
excludes:
  - 192.168.235.132

配置

--debug输出debug日志,可选参数

easyctl deny firewall -c config.yaml --debug

export指令集

chart导出

harbor中批量下载chart文件

背景说明

通常chart应用存放于harbor进行管理,但harbor(v2.1.4)只支持单个chart文件下载。

对于离线批量分发场景,比较难受,特开发该功能。

生成默认配置文件

[root@localhost ~]# easyctl export chart
I0927 09:30:47.685246   14817 export.go:44] 检测到配置文件参数为空,生成配置文件样例 -> config.yaml

修改配置文件

vi config.yaml

helm-repo:
  endpoint: 10.10.1.3:80   # harbor访问地址
  domain: harbor.wl.io      # harbor域
  username: admin           # harbor用户
  password: 123456          # harbor密码
  preserveDir: /root/charts # chart包持久化目录
  package: true             # 是否打成tar包
  repo-name: charts         # chart repo harbor内的名称

配置

--debug输出debug日志,可选参数

[root@node1 ~]# easyctl export chart -c config.yaml
INFO[0000] 解析chart仓库配置...
INFO[0000] 待导出chart数量为: 135
INFO[0000] 导出chart...
INFO[0000] 创建目录: /root/charts
INFO[0000] 逐一导出chart中...
INFO[0002] 导出完毕,chart总数为:135

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
add
set
pkg
add
log
set
ssh
util/ssh
/* Copyright 2020 The KubeSphere Authors.
/* Copyright 2020 The KubeSphere Authors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL