主从配置详细过程:

环境准备:
配置好服务器,主从服务器都安装并启动mysql数据库 # 添加读写账号和只读账号,应用配置中,写主库用读写账号,统计从库数据yoga只读账号
grant select,insert,update,delete on f_crack_check.* to f_crack_check_user@"%" identified by "pass";
grant select on f_crack_check.* to f_crack_check_read@"%" identified by "pass";
flush privileges; 注意:当配置好主从后,添加账号,或者任何写库的操作都需要在主库中操作,否则可能引起主从不一致 # 为了方便后面切换服务器方便,内网使用域名的方式进行数据库链接 主库连接地址:172.30.0.51 f_crack_check.master.prod.mysql
从库连接地址:172.30.0.52 f_crack_check.slave01.prod.mysql 主从数据库服务器均安装xtrabackup工具
wget http://repo.percona.com/tools/yum/release/7/RPMS/x86_64/percona-xtrabackup-24-2.4.12-1.el7.x86_64.rpm yum localinstall percona-xtrabackup--2.4.-.el7.x86_64.rpm -y .主库中备份,将mysql数据库整个备份到/opt/目录下
# innobackupex --defaults-file="/etc/my.cnf" --user=root -p'pass' --socket=/tmp/mysql.sock /opt
xtrabackup: recognized server arguments: --datadir=/data/mysql_data --tmpdir=/tmp --open_files_limit= --log_bin=mysql-bin --server-id= --innodb_data_home_dir=/data/mysql_data --innodb_data_file_path=ibdata1:1G;ibdata2:1G:autoextend --innodb_log_group_home_dir=/data/mysql_data --innodb_undo_directory=/data/mysql_data/undolog/ --innodb_undo_tablespaces= --innodb_buffer_pool_size=3G --innodb_log_file_size=256M --innodb_log_buffer_size=64M --innodb_log_files_in_group= --innodb_flush_log_at_trx_commit= --innodb_file_per_table= --innodb_read_io_threads= --innodb_write_io_threads= --innodb_max_dirty_pages_pct= --innodb_flush_method=O_DIRECT --innodb_autoextend_increment=
xtrabackup: recognized client arguments: --datadir=/data/mysql_data --tmpdir=/tmp --open_files_limit= --log_bin=mysql-bin --server-id= --innodb_data_home_dir=/data/mysql_data --innodb_data_file_path=ibdata1:1G;ibdata2:1G:autoextend --innodb_log_group_home_dir=/data/mysql_data --innodb_undo_directory=/data/mysql_data/undolog/ --innodb_undo_tablespaces= --innodb_buffer_pool_size=3G --innodb_log_file_size=256M --innodb_log_buffer_size=64M --innodb_log_files_in_group= --innodb_flush_log_at_trx_commit= --innodb_file_per_table= --innodb_read_io_threads= --innodb_write_io_threads= --innodb_max_dirty_pages_pct= --innodb_flush_method=O_DIRECT --innodb_autoextend_increment=
:: innobackupex: Starting the backup operation IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!". :: version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;port=3306;mysql_socket=/tmp/mysql.sock' as 'root' (using password: YES).
Failed to connect to MySQL server as DBD::mysql module is not installed at - line .
:: Connecting to MySQL server host: localhost, user: root, password: set, port: , socket: /tmp/mysql.sock
Using server version 5.7.--log
innobackupex version 2.4. based on MySQL server 5.7. Linux (x86_64) (revision id: 170eb8c)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /data/mysql_data
xtrabackup: open files limit requested , set to
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = /data/mysql_data
xtrabackup: innodb_data_file_path = ibdata1:1G;ibdata2:1G:autoextend
xtrabackup: innodb_log_group_home_dir = /data/mysql_data
xtrabackup: innodb_log_files_in_group =
xtrabackup: innodb_log_file_size =
xtrabackup: using O_DIRECT
InnoDB: Number of pools:
:: >> log scanned up to ()
InnoDB: Opened undo tablespaces
InnoDB: undo tablespaces made active
xtrabackup: Generating a list of tablespaces
InnoDB: Allocated tablespace ID for mysql/server_cost, old maximum was
:: [] Copying /data/mysql_data/ibdata1 to /opt/--09_19--/ibdata1
:: >> log scanned up to () ...
:: Finished backing up non-InnoDB tables and files
:: Executing LOCK BINLOG FOR BACKUP...
:: [] Writing /opt/--09_19--/xtrabackup_binlog_info
:: [] ...done
:: Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
xtrabackup: The latest check point (for incremental): ''
xtrabackup: Stopping log copying thread.
. :: >> log scanned up to () :: Executing UNLOCK BINLOG
:: Executing UNLOCK TABLES
:: All tables unlocked
:: [] Copying ib_buffer_pool to /opt/--09_19--/ib_buffer_pool
:: [] ...done
:: Backup created in directory '/opt/2019-08-09_19-38-37/'
MySQL binlog position: filename 'mysql-bin.000004', position ''
:: [] Writing /opt/--09_19--/backup-my.cnf
:: [] ...done
:: [] Writing /opt/--09_19--/xtrabackup_info
:: [] ...done
xtrabackup: Transaction log of lsn () to () was copied.
:: completed OK! .预处理,进行事物检查(最好直接在主库中备份完成后检查)
# innobackupex --defaults-file="/etc/my.cnf" --user=root -p'pass' --socket=/tmp/mysql.sock --apply-log --use-memory=2G /opt/--09_19--/
xtrabackup: recognized server arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksum_algorithm=strict_crc32 --innodb_data_file_path=ibdata1:1G;ibdata2:1G:autoextend --innodb_log_files_in_group= --innodb_log_file_size= --innodb_fast_checksum= --innodb_page_size= --innodb_log_block_size= --innodb_undo_directory=/data/mysql_data/undolog/ --innodb_undo_tablespaces= --server-id= --redo-log-version=
xtrabackup: recognized client arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksum_algorithm=strict_crc32 --innodb_data_file_path=ibdata1:1G;ibdata2:1G:autoextend --innodb_log_files_in_group= --innodb_log_file_size= --innodb_fast_checksum= --innodb_page_size= --innodb_log_block_size= --innodb_undo_directory=/data/mysql_data/undolog/ --innodb_undo_tablespaces= --server-id= --redo-log-version=
:: innobackupex: Starting the apply-log operation IMPORTANT: Please check that the apply-log run completes successfully.
At the end of a successful apply-log run innobackupex
prints "completed OK!". innobackupex version 2.4. based on MySQL server 5.7. Linux (x86_64) (revision id: 170eb8c)
xtrabackup: cd to /opt/--09_19--/
xtrabackup: This target seems to be not prepared yet.
InnoDB: Number of pools:
xtrabackup: xtrabackup_logfile detected: size=, start_lsn=()
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:1G;ibdata2:1G:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group =
xtrabackup: innodb_log_file_size =
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:1G;ibdata2:1G:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group =
xtrabackup: innodb_log_file_size =
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using bytes for buffer pool (set by --use-memory parameter)
InnoDB: PUNCH HOLE support available xtrabackup: starting shutdown with innodb_fast_shutdown =
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number
InnoDB: Number of pools:
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:1G;ibdata2:1G:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group =
xtrabackup: innodb_log_file_size =
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
...
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number
:: completed OK! .将备份出来的数据库scp拷贝到从库
# scp -P -r --09_19-- 172.30.0.52:/opt .关闭从库,清理从库数据,恢复数据到从库 /etc/init.d/mysqld stop 删除从库的数据和日志信息
rm -rf /data/mysql_data/* 在从库上执行(将数据恢复到数据库中)
# innobackupex --defaults-file="/etc/my.cnf" --user=root --socket=/tmp/mysql.sock --copy-back /opt/2019-08-09_19-38-37/
xtrabackup: recognized server arguments: --datadir=/data/mysql_data --tmpdir=/tmp --open_files_limit=10000 --log_bin=mysql-bin --server-id=52 --innodb_data_home_dir=/data/mysql_data --innodb_data_file_path=ibdata1:1G;ibdata2:1G:autoextend --innodb_log_group_home_dir=/data/mysql_data --innodb_undo_directory=/data/mysql_data/undolog/ --innodb_undo_tablespaces=3 --innodb_buffer_pool_size=3G --innodb_log_file_size=256M --innodb_log_buffer_size=64M --innodb_log_files_in_group=3 --innodb_flush_log_at_trx_commit=1 --innodb_file_per_table=1 --innodb_read_io_threads=8 --innodb_write_io_threads=8 --innodb_max_dirty_pages_pct=75 --innodb_flush_method=O_DIRECT --innodb_autoextend_increment=32
xtrabackup: recognized client arguments: --datadir=/data/mysql_data --tmpdir=/tmp --open_files_limit=10000 --log_bin=mysql-bin --server-id=52 --innodb_data_home_dir=/data/mysql_data --innodb_data_file_path=ibdata1:1G;ibdata2:1G:autoextend --innodb_log_group_home_dir=/data/mysql_data --innodb_undo_directory=/data/mysql_data/undolog/ --innodb_undo_tablespaces=3 --innodb_buffer_pool_size=3G --innodb_log_file_size=256M --innodb_log_buffer_size=64M --innodb_log_files_in_group=3 --innodb_flush_log_at_trx_commit=1 --innodb_file_per_table=1 --innodb_read_io_threads=8 --innodb_write_io_threads=8 --innodb_max_dirty_pages_pct=75 --innodb_flush_method=O_DIRECT --innodb_autoextend_increment=32
190809 19:52:10 innobackupex: Starting the copy-back operation IMPORTANT: Please check that the copy-back run completes successfully.
At the end of a successful copy-back run innobackupex
prints "completed OK!". innobackupex version 2.4.12 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 170eb8c)
190809 19:52:10 [01] Copying undo001 to /data/mysql_data/undolog/undo001
190809 19:52:10 [01] ...done
190809 19:52:10 [01] Copying undo002 to /data/mysql_data/undolog/undo002
190809 19:52:10 [01] ...done
190809 19:52:10 [01] Copying undo003 to /data/mysql_data/undolog/undo003
190809 19:52:10 [01] ...done
190809 19:52:10 [01] Copying ib_logfile0 to /data/mysql_data/ib_logfile0
190809 19:52:10 [01] ...done
190809 19:52:11 [01] Copying ib_logfile1 to /data/mysql_data/ib_logfile1
190809 19:52:11 [01] ...done
190809 19:52:12 [01] Copying ib_logfile2 to /data/mysql_data/ib_logfile2
...
190809 19:52:27 [01] Copying ./xtrabackup_binlog_pos_innodb to /data/mysql_data/xtrabackup_binlog_pos_innodb
190809 19:52:27 [01] ...done
190809 19:52:27 completed OK! 5.修改权限,启动从库
# chown -R mysql.mysql /data/mysql_data/ 查看主库中master位置,方便后面配置主从同步点 # cat /opt/2019-08-09_19-38-37/xtrabackup_binlog_info
mysql-bin.000004 660 6.主库中创建建salve同步用户 grant replication slave,reload,super on *.* to rep@172.30.0.52 identified by 'wsdb123';
FLUSH PRIVILEGES; 7.从库执行同步 mysql> change master to master_host='f_crack_check.prod.mysql.eus',master_user='rep',master_password='wsdb123',master_log_file='mysql-bin.000004',master_log_pos=660;
mysql> start slave; mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: f_crack_check.prod.mysql.eus
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 1119
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 779
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes # 关键项,都为yes表示配置主从同步成功
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: information_schema,performance_schema,undolog,for_nagios,undolog,information_schema,performance_schema,undolog,for_nagios,undolog
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table: information_schema.%,performance_schema.%,undolog.%,for_nagios.%,undolog.%,information_schema.%,performance_schema.%,undolog.%,for_nagios.%,undolog.%
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1119
Relay_Log_Space: 986
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 51
Master_UUID: b7215ccd-b9b8-11e9-885d-00163e0073ee
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: b7215ccd-b9b8-11e9-885d-00163e0073ee:1-774
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec) pass ### rep from master
172.30.0.51 f_crack_check.prod.mysql.eus # 主从服务器配置:
阿里云服务器,计算型网络增强型
8核16G内存
40G系统盘 SSD 400G数据盘 master主节点的my.cnf配置: [master]# cat /etc/my.cnf
# Example MySQL config file for medium systems.
# 8核 16G
# This is for a system with little memory (16G) where MySQL plays
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock # The MySQL server
[mysqld]
user = mysql
port = 3306
bind-address = 0.0.0.0
socket = /tmp/mysql.sock
datadir = /data/mysql_data
pid-file = /data/mysql_data/mysql.pid
basedir = /usr/local/mysql
tmpdir = /tmp #此开关默认为NULL,即不允许导入导出。
#secure-file-priv = /opt/upload #-------------------------------gobal variables------------------------#
#默认关闭,涉及到timestamp类型的列自动更新的问题
explicit_defaults_for_timestamp = 1
###transaction_write_set_extraction = XXHASH64 #以便在server收集写集合的同时将其记录到二进制日志。并且是行更改后的唯一标识此标识将用于检测冲突。
###loose-group_replication_group_name = 'ce9be252-2b71-11e6-b8f4-00212889f856' #组的名字可以随便起,但不能用主机的GTID
###loose-group_replication_start_on_boot = off #为了避免每次启动自动引导具有相同名称的第二个组,所以设置为OFF。
###loose-group_replication_bootstrap_group = off #同上
###loose-group_replication_local_address = '192.168.1.88:33071' #写自己主机所在IP
###loose-group_replication_group_seeds ='192.168.1.88:33071,192.168.1.89:33071,192.168.1.90:33071'
###loose-group_replication_single_primary_mode = off #关闭单主模式的参数
###loose-group_replication_enforce_update_everywhere_checks = on #开启多主模式的参数 skip-external-locking
skip-name-resolve
skip-ssl #memory is 16G
key_buffer_size = 32M
table_open_cache = 2048
table_definition_cache = 1024
sort_buffer_size = 4M
net_buffer_length = 32K
read_buffer_size = 4M
read_rnd_buffer_size = 16M open_files_limit = 10000
thread_cache_size = 400
query_cache_type = 0
query_cache_size = 32M
max_write_lock_count = 300
wait_timeout = 120
interactive_timeout = 120
net_read_timeout = 120
net_write_timeout = 120 max_connections = 800
max_user_connections = 750
max_connect_errors = 10000
max_allowed_packet = 512M
back_log = 2048
log_timestamps = system
performance_schema = OFF
character_set_server = utf8mb4 ##当链接数耗尽后,通过设置别用端口,让root可以登录
extra_max_connections = 2
extra_port = 13306 ###让mysql不区分大小写敏感
lower_case_table_names = 1 #explicit_defaults_for_timestamp = 1 #----------------Myisam--------------------------------#
myisam_recover_options = DEFAULT
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 512M
myisam_repair_threads = 1 #if the query is exec time great than 2 seconds, the query will log to slow log if slowlog is enabled.
long_query_time = 1
slow_query_log = On
slow-query-log-file = /data/mysql_data/slow.log
show_compatibility_56 = on # Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking #----------------------------MySQL Log----------------#
# Replication Master Server (default)
# binary logging is required for replication
log-bin = mysql-bin
expire_logs_days = 20
log_error = error.log
log_error_verbosity = 1
log_warnings = 1 # binary logging format - mixed recommended
binlog_format = row
relay-log = mysql-relay-bin
relay-log-index = relay.index
# required unique id between 1 and 2^32 - 1
server-id = 51  # 关键配置,主从配置server-id不能重复
#sql-mode = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
#sql-mode = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
sync_binlog = 1
log_slave_updates = 1
#binlog_checksum = NONE #------------------------------replicate--------------#
#排除不需要同步的库表
#replicate-ignore-db = mysql
#replicate-ignore-db = sys
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = undolog
replicate-ignore-db = for_nagios
replicate-ignore-db = undolog #replicate_wild_ignore_table = mysql.%
#replicate_wild_ignore_table = sys.%
replicate_wild_ignore_table = information_schema.%
replicate_wild_ignore_table = performance_schema.%
replicate_wild_ignore_table = undolog.%
replicate_wild_ignore_table = for_nagios.%
replicate_wild_ignore_table = undolog.% #主主复制需要开启
#auto_increment_offset= 2
#auto_increment_increment= 2 #GTID模式复制,需要开启如下
#gtid_mode = ON
#enforce_gtid_consistency = ON #并发复制
slave-parallel-type = LOGICAL_CLOCK
slave-parallel-workers = 2
master_info_repository = TABLE
relay_log_info_repository = TABLE
relay_log_recovery = ON #跳过slave进程启动参数
skip-slave-start #如果实例为从库,则需要设置为on
#read_only = on #skip-grant-tables #--------------------------------------------------------innoDB------------#
innodb_rollback_on_timeout
# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /data/mysql_data
innodb_data_file_path = ibdata1:1G;ibdata2:1G:autoextend
innodb_log_group_home_dir = /data/mysql_data
innodb_undo_directory = /data/mysql_data/undolog/
innodb_undo_logs = 128
innodb_undo_tablespaces = 3 # You can set .._buffer_pool_size up to 50 - 80 %
#innodb_use_sys_malloc = 0
#innodb_page_size = 8192
innodb_buffer_pool_size = 3G
innodb_buffer_pool_instances = 1
#innodb_additional_mem_pool_size = 8M # Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 256M
innodb_log_buffer_size = 64M
innodb_log_files_in_group = 3
#每次事务提交时MySQL都会把log buffer的数据写入log file,并且flush(刷到磁盘)中去,该模式为系统默认
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 120
#启用独立表空间
innodb_file_per_table = 1 #CPU是1颗8核的,那么可以设置
innodb_read_io_threads = 8
innodb_write_io_threads = 8 #默认是0,则表示没有并发线程数限制,所有请求都会直接请求线程执行,当并发用户线程数量小于64,建议设置innodb_thread_concurrency=0,在大多数情况下,最佳的值是小于并接近虚拟CPU的个数
innodb_thread_concurrency = 12
innodb_max_dirty_pages_pct = 75
innodb_flush_method = O_DIRECT innodb_purge_threads = 10
innodb_large_prefix = 1 #参数待测试
#innodb_io_capacity = 20000
#innodb_io_capacity_max = 40000 #根据CPU核心数来设定
thread_pool_size = 8
#thread_handling = pool-of-threads
thread_pool_oversubscribe = 24 #thread_handling = pool-of-threads
thread_pool_stall_limit = 100
thread_pool_max_threads = 30 #解释: 在启动时把热数据加载到内存。
innodb_buffer_pool_load_at_startup = 1
#解释: 在关闭时把热数据dump到本地磁盘
innodb_buffer_pool_dump_at_shutdown = 1 ##默认是8M, 如果一次insert数据量比较多的话, 可以适当增加
innodb_autoextend_increment = 32 [mysqldump]
quick
max_allowed_packet = 512M [mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates [myisamchk]
#key_buffer_size = 20M
#sort_buffer_size = 20M
key_buffer_size = 200M
sort_buffer_size = 200M
read_buffer = 2M
write_buffer = 2M [mysqld_safe]
#控制文件打开数的show global status like 'open%file%';比较合适的设置:Open_files / open_files_limit * 100% <= 75%
open-files-limit = 65535
log-error = /data/mysql_data/error.log [mysqlhotcopy]
interactive-timeout slave从库my.cnf配置 [slave]# cat /etc/my.cnf
# Example MySQL config file for medium systems.
# 8核 16G
# This is for a system with little memory (16G) where MySQL plays
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock # The MySQL server
[mysqld]
user = mysql
port = 3306
bind-address = 0.0.0.0
socket = /tmp/mysql.sock
datadir = /data/mysql_data
pid-file = /data/mysql_data/mysql.pid
basedir = /usr/local/mysql
tmpdir = /tmp #此开关默认为NULL,即不允许导入导出。
#secure-file-priv = /opt/upload #-------------------------------gobal variables------------------------#
#默认关闭,涉及到timestamp类型的列自动更新的问题
explicit_defaults_for_timestamp = 1
###transaction_write_set_extraction = XXHASH64 #以便在server收集写集合的同时将其记录到二进制日志。并且是行更改后的唯一标识此标识将用于检测冲突。
###loose-group_replication_group_name = 'ce9be252-2b71-11e6-b8f4-00212889f856' #组的名字可以随便起,但不能用主机的GTID
###loose-group_replication_start_on_boot = off #为了避免每次启动自动引导具有相同名称的第二个组,所以设置为OFF。
###loose-group_replication_bootstrap_group = off #同上
###loose-group_replication_local_address = '192.168.1.88:33071' #写自己主机所在IP
###loose-group_replication_group_seeds ='192.168.1.88:33071,192.168.1.89:33071,192.168.1.90:33071'
###loose-group_replication_single_primary_mode = off #关闭单主模式的参数
###loose-group_replication_enforce_update_everywhere_checks = on #开启多主模式的参数 skip-external-locking
skip-name-resolve
skip-ssl #memory is 16G
key_buffer_size = 32M
table_open_cache = 2048
table_definition_cache = 1024
sort_buffer_size = 4M
net_buffer_length = 32K
read_buffer_size = 4M
read_rnd_buffer_size = 16M open_files_limit = 10000
thread_cache_size = 400
query_cache_type = 0
query_cache_size = 32M
max_write_lock_count = 300
wait_timeout = 120
interactive_timeout = 120
net_read_timeout = 120
net_write_timeout = 120 max_connections = 800
max_user_connections = 750
max_connect_errors = 10000
max_allowed_packet = 512M
back_log = 2048
log_timestamps = system
performance_schema = OFF
character_set_server = utf8mb4 ##当链接数耗尽后,通过设置别用端口,让root可以登录
extra_max_connections = 2
extra_port = 13306 ###让mysql不区分大小写敏感
lower_case_table_names = 1 #explicit_defaults_for_timestamp = 1 #----------------Myisam--------------------------------#
myisam_recover_options = DEFAULT
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 512M
myisam_repair_threads = 1 #if the query is exec time great than 2 seconds, the query will log to slow log if slowlog is enabled.
long_query_time = 1
slow_query_log = On
slow-query-log-file = /data/mysql_data/slow.log
show_compatibility_56 = on # Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking #----------------------------MySQL Log----------------#
# Replication Master Server (default)
# binary logging is required for replication
log-bin = mysql-bin
expire_logs_days = 20
log_error = error.log
log_error_verbosity = 1
log_warnings = 1 # binary logging format - mixed recommended
binlog_format = row
relay-log = mysql-relay-bin
relay-log-index = relay.index
# required unique id between 1 and 2^32 - 1
server-id = 52
#sql-mode = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
#sql-mode = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
sync_binlog = 1
log_slave_updates = 1
#binlog_checksum = NONE #------------------------------replicate--------------#
#排除不需要同步的库表
#replicate-ignore-db = mysql
#replicate-ignore-db = sys
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = undolog
replicate-ignore-db = for_nagios
replicate-ignore-db = undolog #replicate_wild_ignore_table = mysql.%
#replicate_wild_ignore_table = sys.%
replicate_wild_ignore_table = information_schema.%
replicate_wild_ignore_table = performance_schema.%
replicate_wild_ignore_table = undolog.%
replicate_wild_ignore_table = for_nagios.%
replicate_wild_ignore_table = undolog.% #主主复制需要开启
#auto_increment_offset= 2
#auto_increment_increment= 2 #GTID模式复制,需要开启如下
#gtid_mode = ON
#enforce_gtid_consistency = ON #并发复制
slave-parallel-type = LOGICAL_CLOCK
slave-parallel-workers = 2
master_info_repository = TABLE
relay_log_info_repository = TABLE
relay_log_recovery = ON #跳过slave进程启动参数
skip-slave-start #如果实例为从库,则需要设置为on
read_only = on #skip-grant-tables #--------------------------------------------------------innoDB------------#
innodb_rollback_on_timeout
# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /data/mysql_data
innodb_data_file_path = ibdata1:1G;ibdata2:1G:autoextend
innodb_log_group_home_dir = /data/mysql_data
innodb_undo_directory = /data/mysql_data/undolog/
innodb_undo_logs = 128
innodb_undo_tablespaces = 3 # You can set .._buffer_pool_size up to 50 - 80 %
#innodb_use_sys_malloc = 0
#innodb_page_size = 8192
innodb_buffer_pool_size = 3G
innodb_buffer_pool_instances = 1
#innodb_additional_mem_pool_size = 8M # Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 256M
innodb_log_buffer_size = 64M
innodb_log_files_in_group = 3
#每次事务提交时MySQL都会把log buffer的数据写入log file,并且flush(刷到磁盘)中去,该模式为系统默认
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 120
#启用独立表空间
innodb_file_per_table = 1 #CPU是1颗8核的,那么可以设置
innodb_read_io_threads = 8
innodb_write_io_threads = 8 #默认是0,则表示没有并发线程数限制,所有请求都会直接请求线程执行,当并发用户线程数量小于64,建议设置innodb_thread_concurrency=0,在大多数情况下,最佳的值是小于并接近虚拟CPU的个数
innodb_thread_concurrency = 12
innodb_max_dirty_pages_pct = 75
innodb_flush_method = O_DIRECT innodb_purge_threads = 10
innodb_large_prefix = 1 #参数待测试
#innodb_io_capacity = 20000
#innodb_io_capacity_max = 40000 #根据CPU核心数来设定
thread_pool_size = 8
#thread_handling = pool-of-threads
thread_pool_oversubscribe = 24 #thread_handling = pool-of-threads
thread_pool_stall_limit = 100
thread_pool_max_threads = 30 #解释: 在启动时把热数据加载到内存。
innodb_buffer_pool_load_at_startup = 1
#解释: 在关闭时把热数据dump到本地磁盘
innodb_buffer_pool_dump_at_shutdown = 1 ##默认是8M, 如果一次insert数据量比较多的话, 可以适当增加
innodb_autoextend_increment = 32 [mysqldump]
quick
max_allowed_packet = 512M [mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates [myisamchk]
#key_buffer_size = 20M
#sort_buffer_size = 20M
key_buffer_size = 200M
sort_buffer_size = 200M
read_buffer = 2M
write_buffer = 2M [mysqld_safe]
#控制文件打开数的show global status like 'open%file%';比较合适的设置:Open_files / open_files_limit * 100% <= 75%
open-files-limit = 65535
log-error = /data/mysql_data/error.log [mysqlhotcopy]
interactive-timeout 备份计划:
1.备份脚本的目录结构 [/usr/local/worksh]# tree xtrabackup_cron/
xtrabackup_cron/
├── bin
│   └── mysql_increment_hot_backup.sh
├── conf
│   └── mysql_increment_hot_backup.conf
├── log
└── var 备份脚本 [/usr/local/worksh]# cat /usr/local/worksh/xtrabackup_cron/bin/mysql_increment_hot_backup.sh
#!/usr/bin/env bash # Program: MySQL 增量备份脚本 使用 percona xtrabackup
##进入程序目录
cd /usr/local/worksh/xtrabackup_cron/bin
# 读取配置文件中的所有变量值, 设置为全局变量
# 配置文件
conf_file="../conf/mysql_increment_hot_backup.conf"
# mysql 用户
user=`sed '/^user=/!d;s/.*=//' $conf_file`
# mysql 密码
#password=`sed '/^password=/!d;s/.*=//' $conf_file`
password="xtrabackup**123" # mysql 备份目录
backup_dir=`sed '/^backup_dir=/!d;s/.*=//' $conf_file`
# percona-xtrabackup 备份软件路径
xtrabackup_dir=`sed '/^xtrabackup_dir=/!d;s/.*=//' $conf_file`
# 全备是在一周的第几天
full_backup_week_day=`sed '/^full_backup_week_day=/!d;s/.*=//' $conf_file`
# mysql 全备前缀标识
full_backup_prefix=`sed '/^full_backup_prefix=/!d;s/.*=//' $conf_file`
# mysql 增量备前缀标识
increment_prefix=`sed '/^increment_prefix=/!d;s/.*=//' $conf_file`
# mysql 配置文件
mysql_conf_file=`sed '/^mysql_conf_file=/!d;s/.*=//' $conf_file`
# 备份错误日志文件
error_log=`sed '/^error_log=/!d;s/.*=//' $conf_file`
# 备份索引文件
index_file=`sed '/^index_file=/!d;s/.*=//' $conf_file` # 备份日期
backup_date=`date +%F`
# 备份日期
backup_time=`date +%H-%M-%S`
# 备份日期
backup_week_day=`date +%u` # 设置备份线程数
backup_thread=4 # 创建相关目录
log_dir=../log
var_dir=../var
mkdir -p $backup_dir
mkdir -p $log_dir
mkdir -p $var_dir # 全量备份
function full_backup() {
backup_folder=${full_backup_prefix}_${backup_date}_${backup_time}_${backup_week_day} mkdir -p $backup_dir/$backup_folder
$xtrabackup_dir/bin/innobackupex --defaults-file=$mysql_conf_file --user=$user --password=$password --parallel=$backup_thread --no-timestamp $backup_dir/$backup_folder > $log_dir/${backup_folder}.log 2>&1
return $?
} # 增量备份
function increment_backup() {
backup_folder=${increment_prefix}_${backup_date}_${backup_time}_${backup_week_day}
incr_base_folder=`sed -n '$p' $index_file | \
awk -F '[, {}]*' '{print $3}' | \
awk -F ':' '{print $2}'` mkdir -p $backup_dir/$backup_folder
$xtrabackup_dir/bin/innobackupex \
--defaults-file=$mysql_conf_file \
--user=$user \
--password=$password \
--no-timestamp \
--incremental \
$backup_dir/$backup_folder \
--incremental-basedir=$backup_dir/$incr_base_folder > $log_dir/${backup_folder}.log 2>&1
return $?
} # 删除之前的备份(一般在全备完成后使用)
function delete_before_backup() {
cat $index_file | awk -F '[, {}]*' '{print $3}' | \
awk -v backup_dir=$backup_dir -F ':' '{if($2!=""){printf("rm -rf %s/%s\n", backup_dir, $2)}}' | \
/bin/bash cat $index_file | awk -F '[, {}]*' '{print $3}' | \
awk -v log_dir=$log_dir -F ':' '{if($2!=""){printf("rm -rf %s/%s.log\n", log_dir, $2)}}' | \
/bin/bash
} # 备份索引文件
function backup_index_file() {
cp $index_file ${index_file}_$(date -d "1 day ago" +%F)
} # 备份索引文件
function send_index_file_to_remote() {
echo 'send index file ok'
} # 添加索引, 索引记录了当前最新的备份
function append_index_to_file() {
echo "{week_day:$backup_week_day, \
dir:${1}_${backup_date}_${backup_time}_${backup_week_day}, \
type:${1}, \
date:${backup_date}}" >> $index_file
} # 记录 错误消息到文件
function logging_backup_err() {
echo "{week_day:$backup_week_day, \
dir:${1}_${backup_date}_${backup_time}_${backup_week_day}, \
type:${1}, \
date:${backup_date}}" >> $error_log
} # 清空索引
function purge_index_from_file() {
> $index_file
} # 清空错误日志信息
function purge_err_log() {
> $error_log
} # 打包备份
function tar_backup_file() {
echo "tar $1 ok"
} # 发送备份到远程
function send_backup_to_remote() {
echo "send $1 remote ok"
} # 判断是应该全备还是增量备份
# 0:full, 1:incr
function get_backup_type() {
full_backup_week_day=`sed '/^full_backup_week_day=/!d;s/.*=//' $conf_file`
backup_type=0
if [ "$full_backup_week_day" -eq `date +%u` ]; then
backup_type=0
else
backup_type=1
fi
if [ ! -n "`cat $index_file`" ]; then
backup_type=0
fi
return $backup_type
} # 测试配置文件正确性
function test_conf_file() {
# 判断每个变量是否在配置文件中有配置,没有则退出程序
if [ ! -n "$user" ]; then echo 'fail: configure file user not set'; exit 2; fi
if [ ! -n "$password" ]; then echo 'fail: configure file password not set'; exit 2; fi
if [ ! -n "$backup_dir" ]; then echo 'fail: configure file backup_dir not set'; exit 2; fi
if [ ! -n "$full_backup_week_day" ]; then echo 'fail: configure file full_backup_week_day not set'; exit 2; fi
if [ ! -n "$full_backup_prefix" ]; then echo 'fail: configure file full_backup_prefix not set'; exit 2; fi
if [ ! -n "$increment_prefix" ]; then echo 'fail: configure file increment_prefix not set'; exit 2; fi
if [ ! -n "$mysql_conf_file" ]; then echo 'fail: configure file mysql_conf_file not set'; exit 2; fi
if [ ! -n "$error_log" ]; then echo 'fail: configure file error_log not set'; exit 2; fi
if [ ! -n "$index_file" ]; then echo 'fail: configure file index_file not set'; exit 2; fi
} # 执行
function run() {
# 检测配置文件值
test_conf_file # 判断是执行全备还是曾量备份
get_backup_type
backup_type=$?
case $backup_type in
0 )
# 全量备份
full_backup
backup_ok=$?
if [ 0 -eq "$backup_ok" ]; then
# 全备成功
# # 打包最新备份
# tar_backup_file $full_backup_prefix
# # 将tar备份发送到远程
# send_backup_to_remote $full_backup_prefix
# 备份索引文件
backup_index_file
# # 发送索引文件到远程
# send_index_file_to_remote
# 清除之前的备份
delete_before_backup
# 清除索引文件
purge_index_from_file
# 添加索引, 索引记录了当前最新的备份
append_index_to_file $full_backup_prefix
else
# 全备失败
# 删除备份目录
rm -rf ${backup_dir}/${full_backup_prefix}_${backup_date}_${backup_time}_${backup_week_day}
# 记录错误日志
logging_backup_err $full_backup_prefix
fi
;;
1 )
# 增量备份
increment_backup
backup_ok=$?
if [ 0 -eq "$backup_ok" ]; then
# 增量备份成功
# # 打包最新备份
# tar_backup_file $increment_prefix
# # 将tar备份发送到远程
# send_backup_to_remote $increment_prefix
# 添加索引, 索引记录了当前最新的备份
append_index_to_file $increment_prefix
else
# 增量备份失败
# 删除备份目录
rm -rf ${backup_dir}/${full_backup_prefix}_${backup_date}_${backup_time}_${backup_week_day}
# 记录错误日志
logging_backup_err $increment_prefix
fi
;;
esac
} run
chown -R apache.users /data/MySQL_Data_Backup 配置文件
# cat /usr/local/worksh/xtrabackup_cron/conf/mysql_increment_hot_backup.conf
# 备份专用用户
# GRANT RELOAD, PROCESS, SUPER, LOCK TABLES, REPLICATION CLIENT, CREATE TABLESPACE ON *.* TO 'xtrabackup'@'localhost' identified by 'xtrabackuppass';
# flush privileges; # mysql 用户名
user=xtrabackup # mysql 密码
password="xtrabackuppass" # 备份存放路径
backup_dir=/data/MySQL_Data_Backup # percona-xtrabackup 备份软件路径
xtrabackup_dir=/usr # 全备是在一周的第几天
full_backup_week_day=4 # 全量备信息名称 前缀
full_backup_prefix=full # 增量备信息名称 前缀
increment_prefix=incr # mysql配置文件
mysql_conf_file=/etc/my.cnf # 错误日志文件(更具此文件知道备份是否成功)
# format:
# {week_day:1,dir:full/incr_2015-12-29_00-00-00_7,type:full/incr,date:2015-12-30}
error_log=../var/mysql_increment_hot_backup.err # 索引文件
# format:
# {week_day:1,dir:full/incr_2015-12-29_00-00-00_7,type:full/incr}
index_file=../var/mysql_increment_hot_backup.index 2.添加计划任务crontab -e ########mysql backup 每周4进行全备份,每天定时增量备份,保留一周
03 01 * * * /usr/local/worksh/xtrabackup_cron/bin/mysql_increment_hot_backup.sh

percona-mysql5.7.24使用xtrabackup工具配置主从同步的更多相关文章

  1. MYSQL配置主从同步

    MYSQL配置主从同步 mysql主服务器配置 vim /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql. ...

  2. Mysql配置主从同步的基本步骤

    # 配置主从同步的基本步骤 #总结为如下的步骤: # .在主服务器上,必须开启二进制日志机制和配置一个独立的ID # .在每一个从服务器上,配置一个唯一的ID,创建一个用来专门复制主服务器数据的账号 ...

  3. mysql 在Linux 配置 主从同步

    一.主服务器相关配置 1.创建同步账户并指定服务器地址 [root@localhost ~]mysql -uroot -pmysql>use mysqlmysql>grant replic ...

  4. Mysql5.6.24 zip解压缩版配置及修改默认编码方法

    win64位下载地址: http://dev.mysql.com/downloads/file.php?id=456319 下载完毕后解压 配置环境变量 在Path后加上mysql解压后bin文件夹所 ...

  5. centos6.6手动安装mysql5.5并配置主从同步

    0.实验环境 主机IP(Master) 192.168.61.150 centos6.6 从机IP(Slave)   192.168.61.157 centos6.6 1.查看centos系统版本 [ ...

  6. XtraBackup做mysql主从同步

    一.背景: 线上一个主库压力比较大,所以增加一个从库,但是不能重启或者停止主库的正常运行,不能锁库锁表影响业务的正常运行.所以这里想到了XtraBackup 二.XtraBackup介绍: Xtrab ...

  7. mysql数据库配置主从同步

    MySQL主从同步的作用 .可以作为一种备份机制,相当于热备份 .可以用来做读写分离,均衡数据库负载 MySQL主从同步的步骤 一.准备操作 .主从数据库版本一致,建议版本5.5以上 .主从数据库数据 ...

  8. Linux下Oracle 10g DataGuard配置(主从同步及切换)

    环境描述:主库: IP: 10.8.3.191 主机名:primaryORACLE_SID=afcORACLE_BASE=/u01/oracleORACLE_HOME=/u01/oracle/10g备 ...

  9. MySQL 5.6数据库配置主从同步

    win7环境下mysql主从搭建 我下载的是压缩包,免安装的那种 1.简单安装 解压后把my-default.ini复制一份改为my.ini默认mysql会找这个文件,首先从system32下找,然后 ...

随机推荐

  1. C++中与类有关的注意事项(更新中~~~)

    关于构造函数的调用次序,见下列代码 #include<iostream> using namespace std; class A { private: int x; public: A( ...

  2. java连接mysql数据库时的时区设置问题(time_zone)

    java在连接mysql数据库时,会由于时区设置不正确导致报以下的错误:   The server time zone value '???ú±ê×??±??' is unrecognized or ...

  3. No.1.测试Synchronized加锁String字符串后的多线程同步状况

    测试目的描述 Synchronized关键字锁定String字符串可能会带来严重的后果, 尽量不要使用 synchronized(String a) 因为JVM中,因为字符串常量池具有缓冲功能! 接下 ...

  4. destoon模板存放调取规则

    一.模板存放及调用规则      模板存放于系统 template 目录,template 目录下的一个目录例如 template/default/ 即为一套模板 模板文件以 .htm 为扩展名,可直 ...

  5. Nmap扫描工具实验报告

    实验报告 实验内容 通过ping进行操作系统探测 利用Zenmap/Nmap进行TCP connet扫描.TCP SYN扫描和操作系统扫描 实验目的 了解扫描的一般步骤 熟练使用ping命令并能够进行 ...

  6. Fzu-html1

    Fzu-趣考网-前端1 html 题目: 使用html写出h1~h6六种格式的hello world 使用html的table标签制作一个表格,存储本学期专业课程(参考教务处课表) 使用html的sc ...

  7. Set的常用实现类HashSet和TreeSet

    Set HashSet public static void main(String[] args) { //不可以重复  并且是无序的  //自然排序  从A-Z  //eqauls从Object继 ...

  8. java实现大文件上传分片上传断点续传

    我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用. 这次项目的需求: 支持大文件的上传和续传,要求续传支持所有浏览器,包括ie6,ie7,i ...

  9. RookeyFrame 信息 常用信息整理

    博客 https://www.cnblogs.com/rookey/ gitee的地址: https://gitee.com/rookey/Rookey.Frame-v2.0 https://gite ...

  10. 汇编语言DOSBox软件使用方法

    https://wenku.baidu.com/view/e63b8b46ccbff121dc368305.html