XrayR-project / XrayR

A Xray backend framework that can easily support many panels. 一个基于Xray的后端框架,支持V2ay,Trojan,Shadowsocks协议,极易扩展,支持多面板对接
https://xrayr-project.github.io/XrayR-doc/
Mozilla Public License 2.0
2.12k stars 842 forks source link

[GlobalDeviceLimitConfig] RedisDB settings do not work well[v0.8.6] #127

Closed yuanweize closed 1 year ago

yuanweize commented 1 year ago

My two nodes config are set to different redisDB numbers, but when I check redis, they are actually stored in DB number 1

config.yml

image

redis-cli

image

'141' is my test account and it should appear in redisDB 0

If we need more log information, please reply to me. Thank you

yuanweize commented 1 year ago

@thank243

After testing the GlobalDeviceLimitConfig redis configuration of the last node will overwrites the redis configuration of the previous nodes.
[test twice] First set db num: 3,4 Second set db num: 7,6 But 3,7 in both show me (empty array), only 4,6 work and have full data, and both nodes have their data in one redisDB, but two different redisDB i already setup in config.yml]

image
Septrum101 commented 1 year ago

pull the latest version on docker and test. The version should be 0.8.7

yuanweize commented 1 year ago

pull the latest version on docker and test. The version should be 0.8.7

I deployed 0.8.7 by docker and stop local XrayR, mapping /etc/XrayR:/etc/XrayR. I try set db number 3,4 for two nodes (each for a panel) after I run Speedtest and wait for a while, the redid db 3,4 haven't any data. It's seems never stored any records

Septrum101 commented 1 year ago

The limiter is a global instance. Thus, the global limit will be a global instance, you shouldn't configure it for every node on next version.

yuanweize commented 1 year ago

The limiter is a global instance. Thus, the global limit will be a global instance, you shouldn't configure it for every node on next version.

The limiter should not be a global instance, XrayR is also designed to meet the case of multiple nodes, different nodes can be set to different panel API, if this is global instance that need multiple systemctl service for multiple panel. Maybe fix it in v0.8.7? I can test it and if have any new updates, please let me know.

Septrum101 commented 1 year ago

The limiter is a global instance. Thus, the global limit will be a global instance, you shouldn't configure it for every node on next version.

The limiter should not be a global instance, XrayR is also designed to meet the case of multiple nodes, different nodes can be set to different panel API, if this is global instance that need multiple systemctl service for multiple panel. Maybe fix it in v0.8.7? I can test it and if have any new updates, please let me know.

The limiter instance is a global instance from beginning. Xrayr use different tag to distinguish different nodes. We will discuss whether the limiter will be in different node.

XrayR exactly have this bug. If you hot reload the config.yml on change device limit, it will not effect right now.

yuanweize commented 1 year ago

This is my current configuration, which is wrong according to your logic.

Nodes:
- PanelType: V2board
  ApiConfig:
    ApiHost: https://hk #panel 0
    ApiKey: hk
    NodeID: 19
    NodeType: Trojan
  ControllerConfig:
    GlobalDeviceLimitConfig:
        Limit: 1 # 
        RedisAddr: redis.com:6367 # The redis server address
        RedisPassword: # Redis password
        RedisDB: 0 # Redis DB 0 for panel 0
        Timeout: 5 # Timeout for redis request
        Expiry: 60 # Expiry time (second)
    ListenIP: 127.0.0.1

- PanelType: V2board
  ApiConfig:
    ApiHost: https://eu #panel 1
    ApiKey: eu
    NodeID: 19
    NodeType: Trojan
  ControllerConfig:
    GlobalDeviceLimitConfig:
        Limit: 1 # 
        RedisAddr: redis.com:6367 # The redis server address
        RedisPassword: # Redis password
        RedisDB: 1 # Redis DB 1
        Timeout: 5 # Timeout for redis request
        Expiry: 60 # Expiry time (second)
    ListenIP: 127.0.0.1

According to what you said and the documentation example, if this is set up, how to distinguish the redisDB num of different nodes?

Nodes:
- PanelType: V2board
  ApiConfig:
    ApiHost: https://hk #panel 1
    ApiKey: hk
    NodeID: 19
    NodeType: Trojan
  ControllerConfig:
    GlobalDeviceLimitConfig:
        Limit: 1 # 
        RedisAddr: redis.com:6367 # The redis server address
        RedisPassword: # Redis password
        RedisDB: 0 # Redis DB
        Timeout: 5 # Timeout for redis request
        Expiry: 60 # Expiry time (second)
    ListenIP: 127.0.0.1

- PanelType: V2board
  ApiConfig:
    ApiHost: https://eu #panel 2
    ApiKey: eu
    NodeID: 19
    NodeType: Trojan
  ControllerConfig:
    ListenIP: 127.0.0.1
Septrum101 commented 1 year ago

You can test the globalLimt branch now. I just refact this feat and config format.

yuanweize commented 1 year ago

You can test the globalLimt branch now. I just refact this feat and config format.

May I ask how to compile this branch into github packages ?

Septrum101 commented 1 year ago

clone this branch and go build it

yuanweize commented 1 year ago

clone this branch and go build it

Ok, Can you help me modify my configuration? If I want to use a different redisDB for each node

Septrum101 commented 1 year ago

clone this branch and go build it

Ok, Can you help me modify my configuration? If I want to use a different redisDB for each node

If all the nodes on the same server, you should run multi instance. reference the globalLimit branch's config example.

yuanweize commented 1 year ago

So in the future if 2 panels need to run 2 XrayR instance[for example via systemctl service such as XrayR1.service, XrayR2.service ]?

yuanweize commented 1 year ago

clone this branch and go build it

Ok, Can you help me modify my configuration? If I want to use a different redisDB for each node

If all the nodes on the same server, you should run multi instance. reference the globalLimit branch's config example.

As u said XrayR tag to distinguish different nodes, How does limter work on different tags?

Maybe like this


GlobalDeviceLimitConfig:
  Enable: true # Enable the global device limit of a user
  RedisAddr: 10.0.0.188:6379 # The redis server address
  RedisPassword:  # Redis password
  Timeout: 5 # Timeout for redis request
  RedisDB: 0 # Default Redis DB
  Expiry: 60 # Expiry time (second)
Nodes:
  -
    PanelType: "SSpanel" # Panel type: SSpanel, V2board, NewV2board, PMpanel, Proxypanel, V2RaySocks
    ApiConfig:
      ApiHost: "http://127.0.0.1:667"
      ApiKey: "123"
      NodeID: 41
    ControllerConfig:
      ListenIP: 0.0.0.0 # IP address you want to listen
      SendIP: 0.0.0.0 # IP address you want to send pacakage
      RedisDB: 0 # Custom Redis DB[same as defauft]
      AutoSpeedLimitConfig:
        Limit: 0 # Warned speed. Set to 0 to disable AutoSpeedLimit (mbps)
        .....
  -
    PanelType: "SSpanel" # Panel type: SSpanel, V2board, NewV2board, PMpanel, Proxypanel, V2RaySocks
    ApiConfig:
      ApiHost: "http://127.0.0.1:667"
      ApiKey: "123"
      NodeID: 42
    ControllerConfig:
      ListenIP: 0.0.0.0 # IP address you want to listen
      SendIP: 0.0.0.0 # IP address you want to send pacakage
      RedisDB: 1 # Custom Redis DB
      AutoSpeedLimitConfig:
        Limit: 0 # Warned speed. Set to 0 to disable AutoSpeedLimit (mbps)
        WarnTimes: 0 #
....
Septrum101 commented 1 year ago

If you are using v2board. You can easy to use a single xrayr instance to run multi panels.

yuanweize commented 1 year ago

If you are using v2board. You can easy to use a single xrayr instance to run multi panels.

Yes, I have two panels, in the same server for my XrayR configuration has 2 nodes, 2 nodes API respectively 2 panels.

But if there is only one global limter in a config.yml, the uid of both panels will be stored in the same redisDB [global limter redisDB], if the uid is the same and it will be stored in the same redis key

Septrum101 commented 1 year ago

Confirm your version. v0.8.7 added email|uid for identification.

yuanweize commented 1 year ago

Confirm your version. v0.8.7 added email|uid for identification.

I test the globalLimt branch, cause i didn't see where to set valueLimit: 0 # The global device limit of a user, 0 means disable in globalLimit/main/config.yml.example So I put Limit: 0 # The global device limit of a user, 0 means disable in marked place. I only see DeviceLimit: 0 # Local settings will replace remote settings, 0 means disable. I didn't set this.

Log:
  Level: warning # Log level: none, error, warning, info, debug 
  AccessPath: # /etc/XrayR/access.Log
  ErrorPath: # /etc/XrayR/error.log
DnsConfigPath: # /etc/XrayR/dns.json # Path to dns config, check https://xtls.github.io/config/dns.html for help
RouteConfigPath: # /etc/XrayR/route.json # Path to route config, check https://xtls.github.io/config/routing.html for help
InboundConfigPath: # /etc/XrayR/custom_inbound.json # Path to custom inbound config, check https://xtls.github.io/config/inbound.html for help
OutboundConfigPath: # /etc/XrayR/custom_outbound.json # Path to custom outbound config, check https://xtls.github.io/config/outbound.html for help
ConnectionConfig:
  Handshake: 4 # Handshake time limit, Second
  ConnIdle: 30 # Connection idle time limit, Second
  UplinkOnly: 2 # Time limit when the connection downstream is closed, Second
  DownlinkOnly: 4 # Time limit when the connection is closed after the uplink is closed, Second
  BufferSize: 64 # The internal cache size of each connection, kB
GlobalDeviceLimitConfig:
  Enable: true # Enable the global device limit of a user
  Limit: 1 # The global device limit of a user, 0 means disable----------------------<<<<<
  RedisAddr: 10.0.0.188:6379 # The redis server address
  RedisPassword:  # Redis password
  RedisDB: 0 # Redis DB
  Timeout: 5 # Timeout for redis request
  Expiry: 60 # Expiry time (second)

I checked redisDB and saw that key uses UUID|UID to distinguish users. I set GlobalDeviceLimitConfig Limit: 1, but the limit doesn't work. Detail in redisDB:

127.0.0.1:6379[4]> HGETALL "69a6d3bUUID|141"
1) "94.142.94.142"
2) "1"
3) "213.205.94.142."
4) "1"
Septrum101 commented 1 year ago

just set the devicelimit on nodes

yuanweize commented 1 year ago

just set the devicelimit on nodes

I tested with the following configuration, in redisDB can see 2 ip addresses, but both devices can access the internet, not restricted...

DnsConfigPath: # ./dns.json Path to dns config 
GlobalDeviceLimitConfig:
    Enable: true
#    Limit: 0 # The global device limit of a user, 0 means disable
    RedisAddr: redis:63 # The redis server address
    RedisPassword: 123 # Redis password
    RedisDB: 4 # Redis DB
    Timeout: 5 # Timeout for redis request
    Expiry: 60 # Expiry time (second)
Nodes:
- PanelType: V2board
  ApiConfig:
    ApiHost: https://123
    ApiKey: 123
    NodeID: 38
    NodeType: Trojan
    Timeout: 30
    DeviceLimit: 1
    RuleListPath: /etc/XrayR/rulelist
Septrum101 commented 1 year ago

If the IP is in redis. XrayR will bypass this ip. The mechanism same as local limit.

yuanweize commented 1 year ago

If the IP is in redis. XrayR will bypass this ip. The mechanism same as local limit.

I set devicelimit: 1, but I see 2 ip address in redis.

So if the limit is 1, then the number of ip in redis should also be 1?

Septrum101 commented 1 year ago

you can use 2 nodes to test. global is a flex limit not hard limit.

Septrum101 commented 1 year ago

If you have other questions. Please reopen this issue.