rtty:反向代理WebTTY ,Linux遠程維護調(diào)試工具
rtty 是一個反向代理 WebTTY。它由客戶端和服務(wù)端組成。服務(wù)端采用 Go 語言實現(xiàn), 以及使用了 vue + iview。你可以基于你設(shè)置的設(shè)備 ID(不設(shè)置則為設(shè)備的 MAC 地址)通過 Web 瀏覽器訪問你的任意一臺終端。
rtty 非常適合遠程維護你的或者你公司的部署在全球各地的成千上萬的 Linux 設(shè)備。
特性
- 部署簡單,使用方便
- 反向代理
- 根據(jù)你設(shè)置的 ID 連接你的設(shè)備
- 基于 Xterm.js 的全功能終端
- 支持 SSL: openssl、mbedtls、 CyaSSl(wolfssl)
- 支持上傳文件到設(shè)備
- 支持從設(shè)備下載文件
- 支持遠程執(zhí)行命令
- 跨平臺: macOS、Linux、FreeBSD/OpenBSD、OpenWrt/LEDE
客戶端依賴
- libubox - 用于 OpenWrt 的 C 工具函數(shù)庫,但也可以用于其他 Linux 系統(tǒng)中。(參考)
- libuwsc - 一個輕量的針對嵌入式 Linux 的基于 libubox 的 WebSocket 客戶端 C 庫。
- ustream-ssl - 如果你需要支持 SSL
- mbedtls - 如果你選擇 mbedtls 作為你的 SSL 后端
- CyaSSl(wolfssl) - 如果你選擇 wolfssl 作為你的 SSL 后端
- openssl - 如果你選擇 openssl 作為你的 SSL 后端
部署服務(wù)端
安裝
curl https://raw.githubusercontent.com/zhaojh329/rttys/master/install.sh | sudo sh
手動運行
rttys -cert /etc/rttys/rttys.crt -key /etc/rttys/rttys.key
后臺運行
sudo /etc/init.d/rttys start
如何編譯和安裝 rtty 客戶端
針對 Linux 發(fā)行版,例如 Ubuntu 和 CentOS
安裝編譯工具:
sudo apt install gcc cmake git # For Ubuntu
yum install gcc cmake git # For Centos
編譯和安裝依賴軟件包:
sudo apt install libjson-c-dev # For Ubuntu
sudo apt install json-c-devel # For Centos
git clone https://git.openwrt.org/project/libubox.git
cd libubox && cmake -DBUILD_LUA=OFF . && sudo make install
git clone https://github.com/zhaojh329/libuwsc.git
cd libuwsc && cmake -DUWSC_SSL_SUPPORT=OFF . && sudo make install
編譯和安裝 rtty:
git clone https://github.com/zhaojh329/rtty.git
cd rtty && cmake . && sudo make install
運行 rtty
,將下面的參數(shù)替換為你自己的參數(shù):
sudo rtty -I 'My-device-ID' -h 'your-server' -p 5912 -a -v -s -d 'My Device Description'
查詢在線設(shè)備列表:
curl -k https://your-server:5912/devs
[{"id":"My-device-ID","description":"My device"}]
嵌入式Linux平臺
你需要自行交叉編譯。
如何在 OpenWRT 中使用
安裝:
opkg update
opkg list | grep rtty
opkg install rtty-nossl
如果安裝失敗,你可以自己編譯。
配置服務(wù)器參數(shù):
uci add rtty rtty # If it's the first configuration
uci set rtty.@rtty[0].host='your server host'
uci set rtty.@rtty[0].port='your server port'
你可以給你的設(shè)備自定義一個 ID。如果未指定,rtty 將使用指定的網(wǎng)絡(luò)接口的 MAC 地址作為其 ID, 以 MAC 地址作為 ID 的格式為:1A2A3A4A5A6A
。
uci set rtty.@rtty[0].id='your-device-id'
使用 SSL:
uci set rtty.@rtty[0].ssl='1'
保存配置并應(yīng)用:
uci commit
/etc/init.d/rtty restart
如何使用
使用你的 Web 瀏覽器訪問你的服務(wù)器: https://your-server-host:5912
,然后點擊連接按鈕。
你可以非常方便的將 rtty 嵌入到你現(xiàn)有的平臺: https://your-server-host:5912?id=your-id
。
自動登錄: https://your-server:5912/?id=device-id&username=device-username&password=device-password
。
上傳文件和下載文件
使用快捷鍵打開菜單: Ctrl+Shift+f
。
遠程執(zhí)行命令
curl -k https://your-server:5912/cmd -d '{"devid":"test","username":"test","password":"123456","cmd":"ls","params":["/"],"env":[]}'
{"Err":0,"msg":"","code":0,"stdout":"bin\ndev\netc\nlib\nmnt\noverlay\nproc\nrom\nroot\nsbin\nsys\ntmp\nusr\nvar\nwww\n","stderr":""}
貢獻代碼
如果你想幫助 rtty 變得更好,請參考 CONTRIBUTING_ZH.md。