§ 麒麟Kylin系统中安装GreatSQL


§ 1. 准备工作

§ 1.1 配置yum源

开始编译之前,建议先配置好yum源,方便安装一些工具以及必要的依赖包。

这里采用系统安装后默认的YUM源,并生成缓存。

$ yum clean all && yum makecache
1

在开始安装前,请根据文档 安装准备 已经完成准备工作。

提醒:

个别Kylin系统中默认的umask是0077,需要修改一下,否则新建的文件、目录权限控制太严格,可能导致启动异常:

$ umask
0077

$ touch /tmp/tmpfile
$ ls -l /tmp/tmpfile
-rw------- 1 root root 0 Aug 29 16:48 /tmp/tmpfile

$ umask 0022
$ rm -f /tmp/tmpfile ; touch /tmp/tmpfile
$ ls -l /tmp/tmpfile
-rw-r--r-- 1 root root 0 Aug 29 16:49 /tmp/tmpfile
1
2
3
4
5
6
7
8
9
10
11

可以看到tmpfile文件两次不同的权限模式。

修改 /etc/bashrc 使之永久生效:

$ vim /etc/bashrc
...
umask 0022
1
2
3

保存退出。

§ 1.2 选择下载GreatSQL二进制包

一般而言,麒麟kylin系统环境下,也可以选择相应glibc版本的GreatSQL二进制安装包,基本上都能直接运行起来。

例如,本文使用的Kylin系统如下:

$ cat /etc/system-release
Kylin Linux Advanced Server release V10 (Tercel)

$ uname -a
Linux kylin 4.19.90-17.ky10.aarch64 #1 SMP Sun Jun 28 14:27:40 CST 2020 aarch64 aarch64 aarch64 GNU/Linux

$ ldd --version
ldd (GNU libc) 2.28
...
1
2
3
4
5
6
7
8
9

那么在这个环境下,可以选择 GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64.tar.xz 这个二进制包进行安装,甚至选择 GreatSQL-8.0.32-25-Linux-glibc2.28-aarch64.tar.xz 这个Linux Generic通用包一般也是可以的。

当然了,也可以选择相应的minimal包,minimal版本是对二进制文件进行strip后,所以文件尺寸较小,功能上没本质区别,但不支持gdb debug功能,可以放心使用。

将下载的二进制包放到安装目录下,并解压缩:

$ cd /usr/local
$ tar xf GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64.tar.xz
1
2

同时修改设置,将GreatSQL加入 PATH 环境变量:

$ echo 'export PATH=/usr/local/GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64/bin:$PATH' >> ~/.bash_profile
$ source ~/.bash_profile
1
2

接下来准备开始安装GreatSQL二进制包。

§ 2. 安装GreatSQL

§ 2.1 修改my.cnf

建议参考下面这份my.cnf模板,并根据实际情况做些适当调整:

my.cnf for GreatSQL 8.0.32-25 (opens new window)

[client]
socket    = /data/GreatSQL/mysql.sock
[mysql]
loose-skip-binary-as-hex
prompt = "(\\D)[\\u@GreatSQL][\\d]>"
no-auto-rehash
[mysqld]
user    = mysql
port    = 3306
server_id = 3306
basedir = /usr/local/GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64
datadir    = /data/GreatSQL
socket    = /data/GreatSQL/mysql.sock
pid-file = mysql.pid
character-set-server = UTF8MB4
skip_name_resolve = 1
#若你的MySQL数据库主要运行在境外,请务必根据实际情况调整本参数
default_time_zone = "+8:00"

#performance setttings
lock_wait_timeout = 3600
open_files_limit    = 65535
back_log = 1024
max_connections = 1024
max_connect_errors = 1000000
table_open_cache = 2048
table_definition_cache = 2048
thread_stack = 512K
sort_buffer_size = 4M
join_buffer_size = 4M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
thread_cache_size = 768
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 96M
max_heap_table_size = 96M
max_allowed_packet = 64M
net_buffer_shrink_interval = 180
#GIPK
loose-sql_generate_invisible_primary_key = ON

#log settings
log_timestamps = SYSTEM
log_error = /data/GreatSQL/error.log
log_error_verbosity = 3
slow_query_log = 1
log_slow_extra = 1
slow_query_log_file = /data/GreatSQL/slow.log
#设置slow log文件大小1G及总文件数10
max_slowlog_size = 1073741824
max_slowlog_files = 10
long_query_time = 0.01
log_queries_not_using_indexes = 1
log_throttle_queries_not_using_indexes = 60
min_examined_row_limit = 100
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_slow_verbosity = FULL
log_bin = /data/GreatSQL/binlog
binlog_format = ROW
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 6G
max_binlog_size = 1G
#控制binlog总大小,避免磁盘空间被撑爆
binlog_space_limit = 500G
binlog_rows_query_log_events = 1
binlog_expire_logs_seconds = 604800
binlog_checksum = CRC32
gtid_mode = ON
enforce_gtid_consistency = TRUE

#myisam settings
key_buffer_size = 32M
myisam_sort_buffer_size = 128M

#replication settings
relay_log_recovery = 1
slave_parallel_type = LOGICAL_CLOCK
#并行复制线程数可以设置为逻辑CPU数量的2倍
slave_parallel_workers = 64
binlog_transaction_dependency_tracking = WRITESET
slave_preserve_commit_order = 1
slave_checkpoint_period = 2

#启用InnoDB并行查询优化功能
loose-force_parallel_execute = OFF
#设置每个SQL语句的并行查询最大并发度
loose-parallel_default_dop = 8
#设置系统中总的并行查询线程数,可以和最大逻辑CPU数量一样
loose-parallel_max_threads = 64
#并行执行时leader线程和worker线程使用的总内存大小上限,可以设置物理内存的5-10%左右
loose-parallel_memory_limit = 12G

#parallel load data
loose-gdb_parallel_load_chunk_size = 4M

#mgr settings
loose-plugin_load_add = 'mysql_clone.so'
loose-plugin_load_add = 'group_replication.so'
loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"
#MGR本地节点IP:PORT,请自行替换
loose-group_replication_local_address = "172.16.16.10:33061"
#MGR集群所有节点IP:PORT,请自行替换
loose-group_replication_group_seeds = '172.16.16.10:33061,72.16.16.12:33061,72.16.16.12:33061'
loose-group_replication_start_on_boot = ON
loose-group_replication_bootstrap_group = OFF
loose-group_replication_exit_state_action = READ_ONLY
loose-group_replication_flow_control_mode = "DISABLED"
loose-group_replication_single_primary_mode = ON
loose-group_replication_majority_after_mode = ON
loose-group_replication_communication_max_message_size = 10M
loose-group_replication_arbitrator = 0
loose-group_replication_single_primary_fast_mode = 1
loose-group_replication_request_time_threshold = 100
loose-group_replication_primary_election_mode = GTID_FIRST
loose-group_replication_unreachable_majority_timeout = 0
loose-group_replication_member_expel_timeout = 5
loose-group_replication_autorejoin_tries = 288
report_host = "172.16.16.10"

#mgr vip
loose-plugin_load_add = 'greatdb_ha.so'
loose-greatdb_ha_enable_mgr_vip = 1

#innodb settings
innodb_buffer_pool_size = 16G
innodb_buffer_pool_instances = 8
innodb_data_file_path = ibdata1:12M:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 3
innodb_redo_log_capacity = 6G
innodb_doublewrite_files = 2
innodb_max_undo_log_size = 4G
# 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 10000 - 20000
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_open_files = 65534
#提醒:当需要用CLONE加密特性时,不要选用O_DIRECT模式,否则会比较慢
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_online_alter_log_max_size = 4G
innodb_print_ddl_logs = 0
innodb_status_file = 1
innodb_status_output = 0
innodb_status_output_locks = 1
innodb_sort_buffer_size = 64M
innodb_adaptive_hash_index = 0
#开启NUMA支持
innodb_numa_interleave = ON
innodb_print_lock_wait_timeout_info = 1
#自动杀掉超过5分钟不活跃事务,避免行锁被长时间持有
kill_idle_transaction = 300

#innodb monitor settings
#innodb_monitor_enable = "module_innodb,module_server,module_dml,module_ddl,module_trx,module_os,module_purge,module_log,module_lock,module_buffer,module_index,module_ibuf_system,module_buffer_page,module_adaptive_hash"

#pfs settings
performance_schema = 1
#performance_schema_instrument = '%memory%=on'
performance_schema_instrument = '%lock%=on'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

一般修改 basedir/datadir/innodb_buffer_pool_size 等几个选项就可以,修改完后保存退出。

§ 2.3 新建mysql用户

$ /sbin/groupadd mysql
$ /sbin/useradd -g mysql mysql -d /dev/null -s /sbin/nologin
1
2

§ 2.4 新建数据库主目录,并修改权限模式及属主

$ mkdir -p /data/GreatSQL 
$ chown -R mysql:mysql /data/GreatSQL
$ chmod -R 700 /data/GreatSQL
1
2
3

§ 2.5 配置GreatSQL systemd服务

推荐采用systemd来管理GreatSQL服务,可参考这份文件,或根据实际安装目录编辑文件:

$ vim /lib/systemd/system/greatsql.service

[Unit]
Description=GreatSQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]

# some limits
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=65535
# processes/threads
LimitNPROC=65535
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

User=mysql
Group=mysql
#如果是GreatSQL 5.7版本,此处需要改成simple模式,否则可能服务启用异常
#如果是GreatSQL 8.0版本则可以使用notify模式
#Type=simple
Type=notify
TimeoutSec=0
PermissionsStartOnly=true
ExecStartPre=/usr/local/GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64/bin/mysqld_pre_systemd
ExecStart=/usr/local/GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64/bin/mysqld $MYSQLD_OPTS
EnvironmentFile=-/etc/sysconfig/mysql
Restart=on-failure
RestartPreventExitStatus=1
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

务必确认文件中目录及文件名是否正确。

执行命令重载systemd,加入 greatsql 服务,如果没问题就不会报错:

$ systemctl daemon-reload
1

这就安装成功并将GreatSQL添加到系统服务中,后面可以用 systemctl 来管理GreatSQL服务。

§ 3. 启动GreatSQL

执行下面的命令启动GreatSQL服务

$ systemctl start greatsql
1

如果是在一个全新环境中首次启动GreatSQL数据库,可能会失败,因为在 mysqld_pre_systemd 的初始化处理逻辑中,需要依赖 /var/lib/mysql-files 目录保存一个临时文件。如果首次启动失败,可能会有类似下面的报错提示:

$ systemctl status greatsql

● greatsql.service - GreatSQL Server
   Loaded: loaded (/usr/lib/systemd/system/greatsql.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2023-08-30 10:02:03 CST; 1min 14s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1258165 ExecStart=/usr/local/GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64/bin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
  Process: 1257969 ExecStartPre=/usr/local/GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1258165 (code=exited, status=1/FAILURE)
   Status: "Server shutdown complete"

systemd[1]: Starting GreatSQL Server...
mysqld_pre_systemd[1257969]: mktemp: failed to create file via template ‘/var/lib/mysql-files/install-validate-password-plugin.XXXXXX.sql’: No such file or directory
mysqld_pre_systemd[1257969]: chmod: cannot access '': No such file or directory
mysqld_pre_systemd[1257969]: /usr/local/GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64/bin/mysqld_pre_systemd: line 43: : No such file or directory
mysqld_pre_systemd[1257969]: /usr/local/GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64/bin/mysqld_pre_systemd: line 44: $initfile: ambiguous redirect
systemd[1]: greatsql.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: greatsql.service: Failed with result 'exit-code'.
systemd[1]: Failed to start GreatSQL Server.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

只需手动创建 /var/lib/mysql-files 目录,再次启动GreatSQL服务即可:

$ mkdir -p /var/lib/mysql-files && chown -R mysql:mysql /var/lib/mysql-files
$ systemctl start greatsql
1
2

检查服务是否已启动,以及进程状态:

$ systemctl status greatsql
● greatsql.service - GreatSQL Server
   Loaded: loaded (/usr/lib/systemd/system/greatsql.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2023-08-30 10:08:06 CST; 6min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 60129 ExecStartPre=/usr/local/GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 60231 (mysqld)
   Status: "Server is operational"
    Tasks: 49 (limit: 149064)
   Memory: 5.6G
   CGroup: /system.slice/greatsql.service
           └─60231 /usr/local/GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64/bin/mysqld

Jul 12 10:07:58 db170 systemd[1]: Starting GreatSQL Server...
Jul 12 10:08:06 db170 systemd[1]: Started GreatSQL Server.

$ ps -ef | grep mysqld
mysql      60231       1  2 10:08 ?        00:00:10 /usr/local/GreatSQL-8.0.32-25-kylin-glibc2.28-aarch64/bin/mysqld

$ ss -lntp | grep mysqld
LISTEN 0      70                 *:33060            *:*    users:(("mysqld",pid=60231,fd=38))
LISTEN 0      128                *:3306             *:*    users:(("mysqld",pid=60231,fd=43))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

可以看到,GreatSQL服务已经正常启动了。

§ 4. 连接登入GreatSQL

在上面进行GreatSQL初始化时,会为 root@localhost 用户生成一个随机密码,记录在 error.log 日志文件中,例如下面这样:

$ grep -i root /data/GreatSQL/error.log
... A temporary password is generated for root@localhost: ji!pjndiw5sJ
1
2

复制该密码,将用于首次登入GreatSQL所需。

部分GreatSQL二进制包方式安装后,有可能初始化的root密码是空的,这种情况下可以直接登入并修改成安全密码。

$ mysql -uroot  -p"ji!pjndiw5sJ"   #<--这里输入刚才复制的临时密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.32-25 GreatSQL, Release 25, Revision db07cc5cb73
...
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
...
greatsql> \s
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
greatsql>

1
2
3
4
5
6
7
8
9
10
11

首次登入立刻提醒该密码已过期,需要修改,执行类似下面的命令修改即可:

greatsql> ALTER USER USER() IDENTIFIED BY 'GreatSQL@2022';  #<--修改密码
Query OK, 0 rows affected (0.02 sec)

greatsql> \s
...
mysql  Ver 8.0.32-25 for Linux on x86_64 (GreatSQL, Release 25, Revision db07cc5cb73)

Connection id:          8
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         8.0.32-25 GreatSQL, Release 25, Revision db07cc5cb73
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:            /data/GreatSQL/mysql.sock
Binary data as:         Hexadecimal
Uptime:                 20 min 8 sec

Threads: 2  Questions: 19  Slow queries: 0  Opens: 137  Flush tables: 3  Open tables: 53  Queries per second avg: 0.020
--------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

GreatSQL数据库安装并初始化完毕。

§ 5. 安装MySQL Shell

下载MySQL Shell for GreatSQL二进制包 greatsql-shell-8.0.25-16-Linux-glibc2.28-aarch64.tar.xz,在Kylin系统下也可以正常运行。

接下来安装MySQL Shell,以及进行MGR初始化等操作和用RPM包方式安装一样,这里就不赘述了。

参考文档RPM安装并构建MGR集群,从“8. 安装MySQL Shell”这节开始及往后内容即可。

在Kylin系统中,首次运行 mysqlsh 二进制文件时,可能会提示Python依赖错误:

$ /usr/local/greatsql-shell-8.0.25-16-Linux-glibc2.28-aarch64/bin/mysqlsh

./bin/mysqlsh: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
1
2
3

只需将系统中其他版本的Python依赖包头文件做个软链接就行:

$ ln -s /usr/lib64/libpython3.7m.so.1.0 /usr/lib64/libpython3.6m.so.1.0
$ /usr/local/greatsql-shell-8.0.25-16-Linux-glibc2.28-aarch64/bin/mysqlsh
MySQL Shell 8.0.25

Copyright (c) 2016, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
 MySQL  Py >
1
2
3
4
5
6
7
8
9
10

MySQL Shell就可以正常使用,并继续构建MGR集群了。

greatsql-wx