YashanDB修改yasom管理端口的技术研究

我们的文章会在微信公众号IT民工的龙马人生博客网站 ( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢!
由于博客中有大量代码,通过页面浏览效果更佳。

需求说明

来自一次跟朋友的聊天,提到YashanDB的OM管理组件是否可以改端口号。这是一个很新颖的问题,也觉得很有意思。在过去的运维和测试过程中,常做的修改都是修改IP地址或者数据库的监听端口,还很少去思考管理端口的修改。怀着对这个问题的好奇,决定研究一下如何修改。

YashanDB在部署过程中具备自定义端口的功能,所以可以推断安装完成后也可以自定义修改端口。连上VPN,开始搜索相关资料,结果没有搜到类似的需求和操作文档。既然没有现成的,又到晚上12点了,不打扰研发同事,就只能自己研究一下。下面分享一下自己研究的过程和汇总的内容。

本文档只限于技术测试,请勿用于生产环境和业务测试环境。如生产环境有类似的需求,请直接联系YashanDB。

测试环境介绍

测试环境采用主从架构,数据库版本为23.4.6.100,操作系统为麒麟V10,数据库运行状态如下:

[yashan@kylin01 .yasboot]$ yasboot cluster status -c yashandb -d 
+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
| hostid   | node_type | nodeid | pid  | instance_status | database_status | database_role | listen_address    | source_node | data_path                      |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
| host0001 | db        | 1-1:1  | 1572 | open            | normal          | primary       | 10.10.10.125:1688 | -           | /data/yashan/yasdb_data/db-1-1 |
+----------+-----------+--------+------+-----------------+-----------------+---------------+-------------------+-------------+--------------------------------+
| host0002 | db        | 1-2:2  | 1697 | open            | normal          | standby       | 10.10.10.126:1688 | 1-1:1       | /data/yashan/yasdb_data/db-1-2 |
+----------+-----------+--------+------+-----------------+-----------------+---------------+-------------------+-------------+--------------------------------+

修改OM端口

下面将研究后修改OM端口的操作命令汇总如下,需要在主从的所有节点上执行:

[yashan@kylin01 .yasboot]$ sed -i 's/1675/3675/' /data/yashan/yasdb_home/23.4.6.100/om/yashandb/conf/yasom.toml
[yashan@kylin01 .yasboot]$ sed -i 's/1675/3675/' /home/yashan/.yasboot/yashandb.env 
[yashan@kylin01 .yasboot]$ ps -ef|grep -E 'yasom|yasagent'|grep -v grep|awk '{print $2}'|xargs kill -9

测试过程

下面的测试基于猜想进行的验证过程。

寻找配置文件

YashanDB管理组件在安装过程中支持自定义端口,并且是提前编译好的Go语言二进制文件。因此,自定义的端口号可能是写入配置文件中,而非写入静态的二进制文件中。

[root@kylin01 om]# find  /data/yashan/ -type f |grep -Ei "conf|toml"|xargs -i grep -E "10.10" {}
ARCHIVE_DEST_1=SERVICE=10.10.10.126:1689 NODE_ID=1-2:2
LISTEN_ADDR=10.10.10.125:1688
REPLICATION_ADDR=10.10.10.125:1689
ListenAddr = "10.10.10.125:1676"
listen_addr = "10.10.10.125:1675"

10.10.10.125:1675 就是当前OM的IP地址和端口号。

查询yasboot日志

OM可以通过yasboot来启动,这说明yasboot执行的命令肯定包含对应的IP地址和端口号信息。相关日志如下:

2026-01-16 23:57:52 DEBUG  [yasboot] exec.go:63 exec: bash -c ps auxww | grep -w /data/yashan/yasdb_home/23.4.6.100/bin/yasom | grep -v -w grep | awk '{print$2}' starting
2026-01-16 23:57:52 DEBUG  [yasboot] exec.go:63 exec: bash -c export YASDB_OM_ADDR=10.10.10.125:1675; /data/yashan/yasdb_home/23.4.6.100/bin/yasom -c yashandb -l 10.10.10.125:1675 -d starting
2026-01-16 23:57:53 DEBUG  [monit] exec.go:63 exec: bash -c /data/yashan/yasdb_home/23.4.6.100/om/bin/monit -c /data/yashan/yasdb_home/23.4.6.100/om/monit/monitrc monitor yasom starting

可以找到下面这行记录,表明YashanDB启动时执行的命令。在执行命令前设置了环境变量YASDB_OM_ADDR=10.10.10.125:1675。

bash -c export YASDB_OM_ADDR=10.10.10.125:1675; /data/yashan/yasdb_home/23.4.6.100/bin/yasom -c yashandb -l 10.10.10.125:1675 -d starting

跟踪Yasboot获取值的途径

通过操作系统strace命令可以跟踪到yasboot执行过程中打开的文件信息:

newfstatat(AT_FDCWD, "/home/yashan/.yasboot/yashandb.env", {st_mode=S_IFREG|0664, st_size=184, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "/home/yashan/.yasboot/yashandb.env", O_RDONLY|O_CLOEXEC) = 3
fcntl(3, F_GETFL)                       = 0x8000 (flags O_RDONLY|O_LARGEFILE)
fcntl(3, F_SETFL, O_RDONLY|O_NONBLOCK|O_LARGEFILE) = 0
epoll_ctl(4, EPOLL_CTL_ADD, 3, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=377487362, u64=9181517284579999746}}) = -1 EPERM (Operation not permitted)
fcntl(3, F_GETFL)                       = 0x8800 (flags O_RDONLY|O_NONBLOCK|O_LARGEFILE)
fcntl(3, F_SETFL, O_RDONLY|O_LARGEFILE) = 0
read(3, "cluster=\"yashandb\"\nom_addr=\"10.1"..., 512) = 184
read(3, "", 328)                        = 0
close(3)                                = 0
newfstatat(AT_FDCWD, "/data/yashan/yasdb_home/23.4.6.100/om/yashandb/conf/yasom.toml", {st_mode=S_IFREG|0600, st_size=615, ...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "/home/yashan/.yasboot/yashandb_yasdb_home/bin/bash", 0xc0004b3628, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/local/bin/bash", 0xc0004b36f8, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1166952, ...}, 0) = 0
syscall_0x1b7(0xffffffffffffff9c, 0xc0003341d0, 0x1, 0x200, 0, 0) = -1 ENOSYS (Function not implemented)
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1166952, ...}, 0) = 0

通过newfstatat打开了yashandb.env文件,同时通过read读取了文件中的cluster和om_addr的值。

查询yashandb.env的值

env文件中保存了环境变量,yasboot通过这个配置文件来获取OM的信息。

[yashan@kylin01 .yasboot]$ cat yashandb.env
cluster="yashandb"
om_addr="10.10.10.125:3675"
version="23.4.6.100"
same_version=false
base_path="/data/yashan/yasdb_home/23.4.6.100"
max_ac_sql_size=209715200
max_ac_sql_rows=1000000

yasom.toml文件内容

listen_addr参数记录了OM的配置信息,可以推断OM在启动时会自动读取这个文件的配置信息。

[yashan@kylin01 ~]$ vi  /data/yashan/yasdb_home/23.4.6.100/om/yashandb/conf/yasom.toml
listen_addr = "10.10.10.125:1675"
pprof_addr = "0.0.0.0:7890"
sync_interval = 5
sync_mode = "async"
sync_retry_time = 3
mode = "Release"

[db]
  driver = "sqlite3"
  url = "/data/yashan/yasdb_home/23.4.6.100/om/yashandb/data/cod_domor.db?cache=shared&mode=rwc"
  max_open_conns = 1
  auto_migrate = true

[log]
  level = 0
  max_age = 7
  max_size = 104857600
  max_backups = 30
  path = "/data/yashan/log/om/yashandb"
  log_path = "/data/yashan/log/om/yashandb/yasom.log"
  err_log_path = "/data/yashan/log/om/yashandb/yasom-panic.log"
  start_log = "/data/yashan/log/om/yashandb/yasom-start.log"
  console = true

sqlite3的内容

通过sqlite3的dump命令可以发现数据库中还写入了om_addr的信息。

[yashan@kylin01 ~]$ cat /tmp/cod_domor.txt |grep 1675
INSERT INTO kv_config VALUES('om_addr','10.10.10.125:1675',4,'2026-01-16 23:39:20.603647396+08:00','2026-01-16 23:39:20.603647396+08:00',NULL);

验证env与yasom.toml哪个生效

前面提到env文件很可能是给yasboot使用的,yasom.toml里面才是真正的OM监听参数的配置文件。因此,这里简单测试一下env与yasom.toml配置不同的端口号时哪个会生效。

修改env端口

在所有的节点上执行下面命令:

sed -i 's/3675/1675/' /home/yashan/.yasboot/yashandb.env 
ps -ef|grep -E 'yasom|yasagent'|grep -v grep|awk '{print $2}'|xargs kill -9

查询进程

监控进程会自动启动服务。yasom进程启动时有一个-l参数,指定了10.10.10.125和1675。

[yashan@kylin01 ~]$ ps -ef|grep yasom
yashan     11765       1  0 11:47 ?        00:00:00 /data/yashan/yasdb_home/23.4.6.100/bin/yasom -c yashandb -l 10.10.10.125:1675 -d

确认端口

确认yasom进程占用的端口号。这里可以看到端口号是3675,而不是1675。

[root@kylin01 ~]# netstat -anp|grep 11765
tcp        0      0 10.10.10.125:3675       0.0.0.0:*               LISTEN      11765/yasom

参数-l指定的IP地址和端口号看起来没有生效,而是直接读取yasom.toml中的配置文件。

查看YASOM参数

在-h帮助信息中,可以看到-l参数表示OM监听的IP地址和端口号。但从实际测试结果可以推断出,-l参数在监听端口配置上没有生效,不确定是否有其他作用。

[yashan@kylin01 ~]$ yasom  -h

Usages: yasom [<flags>] <command>

yasom daemon process, version: Release 23.4.6.100

Flags:
  -h,--help        Show detailed help information.
     --init        start process with initialization
  -c,--cluster     run with cluster
  -l,--listen      listen on address
  -k,--secret-key  listen rpc secret key
  -d,--daemon      start process in daemon
     --secondary   start yasom as secondary mode
  -L,--log-path    log path
     --web         start om with web mode

Commands:
  completion  generate completion scription

Run 'yasom COMMAND --help' for more information on a command.

查看集群状态

这里可以看到端口1675无法访问:

[yashan@kylin01 ~]$ yasboot cluster status -c yashandb
dial tcp 10.10.10.125:1675: connect: connection refused

yasboot的日志如下:

2026-01-17 11:50:12 DEBUG  [yasboot] rpcclient.go:102 yashandb connecting om: 10.10.10.125:1675
2026-01-17 11:50:12 ERROR  [yasboot] client.go:233 failed to dial server: dial tcp 10.10.10.125:1675: connect: connection refused

这个ERROR级别的日志信息简洁而精确。

结论

OM监听端口的修改直接修改yasom.toml文件即可。

验证功能

通过上面的修改,简单验证yasboot对集群的操作功能是否正常:

[yashan@kylin01 .yasboot]$ yasboot cluster status -c yashandb -d 
+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
| hostid   | node_type | nodeid | pid  | instance_status | database_status | database_role | listen_address    | source_node | data_path                      |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
| host0001 | db        | 1-1:1  | 1572 | open            | normal          | primary       | 10.10.10.125:1688 | -           | /data/yashan/yasdb_data/db-1-1 |
+----------+-----------+--------+------+-----------------+-----------------+---------------+-------------------+-------------+--------------------------------+
| host0002 | db        | 1-2:2  | 1697 | open            | normal          | standby       | 10.10.10.126:1688 | 1-1:1       | /data/yashan/yasdb_data/db-1-2 |
+----------+-----------+--------+------+-----------------+-----------------+---------------+-------------------+-------------+--------------------------------+

[yashan@kylin01 .yasboot]$ yasboot cluster stop -c yashandb
+----------------------------------------------------------------------------------------------------------+
| type | uuid             | name             | hostid | index    | status  | return_code | progress | cost |
+----------------------------------------------------------------------------------------------------------+
| task | 64896ec574dd1cb0 | StopYasdbCluster | -      | yashandb | SUCCESS | 0           | 100      | 6    |
+------+------------------+------------------+--------+----------+---------+-------------+----------+------+
task completed, status: SUCCESS
[yashan@kylin01 .yasboot]$ yasboot cluster start -c yashandb
+-----------------------------------------------------------------------------------------------------------+
| type | uuid             | name              | hostid | index    | status  | return_code | progress | cost |
+-----------------------------------------------------------------------------------------------------------+
| task | 338cc4218c196c97 | StartYasdbCluster | -      | yashandb | SUCCESS | 0           | 100      | 4    |
+------+------------------+-------------------+--------+----------+---------+-------------+----------+------+
task completed, status: SUCCESS

/------------------作者介绍----------------------
姓名:黄廷忠
个人博客: (http://www.htz.pw)
CSDN地址: (https://blog.csdn.net/wwwhtzpw)
博客园地址: (https://www.cnblogs.com/www-htz-pw)
------------------------------------------------/

posted @ 2026-01-17 17:14  认真就输  阅读(3)  评论(0)    收藏  举报