From 93e5a0ba5c031c52b2142f2cd310b6d2e6560f9f Mon Sep 17 00:00:00 2001 From: "Jiangjie.Bai" Date: Wed, 19 Oct 2022 17:42:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=20DB=20Port=20Mapper=20=E6=97=B6=E7=9A=84=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/signal_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/terminal/signal_handlers.py b/apps/terminal/signal_handlers.py index 942e9972a..537d90bce 100644 --- a/apps/terminal/signal_handlers.py +++ b/apps/terminal/signal_handlers.py @@ -21,7 +21,7 @@ def init_db_port_mapper(sender, **kwargs): try: db_port_manager.init() except (ProgrammingError,) as e: - logger.error('Init db port mapper error: {}'.format(e)) + pass @receiver(post_save, sender=Application) From c6a3a141bb3e493e93bf0e24af7475d00be5df30 Mon Sep 17 00:00:00 2001 From: "Jiangjie.Bai" Date: Wed, 19 Oct 2022 20:03:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96Magnus=20Ports?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E6=98=A0=E5=B0=84=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jumpserver/conf.py | 3 +-- apps/jumpserver/settings/custom.py | 3 +-- apps/terminal/utils/db_port_mapper.py | 15 ++++++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/jumpserver/conf.py b/apps/jumpserver/conf.py index 7edc28610..d7e4aee14 100644 --- a/apps/jumpserver/conf.py +++ b/apps/jumpserver/conf.py @@ -485,8 +485,7 @@ class Config(dict): 'SECURITY_DATA_CRYPTO_ALGO': None, 'GMSSL_ENABLED': False, # Magnus 组件需要监听的端口范围 - 'MAGNUS_DB_PORTS_START': 30000, - 'MAGNUS_DB_PORTS_LIMIT_COUNT': 1000, + 'MAGNUS_PORTS': '30000-30100', # 记录清理清理 'LOGIN_LOG_KEEP_DAYS': 200, diff --git a/apps/jumpserver/settings/custom.py b/apps/jumpserver/settings/custom.py index caa712ab3..4e9676379 100644 --- a/apps/jumpserver/settings/custom.py +++ b/apps/jumpserver/settings/custom.py @@ -179,5 +179,4 @@ SESSION_RSA_PRIVATE_KEY_NAME = 'jms_private_key' SESSION_RSA_PUBLIC_KEY_NAME = 'jms_public_key' # Magnus DB Port -MAGNUS_DB_PORTS_START = CONFIG.MAGNUS_DB_PORTS_START -MAGNUS_DB_PORTS_LIMIT_COUNT = CONFIG.MAGNUS_DB_PORTS_LIMIT_COUNT +MAGNUS_PORTS = CONFIG.MAGNUS_PORTS diff --git a/apps/terminal/utils/db_port_mapper.py b/apps/terminal/utils/db_port_mapper.py index ab52aa2a3..b1485ec08 100644 --- a/apps/terminal/utils/db_port_mapper.py +++ b/apps/terminal/utils/db_port_mapper.py @@ -20,15 +20,20 @@ class DBPortManager(object): CACHE_KEY = 'PORT_DB_MAPPER' def __init__(self): - self.port_start = settings.MAGNUS_DB_PORTS_START - self.port_limit = settings.MAGNUS_DB_PORTS_LIMIT_COUNT - self.port_end = self.port_start + self.port_limit + try: + port_start, port_end = settings.MAGNUS_PORTS.split('-') + port_start, port_end = int(port_start), int(port_end) + except Exception as e: + logger.error('MAGNUS_PORTS config error: {}'.format(e)) + port_start, port_end = 30000, 30100 + + self.port_start, self.port_end = port_start, port_end # 可以使用的端口列表 - self.all_available_ports = list(range(self.port_start, self.port_end)) + self.all_available_ports = list(range(self.port_start, self.port_end + 1)) @property def magnus_listen_port_range(self): - return f'{self.port_start}-{self.port_end - 1}' + return settings.MAGNUS_PORTS def init(self): with tmp_to_root_org():