Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【建议】多个地址代理和增加config文件 #12

Open
swRains opened this issue Jan 28, 2023 · 8 comments
Open

【建议】多个地址代理和增加config文件 #12

swRains opened this issue Jan 28, 2023 · 8 comments

Comments

@swRains
Copy link

swRains commented Jan 28, 2023

如果可以同时添加多个代理,通过读取config文件来管理是不是会更好,比如tcp2ws -config.cfg
config文件里就一行一个代理,或者说定义一些.crt和.key文件的路径,我想这样会不会更好。每次重启都打这一长串........

@zanjie1999
Copy link
Owner

zanjie1999 commented Jan 28, 2023

#2
你可以把启动命令写一个sh,加到开机启动(crontab里用@reboot 开头),配置文件有想过,但目前是一个线程管一个转发,也没几个参数,为他增加一个配置文件实在是有点多余

至于一个线程多个转发?因为设计的时候就是设计成单端口多线程tcp连接转发,因为之前用py写了个只支持单线程的用来代替深信服的ssh工具转发ssh的,这个程序写出来最初也是为了解决这个问题,
如果要实现这个需求,改动还蛮大的,懒得动(由于客户端和服务端共用方法,服务端多端口同时转发和不同path转发不同端口同理)

@zanjie1999
Copy link
Owner

还是开起来吧,欢迎pr,有空的话我就写一下
另外想到了可以用bash或者service来实现这个需求

@zanjie1999 zanjie1999 reopened this Jan 28, 2023
@swRains
Copy link
Author

swRains commented Jan 29, 2023

windows的bat我已经写了,linux的bash还得学习下,还是用的太少了

@zanjie1999
Copy link
Owner

举个例子

nohup tcp2ws路径 你的启动参数 > 日志文件 &

一行一个写到一个sh文件中,然后chmod +x 文件名,这样就能运行了

nohup tcp2ws 22 62222 > server.log &
nohup tcp2ws ws://127.0.0.1:62222 6222 > client. log &

停止

killall tcp2ws

@swRains
Copy link
Author

swRains commented Jan 29, 2023

谢谢,这几天我研究学习下,有几台虚拟机要藏一下ssh端口-.-

@HanadaLee
Copy link

我觉得这个需求挺好的,我现在就是用systemd或者docker拉起一个config.conf文件,这个文件本质上是一个shell文件,

#!/bin/bash

# client - xxxxx1
/usr/local/tcp2ws/bin/tcp2ws xxx xxxxx &
# client - xxxxx2
/usr/local/tcp2ws/bin/tcp2ws xxxx xxxx &
# Keep Script Running (if you use systemd to run this script, please remove it)
wait

tcp2ws.service

[Unit]
Description=TCP to WebSocket Proxy
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/tcp2ws/etc/config.conf
ExecStop=/usr/local/tcp2ws/bin/tcp2ws
Restart=on-failure
StartLimitBurst=0

[Install]
WantedBy=multi-user.target

docker-compose.yml

version: "3"

services:
  tcp2ws:
    image: registry.internal.com/hanada/tcp2ws:11.1
    container_name: tcp2ws
    network_mode: host
    entrypoint: ["/bin/bash", "/usr/local/tcp2ws/etc/config.conf"] 
    restart: unless-stopped
    volumes:
      - ./etc/config.conf:/usr/local/tcp2ws/etc/config.conf

虽然但是,实现起来还是好奇怪,感觉像是奇技淫巧
我是建议如果不想搞多线程逻辑,其实可以一个master,自身不跑服务,只载入或更新配置文件,带多个worker进程,每个worker进程跑一个tcp2ws配置实例

@zanjie1999
Copy link
Owner

我觉得这个需求挺好的,我现在就是用systemd或者docker拉起一个config.conf文件,这个文件本质上是一个shell文件,

#!/bin/bash

# client - xxxxx1
/usr/local/tcp2ws/bin/tcp2ws xxx xxxxx &
# client - xxxxx2
/usr/local/tcp2ws/bin/tcp2ws xxxx xxxx &
# Keep Script Running (if you use systemd to run this script, please remove it)
wait

tcp2ws.service

[Unit]
Description=TCP to WebSocket Proxy
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/tcp2ws/etc/config.conf
ExecStop=/usr/local/tcp2ws/bin/tcp2ws
Restart=on-failure
StartLimitBurst=0

[Install]
WantedBy=multi-user.target

docker-compose.yml

version: "3"

services:
  tcp2ws:
    image: registry.internal.com/hanada/tcp2ws:11.1
    container_name: tcp2ws
    network_mode: host
    entrypoint: ["/bin/bash", "/usr/local/tcp2ws/etc/config.conf"] 
    restart: unless-stopped
    volumes:
      - ./etc/config.conf:/usr/local/tcp2ws/etc/config.conf

虽然但是,实现起来还是好奇怪,感觉像是奇技淫巧 我是建议如果不想搞多线程逻辑,其实可以一个master,自身不跑服务,只载入或更新配置文件,带多个worker进程,每个worker进程跑一个tcp2ws配置实例

整挺好,当初也没有对多端口进行转发的需求,也没有预留,想的让他简单易用把ssh转出来,并且比之前Python3写的端口转发器支持同时转发多个连接,如果要改成支持多连接其实还挺麻烦的(因为很多东西都是手搓的),外面套一层用于管理指定端口转发启停到容易的多

@HanadaLee
Copy link

HanadaLee commented Oct 13, 2023

所以如果要简单化处理就是一个worker进程处理一个转发实例,master只负责守护各worker进程,甚至可以考虑实现reload或者动态加载配置文件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants