前言:
Linux下的录屏软件不是很多的,但最近在青云云计算官网无意中发现了一个Linux下的录屏神器,非常的nice,只是在分享方面比较弱。
下面将就centos7下如何部署asciinema,以及如何初步使用它做一个简单的介绍。
青云的演示地址:
在 Kubernetes 上最小化安装 KubeSphere
该软件的官方演示地址:
ai script usage examples - asciinema
一,
简介
asciinema
是一个自由开源的用于录制终端会话并将它们分享到网络上的解决方案。
当你在你的终端内运行 asciinema rec
来启动录像时,你输入命令的时候,终端内的所有输出都会被抓取。
当抓取停止时(通过按下 Ctrl-D
或输出 exit
),抓取的输出将会被上传到 asciinema.org 的网站,并为后续的回放做准备。
Asciinema 项目由多个不同的完整的部分组成,比如 asciinema
命令行工具、asciinema.org API 和 JavaScript 播放器。
Asciinema 的灵感来自于 script
和 scriptreplay
命令。
那么,这个软件的优势是实时录制,最重要的是可以与播放内容交互,例如,复制录屏里的文字等等。当然,可以基于此软件做运维审计,并且一些比较复杂的操作可以通过此软件录制后分享给需要的同事,使得各种操作更加的直观,一目了然。细节拉满
如果仔细看了上面的示例,我相信你会对它的特点有一个充分的了解,并且会喜欢上这个软件(魅力无法阻挡啊~~~~~~)。
#####附 ,据我的观察,asciinema这个软件是英国的,因为服务器好像是在英国。
二,
asciinema的安装部署
该软件是基于python运行的,而很不幸,Linux自带的Python2.7并不太符合。
该软件的安装方式非常的多,主流部署方式都支持,例如,yum,apt,brew,docker,pip等等,推荐的部署方式是pip,但我并不是特别推荐该方式,因为pip方式还是比较麻烦的。
本例是使用的centos7,因此,本文将以centos7下的yum部署为主。
yum的方式部署需要epel源和OS源,本文都采用阿里云的yum源来进行安装
1,
epel源
cat > /etc/yum.repos.d/eeel.repo <<EOF
[eoel]
name=epel
baseurl=https://mirrors.aliyun.com/epel-archive/7.7/x86_64/
enable=1
gpgcheck=0
EOF
2,
OS源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
3,
开始安装
可以看到安装了Python-3.6
[root@centos4 yum.repos.d]# yum install asciinema
Loaded plugins: fastestmirror
Repository 'local' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
中间省略了。。。。
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libtirpc-0.2.4-0.16.el7.x86_64 1/6
Installing : python3-setuptools-39.2.0-10.el7.noarch 2/6
Installing : python3-pip-9.0.3-8.el7.noarch 3/6
Installing : python3-3.6.8-19.el7_9.x86_64 4/6
Installing : python3-libs-3.6.8-19.el7_9.x86_64 5/6
Installing : asciinema-1.4.0-2.el7.noarch 6/6
Verifying : libtirpc-0.2.4-0.16.el7.x86_64 1/6
Verifying : asciinema-1.4.0-2.el7.noarch 2/6
Verifying : python3-3.6.8-19.el7_9.x86_64 3/6
Verifying : python3-setuptools-39.2.0-10.el7.noarch 4/6
Verifying : python3-pip-9.0.3-8.el7.noarch 5/6
Verifying : python3-libs-3.6.8-19.el7_9.x86_64 6/6
Installed:
asciinema.noarch 0:1.4.0-2.el7
Dependency Installed:
libtirpc.x86_64 0:0.2.4-0.16.el7 python3.x86_64 0:3.6.8-19.el7_9 python3-libs.x86_64 0:3.6.8-19.el7_9 python3-pip.noarch 0:9.0.3-8.el7 python3-setuptools.noarch 0:39.2.0-10.el7
三,
asciinema的初步使用
该命令的帮助:
[root@centos4 ~]# asciinema
usage: asciinema [-h] [--version] {rec,play,upload,auth} ...
Record and share your terminal sessions, the right way.
positional arguments:
{rec,play,upload,auth}
rec Record terminal session
play Replay terminal session
upload Upload locally saved terminal session to asciinema.org
auth Manage recordings on asciinema.org account
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
example usage:
Record terminal and upload it to asciinema.org:
asciinema rec
Record terminal to local file:
asciinema rec demo.json
Record terminal and upload it to asciinema.org, specifying title:
asciinema rec -t "My git tutorial"
Record terminal to local file, "trimming" longer pauses to max 2.5 sec:
asciinema rec -w 2.5 demo.json
Replay terminal recording from local file:
asciinema play demo.json
Replay terminal recording hosted on asciinema.org:
asciinema play https://asciinema.org/a/difqlgx86ym6emrmd8u62yqu8
For help on a specific command run:
asciinema <command> -h
1,
录制一个片段并保存在本地,文件名称为test.json
########注:在录制的时候不能修改时间,否则JSON文件将不能正常结束,也就是文件损坏了,该文件不能播放,或者转出GIF图片了
[root@centos4 ~]# asciinema rec test.json
~ Asciicast recording started.
~ Hit Ctrl-D or type "exit" to finish.
[root@centos4 ~]# cd /opt/
[root@centos4 opt]# ls
containerd harbor
[root@centos4 opt]# cd
[root@centos4 ~]# ls
123.gif 123.json docker docker-19.03.9.tgz harbor harbor-offline-installer-v1.5.0.tgz kubesphere-images-v3.0.0 kubesphere_kiali_v1.38.tar test.json
[root@centos4 ~]# ls
123.gif 123.json docker docker-19.03.9.tgz harbor harbor-offline-installer-v1.5.0.tgz kubesphere-images-v3.0.0 kubesphere_kiali_v1.38.tar test.json
[root@centos4 ~]# ls
123.gif 123.json docker docker-19.03.9.tgz harbor harbor-offline-installer-v1.5.0.tgz kubesphere-images-v3.0.0 kubesphere_kiali_v1.38.tar test.json
[root@centos4 ~]# rm -rf docker
[root@centos4 ~]# time
real 0m0.000s
user 0m0.000s
sys 0m0.000s
[root@centos4 ~]# date
Wed Jun 28 08:09:45 CST 2023
[root@centos4 ~]# ntpdate ntp.aliyun.com
28 Jun 00:10:18 ntpdate[18369]: step time server 203.107.6.88 offset -28803.509938 sec
[root@centos4 ~]# #OK,录屏结束了!!!,此时是Ctrl+d 退出
[root@centos4 ~]# exit
~ Asciicast recording finished.
2,
将上面录制的名为test.json 的文件转换为GIF格式的图片:
[root@centos4 ~]# docker pull asciinema/asciicast2gif
Using default tag: latest
latest: Pulling from asciinema/asciicast2gif
7b8b6451c85f: Pull complete
ab4d1096d9ba: Pull complete
e6797d1788ac: Pull complete
e25c5c290bde: Pull complete
0d0a810f8aa3: Pull complete
42065bcdfff8: Pull complete
dd637d6e6d34: Pull complete
d67f7d6bcade: Pull complete
dc5855e21089: Pull complete
118eab60d733: Pull complete
837c1093fc9c: Pull complete
274de556230c: Pull complete
c465677e3bd4: Pull complete
91b6be0aaeda: Pull complete
0c13bd3587dc: Pull complete
2af77900a905: Pull complete
Digest: sha256:4ad3f3d913f59178ca69882431c3622cf9b7cd394e4f29e5ab31d4909033bdfc
Status: Downloaded newer image for asciinema/asciicast2gif:latest
docker.io/asciinema/asciicast2gif:latest
[root@centos4 ~]# docker run --rm -v $PWD:/data asciinema/asciicast2gif -s 2 -t solarized-dark test.json test.gif
==> Loading test.json...
==> Spawning PhantomJS renderer...
==> Generating frame screenshots...
==> Combining 32 screenshots into GIF file...
==> Done.
3,
转换成功的GIF图片:
4,
播放JSON格式的录制的文件 test.json
asciinema play test.json
5,
上传录制的文件到官网
[root@centos4 ~]# asciinema upload test.json
View the recording at:
https://asciinema.org/a/593546
打开浏览器,输入https://asciinema.org/a/593546 就可以看到录制的内容了
未完待续!!!!