JumpServer在5月27日推出了他们的LTS版本:4。 10,然后我就寻思给现有的堡垒机升一下级,然后等到这两天4。 10。 1版本出来之后就趁晚上有空就升级一下。

然后,它就挂了。

  1. 06 北京·朝阳

故障

表现

具体问题就是升级完成之后,数据库架构出现问题,应用程序无法执行。应用回滚会出现“服务器连接错误”提示,所有创建的服务器信息丢失。

解决的思路一个是重新导入备份的数据库,一个是解决数据库结构的问题。

[root@jump jumpserver-installer-v4. 10. 1]# ./jmsctl.sh upgrade
Are you sure you want to update the current version to v4. 10. 1-ce ? ( y/n ) ( default y ): y

1. Check Configuration File
Path to Configuration file: /opt/jumpserver/config
/opt/jumpserver/config/config.txt [ √ ]
/opt/jumpserver/config/loki/loki.yaml [ √ ]
/opt/jumpserver/config/loki/promtail.yml [ √ ]
/opt/jumpserver/config/mariadb/mariadb.cnf [ √ ]
/opt/jumpserver/config/mysql/my.cnf [ √ ]
/opt/jumpserver/config/nginx/lb_http_server.conf [ √ ]
/opt/jumpserver/config/redis/redis.conf [ √ ]
/opt/jumpserver/config/nginx/cert/server.crt [ √ ]
/opt/jumpserver/config/nginx/cert/server.key [ √ ]

complete

2. Loading Docker Image
[jumpserver/core:v4. 10. 1-ce] exist, pass
[redis:7. 0-bullseye] exist, pass
[mariadb:10. 6] exist, pass
[jumpserver/lion:v4. 10. 1-ce] exist, pass
[jumpserver/web:v4. 10. 1-ce] exist, pass
[jumpserver/koko:v4. 10. 1-ce] exist, pass
[jumpserver/chen:v4. 10. 1-ce] exist, pass
complete

3. Backup database
Backing up...
[SUCCESS] Backup succeeded! The backup file has been saved to: /data/jumpserver/db_backup/db_jump-v4. 8. 1-ce-2025-06-05_22:35:37. sql

4. Backup Configuration File
Back up to /data/jumpserver/db_backup/config-v4. 8. 1-ce-2025-06-05_22:35:39. conf

5. Apply database changes
Changing database schema may take a while, please wait patiently
Detected that the JumpServer container is running. Do you want to close the container and continue to upgrade? ( y/n ) ( default y ): y

[+] Running 8/8
✔ Container jms_redis Removed 0. 4s
✔ Container jms_koko Removed 0. 3s
✔ Container jms_chen Removed 0. 2s
✔ Container jms_core Removed 10. 3s
✔ Container jms_web Removed 0. 4s
✔ Container jms_lion Removed 0. 3s
✔ Container jms_celery Removed 10. 4s
! Network jms_net Resource is still in use 0. 0s

WARN[0000] Found orphan containers ( [jms_receptor] ) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
[+] Running 2/2
✔ Container jms_core Started 0. 3s
✔ Container jms_redis Started 0. 3s
2025-06-05 22:36:10 Collect static files
2025-06-05 22:36:10 Collect static files done
2025-06-05 22:36:10 Check database structure change ...
2025-06-05 22:36:10 Migrate model change to database ...
Operations to perform:
Apply all migrations: accounts, acls, admin, assets, audits, auth, authentication, captcha, contenttypes, django_cas_ng, django_celery_beat, labels, notifications, ops, orgs, perms, rbac, sessions, settings, terminal, tickets, users
Running migrations:
Applying audits. 0006_alter_ftplog_account_alter_ftplog_asset_and_more... 2025-06-05 22:36:10 Perform migrate failed
Traceback ( most recent call last ):
File "/opt/py3/lib/python3. 11/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute( sql, params )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/django/db/backends/mysql/base.py", line 75, in execute
return self.cursor.execute( query, args )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/MySQLdb/cursors.py", line 179, in execute
res = self._query( mogrified_query )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/MySQLdb/cursors.py", line 330, in _query
db.query( q )
File "/opt/py3/lib/python3. 11/site-packages/MySQLdb/connections.py", line 261, in query
_mysql.connection.query( self, query )
MySQLdb. OperationalError: ( 1061, "Duplicate key name 'audits_ftplog_account_5b6c1128'" )

The above exception was the direct cause of the following exception:

Traceback ( most recent call last ):
File "/opt/jumpserver/./jms", line 203, in <module>
upgrade_db()
File "/opt/jumpserver/./jms", line 137, in upgrade_db
perform_db_migrate()
File "/opt/jumpserver/./jms", line 92, in perform_db_migrate
raise e
File "/opt/jumpserver/./jms", line 89, in perform_db_migrate
management.call_command( 'migrate' )
File "/opt/py3/lib/python3. 11/site-packages/django/core/management/__init__. py", line 198, in call_command
return command.execute( *args, **defaults )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle( *args, **options )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/django/core/management/base.py", line 96, in wrapped
res = handle_func( *args, **kwargs )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/django/core/management/commands/migrate.py", line 349, in handle
post_migrate_state = executor.migrate(
^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/django/db/migrations/executor.py", line 135, in migrate
state = self._migrate_all_forwards(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
state = self.apply_migration(
^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
state = migration.apply( state, schema_editor )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/django/db/migrations/migration.py", line 130, in apply
operation.database_forwards(
File "/opt/py3/lib/python3. 11/site-packages/django/db/migrations/operations/fields.py", line 235, in database_forwards
schema_editor.alter_field( from_model, from_field, to_field )
File "/opt/py3/lib/python3. 11/site-packages/django/db/backends/base/schema.py", line 788, in alter_field
self._alter_field(
File "/opt/py3/lib/python3. 11/site-packages/django/db/backends/base/schema.py", line 1060, in _alter_field
self.execute( self._create_index_sql( model, fields=[new_field] ))
File "/opt/py3/lib/python3. 11/site-packages/django/db/backends/base/schema.py", line 199, in execute
cursor.execute( sql, params )
File "/opt/py3/lib/python3. 11/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor( sql, params, many, context )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/django/db/backends/utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "/opt/py3/lib/python3. 11/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback( traceback ) from exc_value
File "/opt/py3/lib/python3. 11/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute( sql, params )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/django/db/backends/mysql/base.py", line 75, in execute
return self.cursor.execute( query, args )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/MySQLdb/cursors.py", line 179, in execute
res = self._query( mogrified_query )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/py3/lib/python3. 11/site-packages/MySQLdb/cursors.py", line 330, in _query
db.query( q )
File "/opt/py3/lib/python3. 11/site-packages/MySQLdb/connections.py", line 261, in query
_mysql.connection.query( self, query )
django.db.utils. OperationalError: ( 1061, "Duplicate key name 'audits_ftplog_account_5b6c1128'" )
[ERROR] Failed to change the table structure!

方案

这个问题在Jumpserver的版本历史上出现过好几次了,其实就是数据库字符集的问题。在Jumpserver官方社区里面翻了一下找到了相应的解决方案:

已确定最终问题, 1panel 创建的 jumpserver 数据库默认是 utf8mb4 的,也就是一个字符占用 4个字节,asset 是 varchar( 1024 ), 也就是 4096, 而 mysql 索引最大是 3072, 所以报错了。但如果数据库是 utf8mb3 不会出现这个问题。

解决方案:

更改 audits_ftplog 中 asset 字段的字符集
ALTER TABLE audits_ftplog MODIFY asset VARCHAR( 1024 ) CHARACTER SET utf8 COLLATE utf8_general_ci;
查看已添加的索引
SHOW INDEX FROM audits_ftplog;

看到那个 audits_ftplog_account_xxxx

删除已添加的 account 索引
DROP INDEX audits_ftplog_account_xxxx ON table_name;

处理

数据库

# 连接数据库
mysql -ujumpserver -hxxxx -p
mysql> use db_jump
# 更改 audits_ftplog 中 asset 字段的字符集
mysql> ALTER TABLE audits_ftplog MODIFY asset VARCHAR( 1024 ) CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 9822 rows affected, 2 warnings ( 0. 18 sec )
Records: 9822 Duplicates: 0 Warnings: 2
# 查看已添加的索引
mysql> SHOW INDEX FROM audits_ftplog;
+---------------+------------+-----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+---------------+------------+-----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| audits_ftplog | 0 | PRIMARY | 1 | id | A | 9672 | NULL | NULL | | BTREE | | | YES | NULL |
| audits_ftplog | 1 | audits_ftplog_org_id_de02081f | 1 | org_id | A | 1 | NULL | NULL | | BTREE | | | YES | NULL |
| audits_ftplog | 1 | audits_ftplog_date_start_1672920a | 1 | date_start | A | 9672 | NULL | NULL | | BTREE | | | YES | NULL |
| audits_ftplog | 1 | audits_ftplog_account_5b6c1128 | 1 | account | A | 6 | NULL | NULL | | BTREE | | | YES | NULL |
+---------------+------------+-----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
4 rows in set ( 0. 00 sec )
# 删除已添加的 account 索引
mysql> DROP INDEX audits_ftplog_account_5b6c1128 ON audits_ftplog;
Query OK, 0 rows affected ( 0. 01 sec )
Records: 0 Duplicates: 0 Warnings: 0

应用

# 下载在线升级包
cd /opt
wget https://resource.fit2cloud.com/jumpserver/installer/releases/download/v4. 10. 1/jumpserver-installer-v4. 10. 1. tar.gz
tar -xf jumpserver-installer-v4. 10. 1. tar.gz
cd jumpserver-installer-v4. 10. 1

# 开始升级
./jmsctl.sh upgrade
# 启动 JumpServer 服务
./jmsctl.sh start