跳到主要内容
版本:v3&v6

MYSQL 5.7.X 外置迁移

MYSQL 外置迁移操作,会造成 ONES 服务短暂不可用

配置参数

配置项类型示例描述
mysql_hoststring"10.15.10.203"mysql服务器ip
mysql_portstring"3306"mysql服务端口
mysql_passwordstring"ones@2023"mysql ones 用户密码
is_use_independence_mysqlbooleantrue是否使用外置数据库

环境准备

MYSQL 版本需要是 5.7.42 或 5.7.43,未来更新的版本可能存在兼容性问题
数据库必须是独立实例(不能与其他应用混在一起,否则会影响部署)
考虑到性能压力,mysql 实例的机器资源建议按 ONES 的一半来配置,后续也要能够进行方便的调整

my.cnf 配置文件

如使用阿里云 RDS 数据库,使用 1.2 中的 my.cnf 配置文件

[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4

[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql/
datadir = /usr/local/mysql/data/
pid-file = /var/run/mysqld/mysqld.pid
user = mysql
server-id = 1
log-bin = mysql-bin
log_slave_updates = on #从服务器将时间记录到二进制日志中
auto_increment_increment=1 #自动增长的步长
auto_increment_offset=1

init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
performance_schema_max_table_instances = 200
table_definition_cache=200
table_open_cache=128
log_error = /var/log/mysql/mysql-error.log

character_set_server=utf8mb4
collation_server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

bind-address = 0.0.0.0

skip-name-resolve
back_log = 600
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
max_allowed_packet = 512M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 8M
query_cache_limit = 2M
key_buffer_size = 4M
ft_min_word_len = 4
transaction_isolation = REPEATABLE-READ

log_bin = mysql-bin
binlog_format = row
expire_logs_days = 7
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
skip-external-locking
default-storage-engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 2048M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
interactive_timeout = 28800
wait_timeout = 28800
net_read_timeout = 600
net_write_timeout = 600

#GTID:
gtid_mode=on
enforce_gtid_consistency=on
session_track_gtids=OWN_GTID
session_track_state_change=ON

[mysqldump]
quick
max_allowed_packet = 1024M

my.cnf 配置文件(适用于阿里云 RDS 数据库)

port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
server-id = 1
log-bin = mysql-bin
log_slave_updates = on
auto_increment_increment=1
auto_increment_offset=1
init-connect = 'set names utf8mb4'
character-set-server = utf8mb4
performance_schema_max_table_instances = 200
table_definition_cache=400
table_open_cache=128
log_error = /data/log/mysql/mysql-error.log
lc-messages-dir = /usr/share/mysql/english/
character_set_server=utf8mb4
collation_server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
bind-address = 0.0.0.0
back_log = 600
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
max_allowed_packet = 536870912
binlog_cache_size = 1048576
max_heap_table_size = 8388608
tmp_table_size = 16777216
read_buffer_size = 2097152
read_rnd_buffer_size = 8388608
sort_buffer_size = 8388608
join_buffer_size = 8388608
thread_cache_size = 8
query_cache_size = 8388608
query_cache_limit = 1048576
key_buffer_size = 4194304
ft_min_word_len = 4
transaction_isolation = REPEATABLE-READ
log_bin = mysql-bin
binlog_format = row
expire_logs_days = 7
slow_query_log = ON
long_query_time = 1
slow_query_log_file = /data/log/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp=ON
default-storage-engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 2147483648
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2097152
innodb_log_file_size = 33554432
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_large_prefix=ON
bulk_insert_buffer_size = 8388608
myisam_sort_buffer_size = 8388608
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
net_read_timeout = 600
net_write_timeout = 600
gtid_mode=on
enforce_gtid_consistency=on
session_track_gtids=OWN_GTID
session_track_state_change=ON

操作步骤:

数据备份

数据备份文档

获取 mysql ones用户密码

查询onesopenplatform用户密码

./json-util -config config.json -operator select -key mysql_password
./json-util -config config.json -operator select -key mysql_open_platform_password

拿到如下输出中的密码

[root@localhost ones-example-3.14.xxxxx]# ./json-util -config config.json -operator select -key mysql_password
rQ7W98YRy7cMWcP # ones 用户密码
[root@localhost ones-example-3.14.xxxxx]# ./json-util -config config.json -operator select -key mysql_open_platform_password
rQ7W98YRy7cMWcP # openplatform 用户密码

创建外置数据库用户

mysql root 账号登陆可能需要客户协助

使用 root 账号登陆外置 mysql, 请根据客户提供的 root 密码替换掉下面的 <mysql_root_password>

mysql -uroot -p<mysql_root_password> -h<mysql_host> -P<mysql_port>

创建onesopenplatform用户并赋予该用户root权限,下面的 <mysql_password> <mysql_open_platform_password> 请使用上面获取的用户密码替换

CREATE USER 'ones'@'%' IDENTIFIED BY <mysql_password>;
GRANT ALL PRIVILEGES ON *.* TO 'ones'@'%' WITH GRANT OPTION;

CREATE USER 'openplatform'@'%' IDENTIFIED BY <mysql_open_platform_password>;
GRANT ALL PRIVILEGES ON *.* TO 'openplatform'@'%' WITH GRANT OPTION;

FLUSH PRIVILEGES;

开始外置迁移

登陆 ONES 服务器,进入当前运行中实例的安装目录

cd /data/ones/pkg/ones-example-3.14.xxxxx

执行 common.sh 脚本,交互页面选择 10 选项

执行后此时会有一个交互的过程,要求输入 mysqlhostmysqlport此时先不要输入!!

sudo bash common.sh

新开一个终端,进入安装目录,此时该目录下会有一个 db.tar文件

cd /data/ones/pkg/ones-example-3.14.xxxxx
ll db.tar

解压db.tar ,解压之后会是单独数据库的 sql 文件,例如有 project.sql

mv db.tar /tmp
tar vxf db.tar

进入容器

./onesconfigure e

进入外置数据库并导入数据,<mysql_host> <mysql_password> <mysql_port> 请根据实际情况替换

sql 文件需要以 db.tar 解析出来的为准,实际可能会没有七个

mysql -uones -h<mysql_host> -p<mysql_password> -P<mysql_port>
source /tmp/project.sql;
source /tmp/wiki.sql;
source /tmp/wizeditor.sql;
source /tmp/superset.sql;
source /tmp/camunda.sql;
source /tmp/open_platform_plugin.sql;
source /tmp/plugin_platform.sql;

数据导入完成后,回到第一步的输入 mysqlhostmysqlport,输入完成后即可等待执行,过程有其他中断报错可以及时联系 ONES 工程师

验证

在完成外置数据库迁移后,还需要进行检查和数据测试

  1. 在最新的安装包目录下,执行 ./onesconfigure ss 查询看是否还存在 mysql 进程,如果没有则正常

    ./onesconfigure ss
  2. 在页面创建一个新的项目和任务,以英文命名,然后在数据库执行 select * from project.task where summary like '%英文名%',有信息则为正常

    ./onesconfigure mysql
    select * from project.task where summary like '%英文名%'