概述
MySQL 8.0 启动过程中会开启 33060 端口,而在 JumpServer 服务器中 33060 端口是 Magnus 组件用来连接 MySQL 数据库的端口,当数据库 MySQL 8.0 与 JumpServer 安装在同一服务器上时,可能会出现端口占用的情况。
概览
默认数据库 MySQL 8.x 安装后的端口如下所示:
[root@DB-01 ~]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; generated)
Active: active (exited) since Tue 2023-12-05 02:40:52 EST; 3s ago
Docs: man:systemd-sysv-generator(8)
Process: 2713527 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
12月 05 02:40:51 DB-01 systemd[1]: Starting LSB: start and stop MySQL...
12月 05 02:40:52 DB-01 mysqld[2713527]: Starting MySQL SUCCESS!
12月 05 02:40:52 DB-01 systemd[1]: Started LSB: start and stop MySQL.
12月 05 02:40:52 DB-01 mysqld[2713527]: 2023-12-05T07:40:52.779358Z mysqld_safe error: log-error set to '/data/mysql/error.log', however file don't exists. Create w>
[root@DB-01 ~]# netstat -nltp |grep mysqld
tcp6 0 0 :::33060 :::* LISTEN 16916/./bin/mysqld
tcp6 0 0 :::3306 :::* LISTEN 16916/./bin/mysqld
33060 端口 用于 MySQL X 协议(服务器 mysqlx_port 选项)
解决方法
方法一、修改 MySQL 的默认端口
打开 MySQL 的配置文件,默认为 /etc/my.cnf。
添加端口相关配置项:port 与 mysqlx_port。
[mysqld]
# skip-grant-tables
# mysql安装目录
#basedir=/usr/local/mysql/
basedir=/data/mysql/
# mysql数据库目录
#datadir=/var/lib/mysql/data
datadir=/data/mysql/data
port=3306
innodb_file_per_table=1
character-set-server=UTF8MB4
mysqlx_port=33060
log-bin=mysql-bin
binlog_format=mixed
修改 mysqlx_port 端口设置,修改配置后重新启动 MySQL,验证修改结果 。
[root@DB-01 ~]# netstat -nltp |grep mysqld
tcp6 0 0 :::33060 :::* LISTEN 16916/./bin/mysqld
tcp6 0 0 :::3306 :::* LISTEN 16916/./bin/mysqld
方法二、修改 JumpServer 对应的窗口
打开 JumpServer 的配置文件,默认位置位于 /opt/jumpserver/config/config.txt。
修改当中的 MAGNUS_MYSQL_PORT 选项为未被占用的端口。
################################## 访问配置 ###################################
# 对外提供服务端口, 如果与现有服务冲突请自行修改
#
HTTP_PORT=80
SSH_PORT=2222
MAGNUS_MYSQL_PORT=33061
MAGNUS_MARIADB_PORT=33062
MAGNUS_REDIS_PORT=63790
MAGNUS_POSTGRESQL_PORT=54320
MAGNUS_ORACLE_PORTS=30000-30030
修改完成后重新启动 JumpServer 即修改完成。重启命令如下:
$ jmsctl restart
或
$ cd /opt/jumpserver-offline-installer-版本号-系统架构-补丁/
$ ./jmsctl.sh restart
重启完成后查看系统状态。
[root@jumpserver-01 config]# jmsctl status
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
jms_celery registry.fit2cloud.com/jumpserver/core:v3.5.4 "./entrypoint.sh sta…" celery 3 weeks ago Up 2 weeks (unhealthy) 8080/tcp
jms_chen registry.fit2cloud.com/jumpserver/chen:v3.5.4 "./entrypoint.sh" chen 3 weeks ago Up 3 weeks (healthy) 8082/tcp
jms_core registry.fit2cloud.com/jumpserver/core:v3.5.4 "./entrypoint.sh sta…" core 3 weeks ago Up 3 weeks (healthy) 8080/tcp
jms_kael registry.fit2cloud.com/jumpserver/kael:v3.5.4 "./entrypoint.sh" kael 3 weeks ago Up 3 weeks (healthy) 8083/tcp
jms_koko registry.fit2cloud.com/jumpserver/koko:v3.5.4 "./entrypoint.sh" koko 3 weeks ago Up 3 weeks (healthy) 0.0.0.0:2222->2222/tcp, :::2222->2222/tcp, 5000/tcp
jms_lion registry.fit2cloud.com/jumpserver/lion:v3.5.4 "./entrypoint.sh" lion 3 weeks ago Up 3 weeks (healthy) 4822/tcp, 8081/tcp
jms_magnus registry.fit2cloud.com/jumpserver/magnus:v3.5.4 "./entrypoint.sh" magnus 3 weeks ago Up 3 weeks (healthy) 0.0.0.0:30000-30030->30000-30030/tcp, :::30000-30030->30000-30030/tcp, 0.0.0.0:33061-33062->33061-33062/tcp, :::33061-33062->33061-33062/tcp, 0.0.0.0:54320->54320/tcp, :::54320->54320/tcp, 0.0.0.0:63790->63790/tcp, :::63790->63790/tcp
jms_mysql sha256:aac2cf878de917be8d8f9824756ec5850ba7ccbfc71eaa85346635a50bd7eb89 "docker-entrypoint.s…" mysql 4 weeks ago Up 4 weeks (healthy) 3306/tcp
jms_razor registry.fit2cloud.com/jumpserver/razor:v3.5.4 "./entrypoint.sh" razor 3 weeks ago Up 3 weeks (healthy) 0.0.0.0:3389->3389/tcp, :::3389->3389/tcp
jms_redis sha256:48da0c367062717d34d72a5b7ef416dc2ee830430356ac312ccdd861443a6d5a "docker-entrypoint.s…" redis 4 weeks ago Up 4 weeks (healthy) 6379/tcp
jms_web registry.fit2cloud.com/jumpserver/web:v3.5.4 "/docker-entrypoint.…" web 3 weeks ago Up 3 weeks (healthy) 0.0.0.0:80->80/tcp, :::80->80/tcp
jms_xrdp registry.fit2cloud.com/jumpserver/xrdp:v3.5.4 "./entrypoint.sh" xrdp 3 weeks ago Up 3 weeks (healthy) 0.0.0.0:3390->3390/tcp, :::3390->3390/tcp
在输出信息中查看 jms_magnus 使用的端口是否设置成功。
[root@jumpserver-01 config]# netstat -nltp |grep 33062
tcp 0 0 0.0.0.0:33062 0.0.0.0:* LISTEN 3279940/docker-prox
tcp6 0 0 :::33062 :::* LISTEN 3279946/docker-prox
总结说来,通过以上两种修改配置的方法都可以解决端口冲突的问题。