搭建 tty.js:一款基于浏览器的终端模拟器
来源:互联网 发布:销售数据分析指标 编辑:程序博客网 时间:2024/06/05 03:41
简介
tty.js,一款基于浏览器的终端模拟器。
官方简介如下:
A terminal in your browser using node.js and socket.io. Based on Fabrice Bellard’s vt100 for jslinux.
环境准备
linux-64 位,线上环境
安装 Node
注:这里安装 0.12.x 版本
下载:https://nodejs.org/dist/v0.12.3/node-v0.12.3-linux-x64.tar.gz
$ cd /home$ wget https://nodejs.org/dist/v0.12.3/node-v0.12.3-linux-x64.tar.gz$ tar -zxvf node-v0.12.3-linux-x64.tar.gz$ cd node-v0.12.3-linux-x64$ ln -s /home/node-v0.12.3-linux-x64/bin/node /usr/local/bin/node # 软连接$ ln -s /home/node-v0.12.3-linux-x64/bin/npm /usr/local/bin/npm # 软连接$ node -vv0.12.3
安装 TTY
1、安装 python
注:这里安装 2.6.x 版本
下载:https://www.python.org/ftp/python/2.6.9/Python-2.6.9.tgz
$ cd /home$ wget https://www.python.org/ftp/python/2.6.9/Python-2.6.9.tgz$ tar -zxf Python-2.6.9.tgz$ cd Python-2.6.9$ ./configure --prefix=/usr/local/python2.6 # 编译$ make && make install # 安装$ ln -s /usr/local/python2.6/bin/python2.6 /usr/bin/python # 软连接$ python -VPython 2.6.9
2、安装 tty.js
$ cd /var/www$ mkdir nodejs$ cd nodejs$ mkdir nodejs-tty$ cd nodejs-tty$ npm install tty.js # 成功了...这背后得有多少坎坷啊
配置和运行 TTY
1、新建 /var/www/nodejs/nodejs-tty/index.js
,内容如下:
var tty = require('tty.js');var conf = tty.config.readConfig() , app = tty.createServer(conf);app.get('/foo', function(req, res, next) { res.send('bar');});app.listen();
2、配置文件 /root/.tty.js/config.json:
{ "users": { "hello": "world" }, "https": { "key": "./server.key", "cert": "./server.crt" }, "port": 3000, // "hostname": "127.0.0.1", "shell": "bash", "shellArgs": ["arg1", "arg2"], "static": "./static", "limitGlobal": 10000, "limitPerUser": 1000, "localOnly": false, "cwd": ".", "syncSession": false, "sessionTimeout": 600000, "log": true, "io": { "log": false }, "debug": false, "term": { "termName": "xterm", "geometry": [80, 24], "scrollback": 1000, "visualBell": false, "popOnBell": false, "cursorBlink": false, "screenKeys": false, "colors": [ "#2e3436", "#cc0000", "#4e9a06", "#c4a000", "#3465a4", "#75507b", "#06989a", "#d3d7cf", "#555753", "#ef2929", "#8ae234", "#fce94f", "#729fcf", "#ad7fa8", "#34e2e2", "#eeeeec" ] }}
3、启动 tty.js
$ node /var/www/nodejs/nodejs-tty/index.js
4、延伸
$ node /var/www/nodejs/nodejs-tty/index.js & # 加&:放到后台运行$ jobs # 查看后台进程[1]+ Running node index.js &
若用jobs无法查看到后台 tty.js 进程,则用端口来查找对应的进程:
$ netstat -anp|grep 3000 # 端口使用情况$ lsof -i :3000 # 查找出占用3000端口的进程$ kill -9 [pid] # 杀死进程
问题汇总
1、线上安装了 Node v5.0.0(当前最新版),在安装tty.js 时,node_modules 里没有独立的 tty.js 模块,这是为什么?
(1)分析
在对比了本地(Node v0.12.3)之后,发现 tty.js 的最新更新时间为4个月前,即有可能 tty.js 只支持 node.js 与 io.js 合并之前的版本;
(2)解决
于是,我就按照自己的本地版本在线上安装了Node v0.12.3。
2、在安装完Python3.5.0之后,运行npm intall tty.js
,出错,提示:
node-gyp编译失败,Python版本必须在大于等于 2.7.0 和小于 3.0.0 之间,并且推荐2.7.0;
于是乎,我就打开了 Python 官网,在首页点击下载了 Python2.7.6 版本。
3、安装完 Python2.7.6 之后,再次执行npm install tty.js
时,总是卡在 node-gyp rebuild 上,并且等了好久都没进展;
参考资料:http://www.bubuko.com/infodetail-827600.html
根据这篇文章所说,我怀疑是下载 node.js 对应版本的源码太慢导致,遂按照作者的说明操作了一遍;
$ wget http://nodejs.org/dist/v0.12.3/node-v0.12.3.tar.gz$ tar -zxf node-v0.12.3.tar.gz -C ~/.node-gyp$ mv ~/.node-gyp/node-v0.12.3 ~/.node-gyp/0.12.3$ printf "9\n">~/.node-gyp/0.12.3/installVersion
4、再次执行npm install tty.js
时,出现configure error
,具体错误如下:
gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1
参考资料:
http://stackoverflow.com/questions/18495907/gyp-filed-with-exit-code-1-when-trying-to-install-zookeeper-on-window-using-n
http://stackoverflow.com/questions/21155922/error-installing-node-gyp-on-ubuntu
大意是说,安装 Python2.6.x 版本可以解决问题,至于为什么,我也没有去深究;
于是,我又马不停蹄的安装了 Python2.6.9 。
5、又是折腾了一番之后,再次执行npm install tty.js
时,提示common.gypi not found
;
参考资料:http://www.xuebuyuan.com/2099911.html
(1)分析
话说这是什么情况?要了解这是什么情况,我们就需要知道gyp是什么东西
,传送门:https://github.com/TooTallNate/node-gyp,这是gyp的仓库地址;瞧瞧README,也许你已经知道了:
node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js;
翻译过来就是: node-gyp 是一个用 node.js 编写的用于编译 node.js 原生的本地模块的跨平台命令行工具。也就是说,如果你安装的模块需要以本地模块的方式加载,那么就必须要经过 gyp 的编译。
回到我们的问题, common.gypi 顾名思义肯定是 gyp 的东西。打开一看,发现它类似于编译前的配置文件(跟 makefile 类似)。所以如果 common.gypi 缺失,当然安装不了了!
(2)原因
但是我们都没动过 gyp ,怎么就会缺失了编译的配置文件呢?有一种可能性非常大的情况就是,你曾经手动取消了某次模块的安装过程,或者某模块的安装过程中发生了意外情况导致编译意外中断;
(3)解决
那怎么解决呢?其实很简单。把~/.node-gyp
文件夹删掉就好了(就是把前面自己手动创建的~/.node-gyp/0.12.3
文件夹删除)!这样 node 会重新执行一次编译过程。如果顺利的话 common.gypi 就会自动生成了。也不会再报common.gypi not found
的错误了。
- 搭建 tty.js:一款基于浏览器的终端模拟器
- 浏览器linux终端交互工具--tty.js
- 使用tty.js 在浏览器上使用终端
- tty.js打通浏览器与Linux的通道
- TTY终端的输入过程
- TTY终端的输入过程
- TTY终端的输入过程
- 一款基于js的幻灯图片代码
- tty 终端
- template.js —一款基于JS的模板引擎
- linux下终端的类型(TTY)
- 终端tty和控制台console的区别
- 控制台,终端,虚拟终端,tty,shell等概念的区别
- 控制台,终端,虚拟终端,tty,shell等概念的区别
- 控制台,终端,虚拟终端,tty,shell等概念的区别
- 终端、虚拟终端、shell、控制台、tty的区别
- 终端、虚拟终端、shell、控制台、tty的区别
- 终端、虚拟终端、shell、控制台、tty的区别
- 内存管理算法--Buddy伙伴算法
- Android休闲游戏-快踩我-开发笔记
- Android Speex编译及使用
- Android MVC、MVP架构
- 2015/12/1 0000004
- 搭建 tty.js:一款基于浏览器的终端模拟器
- Redis的“表”怎么设计的?
- 十二月伊始。
- Protobuf与Json互转
- SpringMVC_post乱码
- Linux内核的信号机制——怪胎
- LeetCode 145 Binary Tree Postorder Traversal
- IGMP Snooping
- 安卓Android控件ListView获取item中EditText值