二进制包安装并构建MGR集群


本文档主要介绍如何用二进制包方式安装GreatSQL数据库,假定本次安装是在CentOS 8.x x86_64环境中安装,并且是以root用户身份执行安装操作。

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

1. MGR集群规划

本次计划在3台服务器上安装GreatSQL数据库并部署MGR集群:

nodeipdatadirportrole
GreatSQL-01172.16.16.10/data/GreatSQL/3306PRIMARY
GreatSQL-02172.16.16.11/data/GreatSQL/3306SECONDARY
GreatSQL-03172.16.16.12/data/GreatSQL/3306ARBITRATOR

以下安装配置工作先在三个节点都同样操作一遍。

2. 下载安装包

点击此处二进制包安装并构建MGR集群 - 图1 (opens new window)下载最新的安装包,下载以下几个就可以:

  • GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64.tar.xz

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

  1. $ cd /usr/local
  2. $ curl -o GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64.tar.xz https://product.greatdb.com/GreatSQL-8.0.25-16/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64.tar.xz
  3. $ tar xf GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64.tar.xz

3. 启动前准备

3.1 修改 /etc/my.cnf 配置文件

参考这份文件二进制包安装并构建MGR集群 - 图2 (opens new window),可根据实际情况修改,一般主要涉及数据库文件分区、目录,内存配置等少数几个选项。以下面这份为例:

  1. #my.cnf
  2. [client]
  3. user = root
  4. datadir = /data/GreatSQL/mysql.sock
  5. [mysqld]
  6. user = mysql
  7. port = 3306
  8. #主从复制或MGR集群中,server_id记得要不同
  9. #另外,实例启动时会生成 auto.cnf,里面的 server_uuid 值也要不同
  10. #server_uuid的值还可以自己手动指定,只要符合uuid的格式标准就可以
  11. server_id = 3306
  12. basedir = /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64
  13. datadir = /data/GreatSQL
  14. socket = mysql.sock
  15. pid-file = mysql.pid
  16. character-set-server = UTF8MB4
  17. skip_name_resolve = 1
  18. #若你的MySQL数据库主要运行在境外,请务必根据实际情况调整本参数
  19. default_time_zone = "+8:00"
  20. #performance setttings
  21. lock_wait_timeout = 3600
  22. open_files_limit = 65535
  23. back_log = 1024
  24. max_connections = 512
  25. max_connect_errors = 1000000
  26. table_open_cache = 1024
  27. table_definition_cache = 1024
  28. thread_stack = 512K
  29. sort_buffer_size = 4M
  30. join_buffer_size = 4M
  31. read_buffer_size = 8M
  32. read_rnd_buffer_size = 4M
  33. bulk_insert_buffer_size = 64M
  34. thread_cache_size = 768
  35. interactive_timeout = 600
  36. wait_timeout = 600
  37. tmp_table_size = 32M
  38. max_heap_table_size = 32M
  39. #log settings
  40. log_timestamps = SYSTEM
  41. log_error = error.log
  42. log_error_verbosity = 3
  43. slow_query_log = 1
  44. log_slow_extra = 1
  45. slow_query_log_file = slow.log
  46. long_query_time = 0.1
  47. log_queries_not_using_indexes = 1
  48. log_throttle_queries_not_using_indexes = 60
  49. min_examined_row_limit = 100
  50. log_slow_admin_statements = 1
  51. log_slow_slave_statements = 1
  52. log_bin = binlog
  53. binlog_format = ROW
  54. sync_binlog = 1
  55. binlog_cache_size = 4M
  56. max_binlog_cache_size = 2G
  57. max_binlog_size = 1G
  58. binlog_rows_query_log_events = 1
  59. binlog_expire_logs_seconds = 604800
  60. #MySQL 8.0.22前,想启用MGR的话,需要设置binlog_checksum=NONE才行
  61. binlog_checksum = CRC32
  62. gtid_mode = ON
  63. enforce_gtid_consistency = TRUE
  64. #myisam settings
  65. key_buffer_size = 32M
  66. myisam_sort_buffer_size = 128M
  67. #replication settings
  68. relay_log_recovery = 1
  69. slave_parallel_type = LOGICAL_CLOCK
  70. #可以设置为逻辑CPU数量的2倍
  71. slave_parallel_workers = 64
  72. binlog_transaction_dependency_tracking = WRITESET
  73. slave_preserve_commit_order = 1
  74. slave_checkpoint_period = 2
  75. #mgr settings
  76. loose-plugin_load_add = 'mysql_clone.so'
  77. loose-plugin_load_add = 'group_replication.so'
  78. loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"
  79. #MGR本地节点IP:PORT,请自行替换
  80. loose-group_replication_local_address = "172.16.16.10:33061"
  81. #MGR集群所有节点IP:PORT,请自行替换
  82. loose-group_replication_group_seeds = "172.16.16.10:33061,172.16.16.11:33061,172.16.16.12:33061"
  83. loose-group_replication_start_on_boot = OFF
  84. loose-group_replication_bootstrap_group = OFF
  85. loose-group_replication_exit_state_action = READ_ONLY
  86. loose-group_replication_flow_control_mode = "DISABLED"
  87. loose-group_replication_single_primary_mode = ON
  88. loose-group_replication_majority_after_mode = ON
  89. loose-group_replication_communication_max_message_size = 10M
  90. loose-group_replication_arbitrator = 0
  91. loose-group_replication_single_primary_fast_mode = 1
  92. loose-group_replication_request_time_threshold = 100
  93. loose-group_replication_primary_election_mode = GTID_FIRST
  94. loose-group_replication_unreachable_majority_timeout = 30
  95. loose-group_replication_member_expel_timeout = 5
  96. loose-group_replication_autorejoin_tries = 288
  97. report_host = "172.16.16.10"
  98. #innodb settings
  99. innodb_buffer_pool_size = 64G
  100. innodb_buffer_pool_instances = 8
  101. innodb_data_file_path = ibdata1:12M:autoextend
  102. innodb_flush_log_at_trx_commit = 1
  103. innodb_log_buffer_size = 32M
  104. innodb_log_file_size = 2G
  105. innodb_log_files_in_group = 3
  106. innodb_max_undo_log_size = 4G
  107. # 根据您的服务器IOPS能力适当调整
  108. # 一般配普通SSD盘的话,可以调整到 10000 - 20000
  109. # 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
  110. innodb_io_capacity = 4000
  111. innodb_io_capacity_max = 8000
  112. innodb_open_files = 65535
  113. innodb_flush_method = O_DIRECT
  114. innodb_lru_scan_depth = 4000
  115. innodb_lock_wait_timeout = 10
  116. innodb_rollback_on_timeout = 1
  117. innodb_print_all_deadlocks = 1
  118. innodb_online_alter_log_max_size = 4G
  119. innodb_print_ddl_logs = 1
  120. innodb_status_file = 1
  121. #注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log_error文件增长较快
  122. innodb_status_output = 0
  123. innodb_status_output_locks = 1
  124. innodb_sort_buffer_size = 67108864
  125. #innodb monitor settings
  126. innodb_monitor_enable = "module_innodb"
  127. innodb_monitor_enable = "module_server"
  128. innodb_monitor_enable = "module_dml"
  129. innodb_monitor_enable = "module_ddl"
  130. innodb_monitor_enable = "module_trx"
  131. innodb_monitor_enable = "module_os"
  132. innodb_monitor_enable = "module_purge"
  133. innodb_monitor_enable = "module_log"
  134. innodb_monitor_enable = "module_lock"
  135. innodb_monitor_enable = "module_buffer"
  136. innodb_monitor_enable = "module_index"
  137. innodb_monitor_enable = "module_ibuf_system"
  138. innodb_monitor_enable = "module_buffer_page"
  139. innodb_monitor_enable = "module_adaptive_hash"
  140. #innodb parallel query
  141. force_parallel_execute = OFF
  142. parallel_default_dop = 8
  143. parallel_max_threads = 96
  144. temptable_max_ram = 8G
  145. #pfs settings
  146. performance_schema = 1
  147. #performance_schema_instrument = '%memory%=on'
  148. performance_schema_instrument = '%lock%=on'

3.2 新建mysql用户

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

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

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

3.4 增加GreatSQL系统服务

  1. $ vim /lib/systemd/system/greatsql.service
  2. [Unit]
  3. Description=GreatSQL Server
  4. Documentation=man:mysqld(8)
  5. Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
  6. After=network.target
  7. After=syslog.target
  8. [Install]
  9. WantedBy=multi-user.target
  10. [Service]
  11. # some limits
  12. # file size
  13. LimitFSIZE=infinity
  14. # cpu time
  15. LimitCPU=infinity
  16. # virtual memory size
  17. LimitAS=infinity
  18. # open files
  19. LimitNOFILE=65535
  20. # processes/threads
  21. LimitNPROC=65535
  22. # locked memory
  23. LimitMEMLOCK=infinity
  24. # total threads (user+kernel)
  25. TasksMax=infinity
  26. TasksAccounting=false
  27. User=mysql
  28. Group=mysql
  29. Type=simple
  30. TimeoutSec=0
  31. PermissionsStartOnly=true
  32. ExecStartPre=/usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/bin/mysqld_pre_systemd
  33. ExecStart=/usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/bin/mysqld $MYSQLD_OPTS
  34. EnvironmentFile=-/etc/sysconfig/mysql
  35. LimitNOFILE = 10000
  36. Restart=on-failure
  37. RestartPreventExitStatus=1
  38. Environment=MYSQLD_PARENT_PID=1
  39. PrivateTmp=false

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

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

  1. $ systemctl daemon-reload

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

3.5 下载mysqld_pre_systemd文件

GreatSQL二进制包中没有自带 mysqld_pre_systemd 脚本文件,需要自行下载。

点击本链接二进制包安装并构建MGR集群 - 图3 (opens new window) 复制脚本内容,并保存成文件 /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/bin/mysqld_pre_systemd,确认第25行附近 MYSQL_BASEDIR 所指的路径是否正确:

  1. MYSQL_BASEDIR = /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64

之后修改文件属性,加上可执行权限:

  1. $ chmod ug+x /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/bin/mysqld_pre_systemd

4. 启动GreatSQL

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

  1. $ systemctl start greatsql

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

  1. $ systemctl status greatsql
  2. greatsql.service - GreatSQL Server
  3. Loaded: loaded (/usr/lib/systemd/system/greatsql.service; disabled; vendor preset: disabled)
  4. Active: active (running) since Tue 2022-07-12 10:08:06 CST; 6min ago
  5. Docs: man:mysqld(8)
  6. http://dev.mysql.com/doc/refman/en/using-systemd.html
  7. Process: 60129 ExecStartPre=/usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
  8. Main PID: 60231 (mysqld)
  9. Status: "Server is operational"
  10. Tasks: 49 (limit: 149064)
  11. Memory: 5.6G
  12. CGroup: /system.slice/greatsql.service
  13. └─60231 /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/bin/mysqld
  14. Jul 12 10:07:58 db170 systemd[1]: Starting GreatSQL Server...
  15. Jul 12 10:08:06 db170 systemd[1]: Started GreatSQL Server.
  16. $ ps -ef | grep mysqld
  17. mysql 60231 1 2 10:08 ? 00:00:10 /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/bin/mysqld
  18. $ ss -lntp | grep mysqld
  19. LISTEN 0 70 *:33060 *:* users:(("mysqld",pid=60231,fd=38))
  20. LISTEN 0 128 *:3306 *:* users:(("mysqld",pid=60231,fd=43))
  21. # 查看数据库文件
  22. $ ls /data/GreatSQL
  23. auto.cnf client-key.pem '#ib_16384_14.dblwr' '#ib_16384_6.dblwr' ib_logfile1 mysql.pid server-key.pem
  24. binlog.000001 error.log '#ib_16384_15.dblwr' '#ib_16384_7.dblwr' ib_logfile2 mysql.sock slow.log
  25. binlog.000002 '#ib_16384_0.dblwr' '#ib_16384_1.dblwr' '#ib_16384_8.dblwr' ibtmp1 mysql.sock.lock sys
  26. binlog.index '#ib_16384_10.dblwr' '#ib_16384_2.dblwr' '#ib_16384_9.dblwr' innodb_status.60231 performance_schema undo_001
  27. ca-key.pem '#ib_16384_11.dblwr' '#ib_16384_3.dblwr' ib_buffer_pool '#innodb_temp' private_key.pem undo_002
  28. ca.pem '#ib_16384_12.dblwr' '#ib_16384_4.dblwr' ibdata1 mysql public_key.pem
  29. client-cert.pem '#ib_16384_13.dblwr' '#ib_16384_5.dblwr' ib_logfile0 mysql.ibd server-cert.pem

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

5. 连接登入GreatSQL

二进制包方式安装GreatSQL后,初始化的root密码是空的,可以直接登入并修改成安全密码:

  1. $ mysql -uroot
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 11
  4. Server version: 8.0.25-16 GreatSQL, Release 16, Revision 8bb0e5af297
  5. ...
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7. mysql> alter user user() identified by 'GreatSQL@2022'; #<--修改密码
  8. Query OK, 0 rows affected (0.02 sec)
  9. mysql> \s
  10. --------------
  11. mysql Ver 8.0.25-16 for Linux on x86_64 (GreatSQL (GPL), Release 16, Revision 8bb0e5af297)
  12. Connection id: 8
  13. Current database:
  14. Current user: root@localhost
  15. SSL: Not in use
  16. Current pager: stdout
  17. Using outfile: ''
  18. Using delimiter: ;
  19. Server version: 8.0.25-16
  20. Protocol version: 10
  21. Connection: Localhost via UNIX socket
  22. Server characterset: utf8mb4
  23. Db characterset: utf8mb4
  24. Client characterset: utf8mb4
  25. Conn. characterset: utf8mb4
  26. UNIX socket: /data/GreatSQL/mysql.sock
  27. Binary data as: Hexadecimal
  28. Uptime: 20 min 8 sec
  29. Threads: 2 Questions: 19 Slow queries: 0 Opens: 137 Flush tables: 3 Open tables: 53 Queries per second avg: 0.020
  30. --------------

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

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

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

问题反馈

联系我们

扫码关注微信公众号

输入图片说明