mysql 8.0.16 单主 mgr搭建
环境介绍:
192.168.142.142 db142
192.168.142.143 db143
192.168.142.145 db145
1、安装依赖包
yum -y install make gcc-c++ cmake bison-devel ncurses-devel readline-devel libaio-devel perl libaio wget lrzsz vim libnuma* bzip2 xz
2、关闭selinux
1sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 2setenforce 0 3 4/etc/init.d/iptables stop 5 6echo "/etc/init.d/iptables stop">>/etc/rc.local
3、修改系统限制参数
1cat >> /etc/security/limits.conf << EOF 2# 3###custom 4# 5* soft nofile 20480 6* hard nofile 65535 7* soft nproc 20480 8* hard nproc 65535 9EOF 10 11# 配置每台hosts主机解析 12 13cat >> /etc/hosts <<"EOF" 14 15192.168.142.142 db142 16192.168.142.143 db143 17192.168.142.145 db145 18EOF
4、修改内核参数
1cat >>/etc/sysctl.conf <<"EOF" 2vm.swappiness=0 3#增加tcp支持的队列数 4net.ipv4.tcp_max_syn_backlog = 65535 5#减少断开连接时 ,资源回收 6net.ipv4.tcp_max_tw_buckets = 8000 7net.ipv4.tcp_tw_reuse = 1 8net.ipv4.tcp_tw_recycle = 1 9net.ipv4.tcp_fin_timeout = 10 10#改变本地的端口范围 11net.ipv4.ip_local_port_range = 1024 65535 12#允许更多的连接进入队列 13net.ipv4.tcp_max_syn_backlog = 4096 14#对于只在本地使用的数据库服务器 15net.ipv4.tcp_fin_timeout = 30 16#端口监听队列 17net.core.somaxconn=65535 18#接受数据的速率 19net.core.netdev_max_backlog=65535 20net.core.wmem_default=87380 21net.core.wmem_max=16777216 22net.core.rmem_default=87380 23net.core.rmem_max=16777216 24EOF 25 26sysctl -p
5、社区版 8.0.16 下载
1cd /opt/ 2wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz 3# 解压安装包 4tar -xJf mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz 5# 进入目录,做软连接,方便以后升级 6cd /usr/local/ 7ln -s /opt/mysql-8.0.16-linux-glibc2.12-x86_64 mysql 8# 创建用户 9groupadd mysql 10useradd -g mysql mysql -d /home/mysql -s /sbin/nologin# 创建相应的目录mkdir -p /data/mysql/mysql_3306/{data,logs,tmp,undolog}
6、配置文件
# node1

1if [ -f /etc/my.cnf ]; then 2 mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%m`.bak 3fi 4# node1 5cat >/data/mysql/mysql_3306/my_3306.cnf <<"EOF" 6[client] 7port = 3306 8socket = /data/mysql/mysql_3306/tmp/mysql_3306.sock 9 10[mysql] 11prompt="\u@\h \R:\m:\s [\d]> " 12no-auto-rehash 13 14[mysqld] 15user = mysql 16port = 3306 17admin_address = 127.0.0.1 18basedir = /usr/local/mysql 19datadir = /data/mysql/mysql_3306/data 20socket = /data/mysql/mysql_3306/tmp/mysql_3306.sock 21pid-file = mysql_3306.pid 22character-set-server = utf8mb4 23skip_name_resolve = 1 24 25#replicate-wild-ignore-table=mysql.% 26replicate-wild-ignore-table=test.% 27replicate-wild-ignore-table=information_schema.% 28 29# Two-Master configure 30#server-1 31#auto-increment-offset = 1 32#auto-increment-increment = 2 33 34#server-2 35#auto-increment-offset = 2 36#auto-increment-increment = 2 37 38 39# semi sync replication settings # 40#plugin_dir = /usr/local/mysql/lib/mysql/plugin 41#plugin_load = "validate_password.so;rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" 42plugin_dir = /usr/local/mysql/lib/plugin #官方版本的路径 43plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" #官方版本的路径 44 45slave_parallel_workers = 4 46slave_parallel_type = LOGICAL_CLOCK 47slave_preserve_commit_order = 1 48 49open_files_limit = 65535 50back_log = 1024 51max_connections = 1024 52max_connect_errors = 1000000 53table_open_cache = 1024 54table_definition_cache = 1024 55table_open_cache_instances = 64 56thread_stack = 512K 57external-locking = FALSE 58max_allowed_packet = 32M 59sort_buffer_size = 4M 60join_buffer_size = 4M 61thread_cache_size = 1536 62interactive_timeout = 600 63wait_timeout = 600 64tmp_table_size = 32M 65max_heap_table_size = 32M 66slow_query_log = 1 67log_timestamps = SYSTEM 68slow_query_log_file = /data/mysql/mysql_3306/logs/slow.log 69log-error = /data/mysql/mysql_3306/logs/error.log 70long_query_time = 0.1 71log_queries_not_using_indexes =1 72log_throttle_queries_not_using_indexes = 60 73min_examined_row_limit = 100 74log_slow_admin_statements = 1 75log_slow_slave_statements = 1 76server-id = 1423306 77log-bin = /data/mysql/mysql_3306/logs/mysql-bin 78sync_binlog = 1 79binlog_cache_size = 4M 80max_binlog_cache_size = 2G 81max_binlog_size = 1G 82binlog_expire_logs_seconds=2592000 83master_info_repository = TABLE 84relay_log_info_repository = TABLE 85gtid_mode = on 86enforce_gtid_consistency = 1 87binlog_checksum=NONE 88log_slave_updates 89slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN' 90binlog_format = row 91binlog_row_image=FULL 92 93relay_log_recovery = 1 94relay-log-purge = 1 95key_buffer_size = 32M 96read_buffer_size = 8M 97read_rnd_buffer_size = 4M 98bulk_insert_buffer_size = 64M 99myisam_sort_buffer_size = 128M 100myisam_max_sort_file_size = 10G 101myisam_repair_threads = 1 102lock_wait_timeout = 3600 103explicit_defaults_for_timestamp = 1 104innodb_thread_concurrency = 0 105innodb_sync_spin_loops = 100 106innodb_spin_wait_delay = 30 107 108#transaction_isolation = REPEATABLE-READ 109transaction_isolation = READ-COMMITTED 110#innodb_additional_mem_pool_size = 16M 111innodb_buffer_pool_size = 2867M 112innodb_buffer_pool_instances = 4 113innodb_buffer_pool_load_at_startup = 1 114innodb_buffer_pool_dump_at_shutdown = 1 115innodb_data_file_path = ibdata1:1G:autoextend 116innodb_flush_log_at_trx_commit = 1 117innodb_log_buffer_size = 32M 118innodb_log_file_size = 2G 119innodb_log_files_in_group = 3 120innodb_max_undo_log_size = 4G 121innodb_undo_directory = /data/mysql/mysql_3306/undolog 122 123# 根据您的服务器IOPS能力适当调整 124# 一般配普通SSD盘的话,可以调整到 10000 - 20000 125# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000 126innodb_io_capacity = 4000 127innodb_io_capacity_max = 8000 128innodb_flush_sync = 0 129innodb_flush_neighbors = 0 130innodb_write_io_threads = 8 131innodb_read_io_threads = 8 132innodb_purge_threads = 4 133innodb_page_cleaners = 4 134innodb_open_files = 65535 135innodb_max_dirty_pages_pct = 50 136innodb_flush_method = O_DIRECT 137innodb_lru_scan_depth = 4000 138innodb_checksum_algorithm = crc32 139innodb_lock_wait_timeout = 10 140innodb_rollback_on_timeout = 1 141innodb_print_all_deadlocks = 1 142innodb_file_per_table = 1 143innodb_online_alter_log_max_size = 4G 144innodb_stats_on_metadata = 0 145 146# some var for MySQL 8 147log_error_verbosity = 3 148innodb_print_ddl_logs = 1 149binlog_expire_logs_seconds = 2592000 150#innodb_dedicated_server = 0 151 152innodb_status_file = 1 153# 注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log-error文件增长较快 154innodb_status_output = 0 155innodb_status_output_locks = 0 156 157#performance_schema 158performance_schema = 1 159performance_schema_instrument = '%memory%=on' 160performance_schema_instrument = '%lock%=on' 161 162#innodb monitor 163innodb_monitor_enable="module_innodb" 164innodb_monitor_enable="module_server" 165innodb_monitor_enable="module_dml" 166innodb_monitor_enable="module_ddl" 167innodb_monitor_enable="module_trx" 168innodb_monitor_enable="module_os" 169innodb_monitor_enable="module_purge" 170innodb_monitor_enable="module_log" 171innodb_monitor_enable="module_lock" 172innodb_monitor_enable="module_buffer" 173innodb_monitor_enable="module_index" 174innodb_monitor_enable="module_ibuf_system" 175innodb_monitor_enable="module_buffer_page" 176innodb_monitor_enable="module_adaptive_hash" 177 178#MGR 179#GR配置项 基中loose前缀表示若group Replication plugin未加载 mysql server仍明治维新启动 180transaction_write_set_extraction = XXHASH64 #对每个事务获取write set,并且用XXHASH64算法获取hash值 181loose-group_replication_group_name = "58f6e65e-9309-11e9-9d88-525400184a0a" #组名,此处可拿select uuid()生成 182loose-group_replication_start_on_boot = off #在mysqld启动时不自动启动组复制 183loose-group_replication_local_address = "192.168.142.142:33006" #本节点的IP地址和端口,注意该端口是组内成员之间通信的端口,而不是MySQL对外提供服务的端口 184loose-group_replication_group_seeds = "192.168.142.142:33006,192.168.142.143:33006,192.168.142.145:33006" #种子节点的IP和端口号,新成员加入到集群的时候需要联系种子节点,启动集群的节点不使用该选项 185loose-group_replication_bootstrap_group = off #关闭,如果打开会造成脑裂 #是否启动集群,注意,该选项任何时候只能用于一个节点,通常情况下启动集群的时候使用,启动之后需要关闭该选项 186 187loose-group_replication_member_weight = 50 #权重选择 188 189 190[mysqldump] 191quick 192max_allowed_packet = 32M 193 194[mysqld_safe] 195#malloc-lib=/usr/local/mysql/lib/jmalloc.so 196nice=-19 197open-files-limit=65535 198 199EOF
my.cnf
# node2

1# node2 2cat >/data/mysql/mysql_3306/my_3306.cnf <<"EOF" 3[client] 4port = 3306 5socket = /data/mysql/mysql_3306/tmp/mysql_3306.sock 6 7[mysql] 8prompt="\u@\h \R:\m:\s [\d]> " 9no-auto-rehash 10 11[mysqld] 12user = mysql 13port = 3306 14admin_address = 127.0.0.1 15basedir = /usr/local/mysql 16datadir = /data/mysql/mysql_3306/data 17socket = /data/mysql/mysql_3306/tmp/mysql_3306.sock 18pid-file = mysql_3306.pid 19character-set-server = utf8mb4 20skip_name_resolve = 1 21 22 23#replicate-wild-ignore-table=mysql.% 24replicate-wild-ignore-table=test.% 25replicate-wild-ignore-table=information_schema.% 26 27# Two-Master configure 28#server-1 29#auto-increment-offset = 1 30#auto-increment-increment = 2 31 32#server-2 33#auto-increment-offset = 2 34#auto-increment-increment = 2 35 36 37# semi sync replication settings # 38#plugin_dir = /usr/local/mysql/lib/mysql/plugin 39#plugin_load = "validate_password.so;rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" 40plugin_dir = /usr/local/mysql/lib/plugin #官方版本的路径 41plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" #官方版本的路径 42 43slave_parallel_workers = 4 44slave_parallel_type = LOGICAL_CLOCK 45slave_preserve_commit_order = 1 46 47open_files_limit = 65535 48back_log = 1024 49max_connections = 1024 50max_connect_errors = 1000000 51table_open_cache = 1024 52table_definition_cache = 1024 53table_open_cache_instances = 64 54thread_stack = 512K 55external-locking = FALSE 56max_allowed_packet = 32M 57sort_buffer_size = 4M 58join_buffer_size = 4M 59thread_cache_size = 1536 60interactive_timeout = 600 61wait_timeout = 600 62tmp_table_size = 32M 63max_heap_table_size = 32M 64slow_query_log = 1 65log_timestamps = SYSTEM 66slow_query_log_file = /data/mysql/mysql_3306/logs/slow.log 67log-error = /data/mysql/mysql_3306/logs/error.log 68long_query_time = 0.1 69log_queries_not_using_indexes =1 70log_throttle_queries_not_using_indexes = 60 71min_examined_row_limit = 100 72log_slow_admin_statements = 1 73log_slow_slave_statements = 1 74server-id = 1433306 75log-bin = /data/mysql/mysql_3306/logs/mysql-bin 76sync_binlog = 1 77binlog_cache_size = 4M 78max_binlog_cache_size = 2G 79max_binlog_size = 1G 80binlog_expire_logs_seconds=2592000 81master_info_repository = TABLE 82relay_log_info_repository = TABLE 83gtid_mode = on 84enforce_gtid_consistency = 1 85binlog_checksum=NONE 86log_slave_updates 87slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN' 88binlog_format = row 89binlog_row_image=FULL 90 91relay_log_recovery = 1 92relay-log-purge = 1 93key_buffer_size = 32M 94read_buffer_size = 8M 95read_rnd_buffer_size = 4M 96bulk_insert_buffer_size = 64M 97myisam_sort_buffer_size = 128M 98myisam_max_sort_file_size = 10G 99myisam_repair_threads = 1 100lock_wait_timeout = 3600 101explicit_defaults_for_timestamp = 1 102innodb_thread_concurrency = 0 103innodb_sync_spin_loops = 100 104innodb_spin_wait_delay = 30 105 106#transaction_isolation = REPEATABLE-READ 107transaction_isolation = READ-COMMITTED 108#innodb_additional_mem_pool_size = 16M 109innodb_buffer_pool_size = 2867M 110innodb_buffer_pool_instances = 4 111innodb_buffer_pool_load_at_startup = 1 112innodb_buffer_pool_dump_at_shutdown = 1 113innodb_data_file_path = ibdata1:1G:autoextend 114innodb_flush_log_at_trx_commit = 1 115innodb_log_buffer_size = 32M 116innodb_log_file_size = 2G 117innodb_log_files_in_group = 3 118innodb_max_undo_log_size = 4G 119innodb_undo_directory = /data/mysql/mysql_3306/undolog 120 121# 根据您的服务器IOPS能力适当调整 122# 一般配普通SSD盘的话,可以调整到 10000 - 20000 123# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000 124innodb_io_capacity = 4000 125innodb_io_capacity_max = 8000 126innodb_flush_sync = 0 127innodb_flush_neighbors = 0 128innodb_write_io_threads = 8 129innodb_read_io_threads = 8 130innodb_purge_threads = 4 131innodb_page_cleaners = 4 132innodb_open_files = 65535 133innodb_max_dirty_pages_pct = 50 134innodb_flush_method = O_DIRECT 135innodb_lru_scan_depth = 4000 136innodb_checksum_algorithm = crc32 137innodb_lock_wait_timeout = 10 138innodb_rollback_on_timeout = 1 139innodb_print_all_deadlocks = 1 140innodb_file_per_table = 1 141innodb_online_alter_log_max_size = 4G 142innodb_stats_on_metadata = 0 143 144# some var for MySQL 8 145log_error_verbosity = 3 146innodb_print_ddl_logs = 1 147binlog_expire_logs_seconds = 2592000 148#innodb_dedicated_server = 0 149 150innodb_status_file = 1 151# 注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log-error文件增长较快 152innodb_status_output = 0 153innodb_status_output_locks = 0 154 155#performance_schema 156performance_schema = 1 157performance_schema_instrument = '%memory%=on' 158performance_schema_instrument = '%lock%=on' 159 160#innodb monitor 161innodb_monitor_enable="module_innodb" 162innodb_monitor_enable="module_server" 163innodb_monitor_enable="module_dml" 164innodb_monitor_enable="module_ddl" 165innodb_monitor_enable="module_trx" 166innodb_monitor_enable="module_os" 167innodb_monitor_enable="module_purge" 168innodb_monitor_enable="module_log" 169innodb_monitor_enable="module_lock" 170innodb_monitor_enable="module_buffer" 171innodb_monitor_enable="module_index" 172innodb_monitor_enable="module_ibuf_system" 173innodb_monitor_enable="module_buffer_page" 174innodb_monitor_enable="module_adaptive_hash" 175 176#MGR 177#GR配置项 基中loose前缀表示若group Replication plugin未加载 mysql server仍明治维新启动 178transaction_write_set_extraction = XXHASH64 #对每个事务获取write set,并且用XXHASH64算法获取hash值 179loose-group_replication_group_name = "58f6e65e-9309-11e9-9d88-525400184a0a" #组名,此处可拿select uuid()生成 180loose-group_replication_start_on_boot = off #在mysqld启动时不自动启动组复制 181loose-group_replication_local_address = "192.168.142.143:33006" #本节点的IP地址和端口,注意该端口是组内成员之间通信的端口,而不是MySQL对外提供服务的端口 182loose-group_replication_group_seeds = "192.168.142.142:33006,192.168.142.143:33006,192.168.142.145:33006" #种子节点的IP和端口号,新成员加入到集群的时候需要联系种子节点,启动集群的节点不使用该选项 183loose-group_replication_bootstrap_group = off #关闭,如果打开会造成脑裂 #是否启动集群,注意,该选项任何时候只能用于一个节点,通常情况下启动集群的时候使用,启动之后需要关闭该选项 184 185loose-group_replication_member_weight = 50 #权重选择 186 187 188[mysqldump] 189quick 190max_allowed_packet = 32M 191 192[mysqld_safe] 193#malloc-lib=/usr/local/mysql/lib/jmalloc.so 194nice=-19 195open-files-limit=65535 196 197EOF
my.cnf
# node3

1# node3 2cat >/data/mysql/mysql_3306/my_3306.cnf <<"EOF" 3[client] 4port = 3306 5socket = /data/mysql/mysql_3306/tmp/mysql_3306.sock 6 7[mysql] 8prompt="\u@\h \R:\m:\s [\d]> " 9no-auto-rehash 10 11[mysqld] 12user = mysql 13port = 3306 14admin_address = 127.0.0.1 15basedir = /usr/local/mysql 16datadir = /data/mysql/mysql_3306/data 17socket = /data/mysql/mysql_3306/tmp/mysql_3306.sock 18pid-file = mysql_3306.pid 19character-set-server = utf8mb4 20skip_name_resolve = 1 21 22 23#replicate-wild-ignore-table=mysql.% 24replicate-wild-ignore-table=test.% 25replicate-wild-ignore-table=information_schema.% 26 27# Two-Master configure 28#server-1 29#auto-increment-offset = 1 30#auto-increment-increment = 2 31 32#server-2 33#auto-increment-offset = 2 34#auto-increment-increment = 2 35 36 37# semi sync replication settings # 38#plugin_dir = /usr/local/mysql/lib/mysql/plugin 39#plugin_load = "validate_password.so;rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" 40plugin_dir = /usr/local/mysql/lib/plugin #官方版本的路径 41plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" #官方版本的路径 42 43slave_parallel_workers = 4 44slave_parallel_type = LOGICAL_CLOCK 45slave_preserve_commit_order = 1 46open_files_limit = 65535 47back_log = 1024 48max_connections = 1024 49max_connect_errors = 1000000 50table_open_cache = 1024 51table_definition_cache = 1024 52table_open_cache_instances = 64 53thread_stack = 512K 54external-locking = FALSE 55max_allowed_packet = 32M 56sort_buffer_size = 4M 57join_buffer_size = 4M 58thread_cache_size = 1536 59interactive_timeout = 600 60wait_timeout = 600 61tmp_table_size = 32M 62max_heap_table_size = 32M 63slow_query_log = 1 64log_timestamps = SYSTEM 65slow_query_log_file = /data/mysql/mysql_3306/logs/slow.log 66log-error = /data/mysql/mysql_3306/logs/error.log 67long_query_time = 0.1 68log_queries_not_using_indexes =1 69log_throttle_queries_not_using_indexes = 60 70min_examined_row_limit = 100 71log_slow_admin_statements = 1 72log_slow_slave_statements = 1 73server-id = 1453306 74log-bin = /data/mysql/mysql_3306/logs/mysql-bin 75sync_binlog = 1 76binlog_cache_size = 4M 77max_binlog_cache_size = 2G 78max_binlog_size = 1G 79binlog_expire_logs_seconds=2592000 80master_info_repository = TABLE 81relay_log_info_repository = TABLE 82gtid_mode = on 83enforce_gtid_consistency = 1 84binlog_checksum=NONE 85log_slave_updates 86slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN' 87binlog_format = row 88binlog_row_image=FULL 89 90relay_log_recovery = 1 91relay-log-purge = 1 92key_buffer_size = 32M 93read_buffer_size = 8M 94read_rnd_buffer_size = 4M 95bulk_insert_buffer_size = 64M 96myisam_sort_buffer_size = 128M 97myisam_max_sort_file_size = 10G 98myisam_repair_threads = 1 99lock_wait_timeout = 3600 100explicit_defaults_for_timestamp = 1 101innodb_thread_concurrency = 0 102innodb_sync_spin_loops = 100 103innodb_spin_wait_delay = 30 104 105#transaction_isolation = REPEATABLE-READ 106transaction_isolation = READ-COMMITTED 107#innodb_additional_mem_pool_size = 16M 108innodb_buffer_pool_size = 2867M 109innodb_buffer_pool_instances = 4 110innodb_buffer_pool_load_at_startup = 1 111innodb_buffer_pool_dump_at_shutdown = 1 112innodb_data_file_path = ibdata1:1G:autoextend 113innodb_flush_log_at_trx_commit = 1 114innodb_log_buffer_size = 32M 115innodb_log_file_size = 2G 116innodb_log_files_in_group = 3 117innodb_max_undo_log_size = 4G 118innodb_undo_directory = /data/mysql/mysql_3306/undolog 119 120# 根据您的服务器IOPS能力适当调整 121# 一般配普通SSD盘的话,可以调整到 10000 - 20000 122# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000 123innodb_io_capacity = 4000 124innodb_io_capacity_max = 8000 125innodb_flush_sync = 0 126innodb_flush_neighbors = 0 127innodb_write_io_threads = 8 128innodb_read_io_threads = 8 129innodb_purge_threads = 4 130innodb_page_cleaners = 4 131innodb_open_files = 65535 132innodb_max_dirty_pages_pct = 50 133innodb_flush_method = O_DIRECT 134innodb_lru_scan_depth = 4000 135innodb_checksum_algorithm = crc32 136innodb_lock_wait_timeout = 10 137innodb_rollback_on_timeout = 1 138innodb_print_all_deadlocks = 1 139innodb_file_per_table = 1 140innodb_online_alter_log_max_size = 4G 141innodb_stats_on_metadata = 0 142 143# some var for MySQL 8 144log_error_verbosity = 3 145innodb_print_ddl_logs = 1 146binlog_expire_logs_seconds = 2592000 147#innodb_dedicated_server = 0 148 149innodb_status_file = 1 150# 注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log-error文件增长较快 151innodb_status_output = 0 152innodb_status_output_locks = 0 153 154#performance_schema 155performance_schema = 1 156performance_schema_instrument = '%memory%=on' 157performance_schema_instrument = '%lock%=on' 158 159#innodb monitor 160innodb_monitor_enable="module_innodb" 161innodb_monitor_enable="module_server" 162innodb_monitor_enable="module_dml" 163innodb_monitor_enable="module_ddl" 164innodb_monitor_enable="module_trx" 165innodb_monitor_enable="module_os" 166innodb_monitor_enable="module_purge" 167innodb_monitor_enable="module_log" 168innodb_monitor_enable="module_lock" 169innodb_monitor_enable="module_buffer" 170innodb_monitor_enable="module_index" 171innodb_monitor_enable="module_ibuf_system" 172innodb_monitor_enable="module_buffer_page" 173innodb_monitor_enable="module_adaptive_hash" 174 175#MGR 176#GR配置项 基中loose前缀表示若group Replication plugin未加载 mysql server仍明治维新启动 177transaction_write_set_extraction = XXHASH64 #对每个事务获取write set,并且用XXHASH64算法获取hash值 178loose-group_replication_group_name = "58f6e65e-9309-11e9-9d88-525400184a0a" #组名,此处可拿select uuid()生成 179loose-group_replication_start_on_boot = off #在mysqld启动时不自动启动组复制 180loose-group_replication_local_address = "192.168.142.145:33006" #本节点的IP地址和端口,注意该端口是组内成员之间通信的端口,而不是MySQL对外提供服务的端口 181loose-group_replication_group_seeds = "192.168.142.142:33006,192.168.142.143:33006,192.168.142.145:33006" #种子节点的IP和端口号,新成员加入到集群的时候需要联系种子节点,启动集群的节点不使用该选项 182loose-group_replication_bootstrap_group = off #关闭,如果打开会造成脑裂 #是否启动集群,注意,该选项任何时候只能用于一个节点,通常情况下启动集群的时候使用,启动之后需要关闭该选项 183 184loose-group_replication_member_weight = 50 #权重选择 185 186 187[mysqldump] 188quick 189max_allowed_packet = 32M 190 191[mysqld_safe] 192#malloc-lib=/usr/local/mysql/lib/jmalloc.so 193nice=-19 194open-files-limit=65535 195 196EOF
my.cnf
7、修改目录权限
1chown -R mysql.mysql /data/mysql/mysql_3306 2chown -R mysql.mysql /usr/local/mysql/
8、初始化数据库
1# /usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql --initialize-insecure 2# 官方推荐使用--initialize,会在错误日志中生成难以输入的临时密码,我这里使用的免密码的方式。 3/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3306/my_3306.cnf --initialize-insecure --user=mysql &
9、查看日志
# tail -f /data/mysql/mysql_3306/logs/error.log
# 10、启动数据库
1/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3306/my_3306.cnf & 2 3ln -s /usr/local/mysql/bin/* /usr/bin/ 4ln -s /usr/local/mysql/lib/* /usr/lib64/ 5ln -s /data/mysql/mysql_3306/tmp/mysql_3306.sock /tmp/mysql.sock
11、配置mgr第一个主节点 192.168.142.142
1# 第一步:创建用于复制的用户 2 3set sql_log_bin=0; 4create user 'repuser'@'%' identified by 'JhXpMK44ju8Vp5bxvO2N'; 5 6grant replication slave,replication client on *.* to 'repuser'@'%'; 7 8create user 'repuser'@'127.0.0.1' identified by 'JhXpMK44ju8Vp5bxvO2N'; 9 10grant replication slave,replication client on *.* to 'repuser'@'127.0.0.1'; 11 12create user 'repuser'@'localhost' identified by 'JhXpMK44ju8Vp5bxvO2N'; 13 14grant replication slave,replication client on *.* to 'repuser'@'localhost'; 15 16set sql_log_bin=1; 17 18# 第二步:配置复制所使用的用户 19 20change master to master_user='repuser',master_password='JhXpMK44ju8Vp5bxvO2N' for channel 'group_replication_recovery'; 21 22# 第三步:安装mysql group replication这个插件 23 24 25# 备注:如果在my.cnf里写写入 plugin_load="group_replication=group_replication.so" 这步就可以不用操作 26 27install plugin group_replication soname 'group_replication.so'; 28 29# 通过show plugins;查看是否安装成功 30show plugins; 31 32# 第四步:建个群(官方点的说法就是初始化一个复制组 33 34set global group_replication_bootstrap_group=on; 35start group_replication; 36set global group_replication_bootstrap_group=off; 37 38select * from performance_schema.replication_group_members;
12、配置另外两节点,在所有从主机上的mysql中执行
1# 第一步:创建用于复制的用户 2 3set sql_log_bin=0; 4create user 'repuser'@'%' identified by 'JhXpMK44ju8Vp5bxvO2N'; 5 6grant replication slave,replication client on *.* to 'repuser'@'%'; 7 8create user 'repuser'@'127.0.0.1' identified by 'JhXpMK44ju8Vp5bxvO2N'; 9 10grant replication slave,replication client on *.* to 'repuser'@'127.0.0.1'; 11 12create user 'repuser'@'localhost' identified by 'JhXpMK44ju8Vp5bxvO2N'; 13 14grant replication slave,replication client on *.* to 'repuser'@'localhost'; 15 16set sql_log_bin=1; 17 18# 第二步:配置复制所使用的用户 19 20change master to master_user='repuser',master_password='JhXpMK44ju8Vp5bxvO2N' for channel 'group_replication_recovery'; 21 22# 第三步:安装mysql group replication这个插件 23 24 25# 备注:如果在my.cnf里写写入 plugin_load="group_replication=group_replication.so" 这步就可以不用操作 26 27install plugin group_replication soname 'group_replication.so'; 28 29# 通过show plugins;查看是否安装成功 30show plugins; 31 32# 第四步:加入前面创建好的复制组 33 34start group_replication; 35select * from performance_schema.replication_group_members; 36 37# 13、查看mgr状态 38mysql> select * from performance_schema.replication_group_members; 39+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+ 40| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | 41+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+ 42| group_replication_applier | 81887515-6ded-11e9-a307-000c29508dcb | db143 | 3306 | ONLINE | SECONDARY | 8.0.16 | 43| group_replication_applier | 8f953e27-8c25-11e9-a39e-000c29c2e60a | db142 | 3306 | ONLINE | PRIMARY | 8.0.16 | 44| group_replication_applier | b2f0bfdc-87db-11e9-b83d-000c298bc91b | db145 | 3306 | ONLINE | SECONDARY | 8.0.16 | 45+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+ 463 rows in set (0.00 sec)
14、创建测试数据
1create database test; 2use test; 3create table test(id int primary key,name varchar(10)); 4insert into test values(1,'jacky');
15、常见故障
1############################### 常见故障 ############################### 2 3mysql> START GROUP_REPLICATION; 4 5ERROR 3092 (HY000): The server is notconfigured properly to be an active member of the group. Please see moredetails on error log. 6 7【解决办法】: 8 9mysql> SET GLOBALgroup_replication_bootstrap_group = ON; 10 11Query OK, 0 rows affected (0.00 sec) 12 13 14mysql> START GROUP_REPLICATION; 15 16Query OK, 0 rows affected (1.03 sec)
16、使用组复制的基础要求
11、必须使用innodb引擎,冲突时要回滚,使用其他引擎可能会数据不一致。 22、每个表都要求显示定义主键,用于冲突检测识别。 33、开启GTID,通过GTID来追踪各事务在各机器上的情况 。 44、binlog使用row模式,确保各机器数据的一致性。 55、使用READ COMMITTED的隔离级别来规避Gap Locks。