Android Termux+QEMU+Alpine+docker
安装Termux
https://f-droid.org/zh_Hans/packages/com.termux/
开始
#下载系统镜像
wget http://dl-cdn.alpinelinux.org/alpine/v3.10/releases/x86_64/alpine-virt-3.10.1-x86_64.iso
#安装QEMU X86_64 环境及依赖
pkg install x11-repo unstable-repo
pkg install qemu-utils qemu-system-x86_64
#创建虚拟镜像(硬盘) 5g为镜像大小,可修改,最少需要2g
qemu-img create -f qcow2 virt-alpine.img 5g
#使用镜像启动虚拟机
qemu-system-x86_64 -hda virt-alpine.img -cdrom alpine-virt-3.10.1-x86_64.iso -boot d -m 512 -nographic
参数解释:
-hda
: 启动的虚拟硬盘-cdrom
: 启动的光盘镜像文件(相当于用光盘安装windows)-boot
: 启动槽位-m
: 内存大小,单位mb-nographic
: 无图像模式,直接在控制台输出--vnc :1
: 以vnc为图像模式输出到”显示器”,并占用vnc 1端口
安装Alpine到虚拟磁盘
使用root账户登录
配置网络
vi /etc/network/interfaces
按“i”进入输入模式,添加以下内容,按“esc”退出输入模式,输入“:wq”保存
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
保存后重启网络:
/etc/init.d/networking restart
安装:
setup-alpine
详细配置:
Select keyboard layout: cn
(选择CN键盘布局)Select variant
(cn)Enter system hostname: stageguard
(输入hostname名称,随意)Which one do you want to initialize? (or '?' or 'done') [eth0]
Ip address for eth0? (or 'dhcp', 'none', '?') [10.0.2.15] dhcp
(选dhcp)Changing password for root
(修改root用户密码)Which timezone are you in? ('?' for list) [UTC] Asia/Shanghai
(时区填Asia/Shanghai)HTTP/FTP proxy URL? (e.g. 'http://proxy:8080', or 'none') [none]
(代理地址,默认none)Enter mirror number (1-47) or URL to add (or r/f/e/done) [f]: 21
(选择软件源,21(清华源))Which SSH server? ('openssh', 'dropbear' or 'none') [openssh]
(SSH服务器,选择openssh(默认))Which disk(s) would you like to use? (or '?' for help or 'none') [none]sda
(安装在何处,选sda)How would you like to use it? ('sys', 'data', 'lvm' or '?' for help) [?] sys
(安装方式,选sys)WARNING: Erase the above disk(s) and continue? [y/N]: y
(清除整个硬盘,y(是))
安装完成后关机
poweroff
启动alpine 安装docker
qemu-system-x86_64 -hda virt-alpine.img -boot c -m 2048 -netdev user,id=nde1,hostfwd=tcp::2222-:22,
hostfwd=tcp::8686-:8888 -device e1000,netdev=nde1,id=d-net1 -nographic
参数解释:
-hda
: 启动的虚拟硬盘-boot
: 启动槽位-m
: 内存大小,单位mb-netdev
: 网络配置,详情请看QEMU_Wiki:Documentation/Networking-device
: 设备配置(当前指向网络设备)-nographic
: 无图像模式,直接在控制台输出--vnc :1
: 以vnc为图像模式输出到”显示器”,并占用vnc 1端口hostfwd=[tcp|udp]:hostport-:guestport
将进入到主机端口的TCP或者UDP连接转发到客户机的端口
配置sshd
vi /etc/ssh/sshd_config
#取消注释PermitRootLogin并修改为yes
rc-service sshd restart
添加社区源
vi /etc/apk/repositories
取消注释comminuty源
安装docker
apk update
apk add docker
#使docker开机启动
rc-update add docker
#开启docker服务
service docker start
#后台启动
setsid containerd
setsid dockerd
测试
docker info
内网穿透
钉钉pierced
- 下载工具
git clone https://github.com/open-dingtalk/pierced.git
- 执行命令
./ding -config=./ding.cfg -subdomain=域名前缀 本地端口
。
apk add git
git clone https://github.com/open-dingtalk/pierced.git
#安装glibc
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk
apk add glibc-2.29-r0.apk
cd pierced/linux
chmod +x ./ding
./ding -config=./ding.cfg -subdomain=aaa111 8080
可能的问题
screen 提示 Cannot find terminfo entry for 'xxx'
#获取支持的终端类型
ls /usr/share/terminfo/x
#等号后面修改为上个命令显示的内容
export TERM=
本文内容绝大部分来自 StageGuard ,进行少量修改
参考:
https://github.com/mzlogin/ding-tunnel/blob/master/README.md