easyctl

command module
v0.7.3-alpha Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: MIT Imports: 15 Imported by: 0

README

easyctl

基于golang轻量级运维工具集

** 适用平台:** CentOS7

安装

编译安装最新版
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 |           |

测试

重新连接列表主机

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