Mysql 利用percona-xtrabackup線上配置主從
Mysql 利用percona-xtrabackup線上配置主從
一.在主從上分別安裝Mysql
編譯安裝
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
groupadd mysql
useradd -g mysql mysql
mkdir -p /usr/local/mysql
[root@TESTDB02-1-16 tools]# tar -xf mysql-5.6.27.tar.gz
[root@TESTDB02-1-16 tools]# cd mysql-5.6.27
[root@TESTDB02-1-16 mysql-5.6.27]# pwd
/usr/local/tools/mysql-5.6.27
[root@TESTDB02-1-16 mysql-5.6.27]# mkdir -p /u02/mysql/data
[root@TESTDB02-1-16 mysql-5.6.27]# chown -R mysql:mysql /u02/mysql
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/u02/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make;
make install;
vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
#prompt="(\u:HOSTNAME:)[\d]> "
prompt="\u@\h \R:\m:\s [\d]> "
no-auto-rehash
[mysqld]
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr
datadir = /u02/mysql/data
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit = 3072
back_log = 103
max_connections = 512
max_connect_errors = 100000
table_open_cache = 512
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 51
query_cache_size = 22M
#default_table_type = InnoDB
tmp_table_size = 96M
max_heap_table_size = 96M
slow_query_log = 1
slow_query_log_file = /u02/mysql/log/slow.log
log-error = /u02/mysql/log/error.log
long_query_time = 3
server-id = 77
log-bin = /u02/mysql/log_bin/log_bin
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 1024M
expire_logs_days = 1
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
relay_log_recovery = 1
key_buffer_size = 15M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
transaction_isolation = REPEATABLE-READ
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 502M
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_locks_unsafe_for_binlog = 0
[mysqldump]
quick
max_allowed_packet = 32M
主庫:
cd /usr/local/mysql/scripts
[root@ scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/u02/mysql/data/
cp ./support-files/mysql.server /etc/init.d/mysqld
主庫修改密碼
匯入所需求庫
mysql -uroot -p test <test.sql
利用percona-xtrabackup備份庫
主從安裝percona-xtrabackup
wget
innobackupex --socket=/data/mysql/mysql.sock --parallel=8 --user=root --password=XMSSSS /data/backup/hotbackup
scp -r /data/backup/hotbackup/* root@備庫:/u02/mysql/hotbackup
主庫建帳戶
GRANT REPLICATION SLAVE ON *.* TO '使用者名稱'@'從庫ip' IDENTIFIED BY '密碼';
從庫恢復
cd /u02/mysql/hotbackup
注意在從庫恢復之前建好my.cnf,如果主庫開啟忽略大小寫,從庫也要一樣,不然會報錯
innobackupex --user=root --password=密碼 --defaults-file=/etc/my.cnf --apply-log /u02/mysql/hotbackup/2015-10-28_17-30-50/
innobackupex --copy-back /u02/mysql/hotbackup/2015-10-28_17-30-50/
chown -R mysql:mysql /u02/mysql
service mysql start
cat xtrabackup_binlog_info
log_bin.000006 928891450
記住此logbin和pos
CHANGE MASTER TO MASTER_HOST='主IP', MASTER_USER='使用者名稱', MASTER_PASSWORD='密碼', MASTER_LOG_FILE='log_bin.000006', MASTER_LOG_POS=928891450;
start slave;
show slave status \G
一.在主從上分別安裝Mysql
編譯安裝
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
groupadd mysql
useradd -g mysql mysql
mkdir -p /usr/local/mysql
[root@TESTDB02-1-16 tools]# tar -xf mysql-5.6.27.tar.gz
[root@TESTDB02-1-16 tools]# cd mysql-5.6.27
[root@TESTDB02-1-16 mysql-5.6.27]# pwd
/usr/local/tools/mysql-5.6.27
[root@TESTDB02-1-16 mysql-5.6.27]# mkdir -p /u02/mysql/data
[root@TESTDB02-1-16 mysql-5.6.27]# chown -R mysql:mysql /u02/mysql
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/u02/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make;
make install;
vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
#prompt="(\u:HOSTNAME:)[\d]> "
prompt="\u@\h \R:\m:\s [\d]> "
no-auto-rehash
[mysqld]
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr
datadir = /u02/mysql/data
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit = 3072
back_log = 103
max_connections = 512
max_connect_errors = 100000
table_open_cache = 512
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 51
query_cache_size = 22M
#default_table_type = InnoDB
tmp_table_size = 96M
max_heap_table_size = 96M
slow_query_log = 1
slow_query_log_file = /u02/mysql/log/slow.log
log-error = /u02/mysql/log/error.log
long_query_time = 3
server-id = 77
log-bin = /u02/mysql/log_bin/log_bin
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 1024M
expire_logs_days = 1
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
relay_log_recovery = 1
key_buffer_size = 15M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
transaction_isolation = REPEATABLE-READ
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 502M
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_locks_unsafe_for_binlog = 0
[mysqldump]
quick
max_allowed_packet = 32M
主庫:
cd /usr/local/mysql/scripts
[root@ scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/u02/mysql/data/
cp ./support-files/mysql.server /etc/init.d/mysqld
主庫修改密碼
匯入所需求庫
mysql -uroot -p test <test.sql
利用percona-xtrabackup備份庫
主從安裝percona-xtrabackup
wget
innobackupex --socket=/data/mysql/mysql.sock --parallel=8 --user=root --password=XMSSSS /data/backup/hotbackup
scp -r /data/backup/hotbackup/* root@備庫:/u02/mysql/hotbackup
主庫建帳戶
GRANT REPLICATION SLAVE ON *.* TO '使用者名稱'@'從庫ip' IDENTIFIED BY '密碼';
從庫恢復
cd /u02/mysql/hotbackup
注意在從庫恢復之前建好my.cnf,如果主庫開啟忽略大小寫,從庫也要一樣,不然會報錯
innobackupex --user=root --password=密碼 --defaults-file=/etc/my.cnf --apply-log /u02/mysql/hotbackup/2015-10-28_17-30-50/
innobackupex --copy-back /u02/mysql/hotbackup/2015-10-28_17-30-50/
chown -R mysql:mysql /u02/mysql
service mysql start
cat xtrabackup_binlog_info
log_bin.000006 928891450
記住此logbin和pos
CHANGE MASTER TO MASTER_HOST='主IP', MASTER_USER='使用者名稱', MASTER_PASSWORD='密碼', MASTER_LOG_FILE='log_bin.000006', MASTER_LOG_POS=928891450;
start slave;
show slave status \G
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24486203/viewspace-1969560/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 利用percona-xtrabackup快速搭建MySQL資料庫主從複製MySql資料庫
- mysqlbackup線上配置Mysql主從架構MySql架構
- mysql主從配置MySql
- mysql 主從配置MySql
- mysql配置主從MySql
- MySQL 主從配置-之-一主一從MySql
- MySQL主從同步配置MySql主從同步
- docker mysql 主從配置DockerMySql
- MySQL雙主雙從配置MySql
- MySql 主從複製配置MySql
- MySQL主從複製配置MySql
- MySQL常用操作和主從配置MySql
- mysql主從資料庫配置MySql資料庫
- mysql主從配置(清晰的思路)MySql
- MYSQL主從複製配置(整理)MySql
- mysql雙主雙從 搭建配置MySql
- docker 配置 Mysql主從叢集DockerMySql
- mysql 5.7 GTID主從配置MySql
- MySQL主從同步配置記錄MySql主從同步
- XtraBackup線上進行MySQL的主從部署一MySql
- MySQL主從同步(一主一從、一主多從、主從從)等結構的概述與配置MySql主從同步
- MySQL主從配置及mysqldump備份MySql
- 使用laradock配置mysql主從同步MySql主從同步
- 8、MySQL主從資料庫配置MySql資料庫
- mysql複製--主從複製配置MySql
- MySQL 主從架構配置詳解MySql架構
- mysql for linux 配置主從複製MySqlLinux
- mysql主從複製原理及配置MySql
- Freebsd 8.3 下Mysql 主從配置MySql
- 【實操記錄】MySQL主從配置MySql
- MHA+MySQL主從配置實現MySQL高可用MySql
- MySQL 配置多主一從 ( 8.0.18 版本 )MySql
- MySQL 主從複製安裝部署配置MySql
- 基於Linux的mysql主從配置LinuxMySql
- 配置\清除 MySQL 主從 讀寫分離MySql
- Docker 教程十五配置MySQL 主從複製DockerMySql
- MYSQL主從複製製作配置方案MySql
- Window 10 單機配置MYSQL主從同步MySql主從同步