将ubuntu上android模拟器映射到宿主机端口

351 阅读2分钟

如果waydroid环境如下

A 开发机 10网段
B ubuntu 10网段
C android  192.168.240.112:5555,运行在ubuntu上

希望 A可以通过adb connect android。

先看能否telnet通, telnet 192.168.240.112 5555

安装haproxy:

      sudo apt install haproxy

修改haproxy配置:

      sudo vim haproxy.conf

#全局配置参数
global
    #日志级别
    log         127.0.0.1 local2
     
    #改变当前工作目录
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    nbproc 1
    #最大连接数
    maxconn     8000
    #用户与用户组
    user        haproxy
    group       haproxy
    #设置为后台进程
    daemon
 
    #stats socket /var/lib/haproxy/stats
 
#默认配置,被frontend,backend,listen段继承使用
defaults
    #ha的工作模式
    mode                    tcp
    #启用每个实例日志记录事件和流量
    log                     global
    option                  tcplog
    option                  dontlognull
    #在使用长连接时,为了避免客户端超时没有关闭长连接,此功能可以使服务器端关闭长连接
    #option http-server-close
    #使后端服务器获取客户端的真实IP
    #option forwardfor       except 127.0.0.0/8
    #如果cookie中写入ServerID而客户端不会刷新Cookie,那么当ServerID对应的服务器宕机后,将强制定向到其它健康的服务器上
    #option                  redispatch
    #当对server的connection失败后,重试的次数
    retries                 3
    #在客户端建立连接但不请求数据时,关闭客户端连接
    #timeout http-request    10s
    #等待最大时长
    #timeout queue           1m
    #定义ha将客户端请求转发到后端服务器所等待的超时时长
    timeout connect         30s
    #客户端非活动状态的超时时长
    timeout client          30m
    #客户端与服务器建立连接后,等待服务器端的超时时长
    timeout server          30m
    #定义保持连接的超时时长
    #timeout http-keep-alive 10s
    #健康状态检测时的超时时间,过短会误判,过长资源消耗
    timeout check           30s
    #每个server的最大连接数
    maxconn                 6000
 
frontend  api01
    bind *:25555
    mode tcp
    log global
    default_backend api01pool
 
backend api01pool
    balance  roundrobin
    server  server1 192.168.240.112:5555 check inter 5000 rise 2 fall 3 maxconn 3000

25555 就是想要映射的端口

重启haproxy,开机启动:

         systemctl status haproxy

         systemctl restart haproxy

         systemctl enable haproxy

netstat -anp|grep 25555 看是否成功

0 .0.0.0:25555

需要将ubuntu 的防火墙关掉(或配置规则),否则远程adb无法连接上。