共计 2420 个字符,预计需要花费 7 分钟才能阅读完成。
导读 | rtop 是一个简单的、无代理的远程服务器监控工具,可通过 SSH 运行。它不需要在远程机器上安装任何代理软件。 |
它的工作原理是建立一个 SSH 会话,并在远程服务器上运行命令来收集系统信息,例如 CPU、磁盘、内存、网络。它每隔几秒钟就会刷新一次信息,就像 top 命令一样。
系统环境
Centos8
安装 golang
检查一下系统是否安装 golang:
[root@server1 ~]# rpm -qa|grep golang
发现没有安装,下面使用 yum list golang
命令查看一下远程仓库里面是否有改安装包:
[ | ]|
Repository AppStream is listed more than once in the configuration | |
Repository extras is listed more than once in the configuration | |
Repository PowerTools is listed more than once in the configuration | |
Repository centosplus is listed more than once in the configuration | |
Available Packages | |
golang.x86_64 1.14.12-1.module_el8.3.0+605+410c5674 AppStream |
发现在 AppStream 源中有 golang 安装包,下面开始安装吧:
[root@server1 ~]# yum -y install golang
为了使用 Go 语言,请在用户主目录下创建一个工作空间。Go 语言会将所有文件保存在这里:
[root@server1 ~]# mkdir -p ~/go_proj/bin
设置 GOPATH 和 GOBIN 环境变量。GOPATH 是项目工作区,将下面两行内容添加到 ~/.bashrc
配置文件中:
[root@server1 ~]# vim ~/.bashrc | |
export GOPATH=$HOME/go_proj | |
export GOBIN=$GOPATH/bin |
安装 rtop
运行 go get
命令来构建 rtop。rtop 二进制文件自动保存在 $GOPATH/bin
下。运行 go get 之前,确保系统安装了 git
工具:
[root@server1 ~]# yum -y install git | |
[root@server1 ~]# go get github.com/rapidloop/rtop | |
package git:/github.com/rapidloop/rtop: git:/github.com/rapidloop/rtop: invalid import path: malformed import path "git:/github.com/rapidloop/rtop": invalid char ':' | |
[root@server1 ~]# go get github.com/rapidloop/rtop | |
package golang.org/x/crypto/ssh: unrecognized import path "golang.org/x/crypto/ssh": https fetch: Get "https://golang.org/x/crypto/ssh?go-get=1": dial tcp 216.239.37.1:443: connect: connection refused | |
package golang.org/x/crypto/ssh/agent: unrecognized import path "golang.org/x/crypto/ssh/agent": https fetch: Get "https://golang.org/x/crypto/ssh/agent?go-get=1": dial tcp 216.239.37.1:443: connect: connection refused | |
package golang.org/x/crypto/ssh/terminal: unrecognized import path "golang.org/x/crypto/ssh/terminal": https fetch: Get "https://golang.org/x/crypto/ssh/terminal?go-get=1": dial tcp 216.239.37.1:443: connect: connection refused |
运行 go get 之后,发现不能下载依赖包。
按照下面操作,创建目录,并手动 git 下载相关依赖:
[ | ]|
[ | ]|
[ | ]|
[ | ]
下面再次运行 go get
就可以了:
[root@server1 x]# go get github.com/rapidloop/rtop
下面可以看到 rtop
可以正常运行了。
如何使用 rtop
rtop 二进制文件存在于 $GOPATH/bin 中,因此只需运行 $GOBIN/rtop
就可以。只需添加远程主机信息,然后使用 rtop 命令进行监控。刷新间隔默认为 5 秒钟。
[root@server1 ~]# $GOBIN/rtop root@192.168.43.131
手动设置刷新间隔以更好地监控。这里设置了 2 秒刷新间隔。
[root@server1 ~]# $GOBIN/rtop root@192.168.43.131 2
总结
]rtop 是一个简单的、无代理的远程服务器监控工具,可通过 SSH 运行。它不需要在远程机器上安装任何代理软件。
正文完
星哥玩云-微信公众号
