MySQL雙主+keeplived安裝部署說明 一、環境介紹 1.1、規劃 序號 類別 版本 主機名 IP 埠 備註 1 OS CentOS release 6.9 (Final) (minimal) my1 172.16.210.180 8306 172.16.210.183 2 mysql m ...
MySQL雙主+keeplived安裝部署說明
一、環境介紹
1.1、規劃
序號 |
類別 |
版本 |
主機名 |
IP |
埠 |
備註 |
1 |
OS |
CentOS release 6.9 (Final) (minimal) |
my1 |
172.16.210.180 |
8306 |
172.16.210.183 |
2 |
mysql |
mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz |
my2 |
172.16.210.181 |
8306 |
|
3 |
keeplived |
keepalived-1.2.7.tar.gz |
|
|
|
|
參考資料:
http://www.cnblogs.com/276815076/p/5649539.html
mysql下載地址:
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
keeplived下載地址:
http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
1.2、MySQL雙主互備+keepalived高可用架構介紹
MySQL主從複製架構可以在很大程度保證MySQL的高可用,在一主多從的架構中還可以利用讀寫分離將讀操作分配到從庫中,減輕主庫壓力。但是在這種架構中,主庫出現故障時需要手動將一臺從庫提升為主庫。在對寫操作要求較高的環境中,主庫故障在主從架構中會成為單點故障。因此需要主主互備架構,避免主節點故障造成寫操作失效。
在雙主互備的架構中,每台MySQL都充當主伺服器,同時充當對方的從伺服器。在任意一臺伺服器上的寫操作都會被覆制到另一臺伺服器上,從而保證了數據的可靠性。
在雙主互備的基礎上加上keepalived,在其中一臺機器上綁定虛擬ip(VIP)。利用vip統一對外服務,可以避免在兩個節點同時寫數據造成衝突。同時當keepalived主節點發生故障時,keeplived會自動將VIP切換到備節點上,從而實現主伺服器的高可用。
二、安裝mysql5.7
2.1、主機M1上的操作
2.1.1、安裝依賴包
yum clean all yum -y update yum -y install gcc gcc-c++ make autoconf automake ncurses-devel bison ncurses cmake libaio libaio-devel boost yum -y install gcc-c++ gd libxml2-devel libjpeg-devel libpng-devel net-snmp-devel wget telnet vim zip unzip yum -y install curl-devel libxslt-devel pcre-devel libjpeg libpng libcurl4-openssl-dev yum -y install libcurl-devel libcurl freetype-config freetype freetype-devel unixODBC libxslt yum -y install gcc automake autoconf libtool openssl-devel yum -y install perl-devel perl-ExtUtils-Embed yum -y install cmake ncurses-devel.x86_64 openldap-devel.x86_64 lrzsz openssh-clients gcc-g77 bison yum -y install libmcrypt libmcrypt-devel mhash mhash-devel bzip2 bzip2-devel yum -y install ntpdate rsync svn patch iptables iptables-services yum -y install libevent libevent-devel cyrus-sasl cyrus-sasl-devel yum -y install gd-devel libmemcached-devel memcached git libssl-devel libyaml-devel auto make yum -y groupinstall "Server Platform Development" "Development tools" yum -y groupinstall "Development tools"
2.1.2、下載解壓
rm -rf /etc/my.cnf mkdir -p /opt/mysql cd /opt/mysql/ wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz tar -zxf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz cd /usr/local/ ln -s /opt/mysql/mysql-5.7.20-linux-glibc2.12-x86_64 mysql
2.1.3、創建所需要的目錄
mkdir -p /data/mysql/mysql_8306/{data,logs,tmp}
2.1.4、更改許可權
groupadd mysql
useradd -g mysql mysql -d /home/mysql -s /sbin/nologin
2.1.5、創建my.cnf
cat >/data/mysql/mysql_8306/my_8306.cnf <<EOF #my.cnf [client] port = 8306 socket = /data/mysql/mysql_8306/tmp/mysql_8306.sock [mysql] #prompt="\u@\h:\p \R:\m:\s [\d]>" #tee=/data/mysql/mysql_8306/data/query.log #prompt="\u@\h:\p \R:\m:\s [\d]>" prompt = "[\u@\h][\d]>\_" connect_timeout = 5 no-auto-rehash [mysqld] #misc user = mysql basedir = /usr/local/mysql datadir = /data/mysql/mysql_8306/data port = 8306 socket = /data/mysql/mysql_8306/tmp/mysql_8306.sock #timeout interactive_timeout = 300 wait_timeout = 300 #character set character-set-server = utf8 open_files_limit = 65535 max_connections = 100 max_connect_errors = 100000 skip-name-resolve = 1 #logs log-output=file slow_query_log = 1 slow_query_log_file = /data/mysql/mysql_8306/logs/slow.log log-error = /data/mysql/mysql_8306/logs/error.log log_error_verbosity = 3 pid-file = mysql.pid long_query_time = 1 #log-slow-admin-statements = 1 #log-queries-not-using-indexes = 1 log-slow-slave-statements = 1 #tmp tmpdir=/data/mysql/mysql_8306/tmp event_scheduler = 1 performance_schema = on max_allowed_packet = 32M character_set_server = utf8mb4 #character_set_server = utf8 default-time-zone = system default-storage-engine = InnoDB #bind_address = 172.16.151.248 explicit_defaults_for_timestamp = 1 #binlog binlog_format = row server-id = 1818306 log-bin = /data/mysql/mysql_8306/logs/mysql-bin log-bin-index = /data/mysql/mysql_8306/logs/mysql-bin.index binlog_cache_size = 4M max_binlog_size = 1G max_binlog_cache_size = 2G sync_binlog = 0 expire_logs_days = 90 #replicate-wild-ignore-table=mysql.% replicate-wild-ignore-table=test.% replicate-wild-ignore-table=information_schema.% #relay log skip_slave_start = 1 max_relay_log_size = 1G relay_log_purge = 1 relay_log_recovery = 1 log_slave_updates #slave-skip-errors=1032,1053,1062 explicit_defaults_for_timestamp=1 #buffers & cache table_open_cache = 2048 table_definition_cache = 2048 table_open_cache = 2048 max_heap_table_size = 96M sort_buffer_size = 2M join_buffer_size = 2M thread_cache_size = 256 query_cache_size = 0 query_cache_type = 0 query_cache_limit = 256K query_cache_min_res_unit = 512 thread_stack = 192K tmp_table_size = 96M key_buffer_size = 8M read_buffer_size = 2M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 32M #myisam myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 #innodb innodb_buffer_pool_size = 10G innodb_buffer_pool_instances = 1 innodb_data_file_path = ibdata1:1G:autoextend innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 64M innodb_log_file_size = 500M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 50 innodb_file_per_table = 1 innodb_rollback_on_timeout innodb_status_file = 1 innodb_io_capacity = 2000 transaction_isolation = READ-COMMITTED innodb_flush_method = O_DIRECT gtid_mode = ON enforce_gtid_consistency = ON master_info_repository = TABLE relay-log-info-repository = TABLE binlog_checksum = NONE log_slave_updates = ON # Two-Master configure #server-1 auto-increment-offset = 1 auto-increment-increment = 2 #server-2 #auto-increment-offset = 2 #auto-increment-increment = 2 # semi sync replication settings # plugin_dir = /usr/local/mysql/lib/plugin #官方版本的路徑 #plugin_dir = /usr/local/mysql/lib/mysql/plugin plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" #官方版本的路徑 #plugin_load = "validate_password.so;rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" loose_rpl_semi_sync_master_enabled = on loose_rpl_semi_sync_master_timeout = 5000 loose_rpl_semi_sync_master_trace_level = 32 loose_rpl_semi_sync_master_wait_no_slave = on loose_rpl_semi_sync_slave_enabled = on loose_rpl_semi_sync_slave_trace_level = 32 loose_rpl_semi_sync_master_enabled = 1 loose_rpl_semi_sync_slave_enabled = 1 loose_rpl_semi_sync_master_timeout = 5000 loose_rpl_semi_sync_master_wait_for_slave_count=1 loose_rpl_semi_sync_master_wait_point=AFTER_SYNC slave_preserve_commit_order = 1 slave_transaction_retries = 128 log_timestamps = system show_compatibility_56 = on slave_parallel_workers = 16 slave_parallel_type = LOGICAL_CLOCK loose_innodb_numa_interleave = 1 innodb_buffer_pool_dump_pct = 40 innodb_page_cleaners = 16 innodb_undo_log_truncate = 1 innodb_max_undo_log_size = 2G innodb_purge_rseg_truncate_frequency = 128 #transaction_write_set_extraction = MURMUR32 # group replication ##log-bin = mysql ##server-id = 618306 ##gtid_mode = ON ##enforce_gtid_consistency = ON ##master_info_repository = TABLE ##relay-log-info-repository = TABLE ##binlog_checksum = NONE ##log_slave_updates = ON ##binlog_format = row ##transaction_write_set_extraction=XXHASH64 ##loose-group_replication_group_name = '3db33b36-0e51-409f-a61d-c99756e90154' ##loose-group_replication_start_on_boot = off ##loose-group_replication_local_address= "10.125.141.62:28306" # 不能超過5位數字 ##loose-group_replication_group_seeds= "10.125.141.62:28306,10.125.141.62:23307,10.125.141.62:23308" # 不能超過5位數字 ##loose-group_replication_bootstrap_group= off # loose-group_replication_single_primary_mode=FALSE ###本次搭建的是mutil_mode # loose-group_replication_enforce_update_everywhere_checks= TRUE [mysqld_safe] #malloc-lib=/usr/local/mysql/lib/jmalloc.so nice=-19 open-files-limit=65535 EOF
2.1.6、修改目錄許可權
chown -R mysql.mysql /data/mysql/
2.1.7、初始化
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_8306/my_8306.cnf --initialize-insecure &
2.1.8、啟動
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_8306/my_8306.cnf &
# 推薦的啟動方式
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_8306/my_8306.cnf &
2.1.9、登陸方式
/usr/local/mysql/bin/mysql -uroot -p -P8306 -S /data/mysql/mysql_8306/tmp/mysql_8306.sock
或者
/usr/local/mysql/bin/mysql -P8306 -S /data/mysql/mysql_8306/tmp/mysql_8306.sock
2.1.10、創建授權修改密碼
set sql_log_bin = 0; create user 'rpl_user'@'%'; grant replication slave on *.* to 'rpl_user'@'%' identified by 'rpl_user2017'; update mysql.user set authentication_string=password('root2017') where user='root'; flush privileges; set sql_log_bin = 1; reset master ; reset slave all;
2.1.11、change master
CHANGE MASTER TO MASTER_HOST='172.16.210.181',MASTER_USER='rpl_user', MASTER_PASSWORD='rpl_user2017',MASTER_PORT=8306, MASTER_CONNECT_RETRY=10,MASTER_AUTO_POSITION =1; start slave; show slave status\G;
2.1.12、設置快捷登陸方式
[root@my1 local]# /usr/local/mysql/bin/mysql_config_editor set --host=localhost --login-path=8306_localhost_login \ > --user=root --port=8306 --password --socket=/data/mysql/mysql_8306/tmp/mysql_8306.sock Enter password: [root@my1 local]# # 查看 /usr/local/mysql/bin/mysql_config_editor print --all [root@my1 local]# alias mysql.8306.login='/usr/local/mysql/bin/mysql --defaults-file=/data/mysql/mysql_8306/my_8306.cnf --login-path=8306_localhost_login'
2.1.13、快捷關閉資料庫
[root@my1 local]#alias mysql.8306.stop='/usr/local/mysql/bin/mysqladmin --login-path=8306_localhost_login shutdown'
2.1.14、加入備忘錄
[root@my1 ~]# cat >>/root/.bashrc <<EOF alias mysql.8306.start='/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_8306/my_8306.cnf &' alias mysql.8306.login='/usr/local/mysql/bin/mysql --defaults-file=/data/mysql/mysql_8306/my_8306.cnf --login-path=8306_localhost_login' alias mysql.8306.stop='/usr/local/mysql/bin/mysqladmin --login-path=8306_localhost_login shutdown' EOF [root@my1 ~]# source /root/.bash_profile
2.1.15、備份腳本
[root@my1 ~]# cat /root/all_database.sh #!/bin/bash /usr/local/mysql/bin/mysqldump --login-path=8306_localhost_login -R -E --triggers -e --max_allowed_packet=16777216 --net_buffer_length=16384 --master-data=2 --single-transaction --all-databases --quick | gzip >/root/all_database_bak_`date +%Y-%m-%d_%H_%M_%S`.sql.gz [root@my1 ~]#
2.2、主機M2上的操作
2.2.1、安裝依賴包
yum clean all yum -y update yum -y install gcc gcc-c++ make autoconf automake ncurses-devel bison ncurses cmake libaio libaio-devel boost yum -y install gcc-c++ gd libxml2-devel libjpeg-devel libpng-devel net-snmp-devel wget telnet vim zip unzip yum -y install curl-devel libxslt-devel pcre-devel libjpeg libpng libcurl4-openssl-dev yum -y install libcurl-devel libcurl freetype-config freetype freetype-devel unixODBC libxslt yum -y install gcc automake autoconf libtool openssl-devel yum -y install perl-devel perl-ExtUtils-Embed yum -y install cmake ncurses-devel.x86_64 openldap-devel.x86_64 lrzsz openssh-clients gcc-g77 bison yum -y install libmcrypt libmcrypt-devel mhash mhash-devel bzip2 bzip2-devel yum -y install ntpdate rsync svn patch iptables iptables-services yum -y install libevent libevent-devel cyrus-sasl cyrus-sasl-devel yum -y install gd-devel libmemcached-devel memcached git libssl-devel libyaml-devel auto make yum -y groupinstall "Server Platform Development" "Development tools" yum -y groupinstall "Development tools"
2.2.2、下載安裝
rm -rf /etc/my.cnf mkdir -p /opt/mysql cd /opt/mysql/ wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz tar -zxf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz cd /usr/local/ ln -s /opt/mysql/mysql-5.7.20-linux-glibc2.12-x86_64 mysql
2.2.3、創建所需要的目錄
mkdir -p /data/mysql/mysql_8306/{data,logs,tmp}
2.2.4、更改許可權
groupadd mysql
useradd -g mysql mysql -d /home/mysql -s /sbin/nologin
2.2.5、創建my.cnf
cat >/data/mysql/mysql_8306/my_8306.cnf <<EOF #my.cnf [client] port = 8306 socket = /data/mysql/mysql_8306/tmp/mysql_8306.sock [mysql] #prompt="\u@\h:\p \R:\m:\s [\d]>" #tee=/data/mysql/mysql_8306/data/query.log #prompt="\u@\h:\p \R:\m:\s [\d]>" prompt = "[\u@\h][\d]>\_" connect_timeout = 5 no-auto-rehash [mysqld] #misc user = mysql basedir = /usr/local/mysql datadir = /data/mysql/mysql_8306/data port = 8306 socket = /data/mysql/mysql_8306/tmp/mysql_8306.sock #timeout interactive_timeout = 300 wait_timeout = 300 #character set character-set-server = utf8 open_files_limit = 65535 max_connections = 100 max_connect_errors = 100000 skip-name-resolve = 1 #logs log-output=file slow_query_log = 1 slow_query_log_file = /data/mysql/mysql_8306/logs/slow.log log-error = /data/mysql/mysql_8306/logs/error.log log_error_verbosity = 3 pid-file = mysql.pid long_query_time = 1 #log-slow-admin-statements = 1 #log-queries-not-using-indexes = 1 log-slow-slave-statements = 1 #tmp tmpdir=/data/mysql/mysql_8306/tmp event_scheduler = 1 performance_schema = on max_allowed_packet = 32M character_set_server = utf8mb4 #character_set_server = utf8 default-time-zone = system default-storage-engine = InnoDB #bind_address = 172.16.151.248 explicit_defaults_for_timestamp = 1 #binlog binlog_format = row server-id = 1818306 log-bin = /data/mysql/mysql_8306/logs/mysql-bin log-bin-index = /data/mysql/mysql_8306/logs/mysql-bin.index binlog_cache_size = 4M max_binlog_size = 1G max_binlog_cache_size = 2G sync_binlog = 0 expire_logs_days = 90 #replicate-wild-ignore-table=mysql.% replicate-wild-ignore-table=test.% replicate-wild-ignore-table=information_schema.% #relay log skip_slave_start = 1 max_relay_log_size = 1G relay_log_purge = 1 relay_log_recovery = 1 log_slave_updates #slave-skip-errors=1032,1053,1062 explicit_defaults_for_timestamp=1 #buffers & cache table_open_cache = 2048 table_definition_cache = 2048 table_open_cache = 2048 max_heap_table_size = 96M sort_buffer_size = 2M join_buffer_size = 2M thread_cache_size = 256 query_cache_size = 0 query_cache_type = 0 query_cache_limit = 256K query_cache_min_res_unit = 512 thread_stack = 192K tmp_table_size = 96M key_buffer_size = 8M read_buffer_size = 2M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 32M #myisam myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 #innodb innodb_buffer_pool_size = 10G innodb_buffer_pool_instances = 1 innodb_data_file_path = ibdata1:1G:autoextend innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 64M innodb_log_file_size = 500M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 50 innodb_file_per_table = 1 innodb_rollback_on_timeout innodb_status_file = 1 innodb_io_capacity = 2000 transaction_isolation = READ-COMMITTED innodb_flush_method = O_DIRECT gtid_mode = ON enforce_gtid_consistency = ON master_info_repository = TABLE relay-log-info-repository = TABLE binlog_checksum = NONE log_slave_updates = ON # Two-Master configure #server-1 #auto-increment-offset = 1 #auto-increment-increment = 2 #server-2 auto-increment-offset = 2 auto-increment-increment = 2 # semi sync replication settings # plugin_dir = /usr/local/mysql/lib/plugin #官方版本的路徑 #plugin_dir = /usr/local/mysql/lib/mysql/plugin plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" #官方版本的路徑 #plugin_load = "validate_password.so;rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" loose_rpl_semi_sync_master_enabled = on loose_rpl_semi_sync_master_timeout = 5000 loose_rpl_semi_sync_master_trace_level = 32 loose_rpl_semi_sync_master_wait_no_slave = on loose_rpl_semi_sync_slave_enabled = on loose_rpl_semi_sync_slave_trace_level = 32 loose_rpl_semi_sync_master_enabled = 1 loose_rpl_semi_sync_slave_enabled = 1 loose_rpl_semi_sync_master_timeout = 5000 loose_rpl_semi_sync_master_wait_for_slave_count=1 loose_rpl_semi_sync_master_wait_point=AFTER_SYNC slave_preserve_commit_order = 1 slave_transaction_retries = 128 log_timestamps = system show_compatibility_56 = on slave_parallel_workers = 16 slave_parallel_type = LOGICAL_CLOCK loose_innodb_numa_interleave = 1 innodb_buffer_pool_dump_pct = 40 innodb_page_cleaners = 16 innodb_undo_log_truncate = 1 innodb_max_undo_log_size = 2G innodb_purge_rseg_truncate_frequency = 128 #transaction_write_set_extraction = MURMUR32 # group replication ##log-bin = mysql ##server-id = 618306 ##gtid_mode = ON ##enforce_gtid_consistency = ON ##master_info_repository = TABLE ##relay-log-info-repository = TABLE ##binlog_checksum = NONE ##log_slave_updates = ON ##binlog_format = row ##transaction_write_set_extraction=XXHASH64 ##loose-group_replication_group_name = '3db33b36-0e51-409f-a61d-c99756e90154' ##loose-group_replication_start_on_boot = off ##loose-group_replication_local_address= "10.125.141.62:28306" # 不能超過5位數字 ##loose-group_replication_group_seeds= "10.125.141.62:28306,10.125.141.62:23307,10.125.141.62:23308" # 不能超過5位數字 ##loose-group_replication_bootstrap_group= off # loose-group_replication_single_primary_mode=FALSE ###本次搭建的是mutil_mode # loose-group_replication_enforce_update_everywhere_checks= TRUE [mysqld_safe] #malloc-lib=/usr/local/mysql/lib/jmalloc.so nice=-19 open-files-limit=65535 EOF
2.2.6、修改目錄許可權
chown -R mysql.mysql /data/mysql/
2.2.7、初始化
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_8306/my_8306.cnf --initialize-insecure &
2.2.8、啟動
# /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_8306/my_8306.cnf & # 推薦的啟動方式 /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_8306/my_8306.cnf &
2.2.9、登陸方式
/usr/local/mysql/bin/mysql -uroot -p -P8306 -S /data/mysql/mysql_8306/tmp/mysql_8306.sock
或者
/usr/local/mysql/bin/mysql -P8306 -S /data/mysql/mysql_8306/tmp/mysql_8306.sock
2.2.10、創建授權修改密碼
set sql_log_bin = 0; create user 'rpl_user'@'%'; grant replication slave on *.* to 'rpl_user'@'%' identified by 'rpl_user2017'; update mysql.user set authentication_string=password('root2017') where user='root'; flush privileges; set sql_log_bin = 1; reset master ; reset slave all;
2.2.11、change master
CHANGE MASTER TO MASTER_HOST='172.16.210.180',MASTER_USER='rpl_user', MASTER_PASSWORD='rpl_user2017',MASTER_PORT=8306, MASTER_CONNECT_RETRY=10,MASTER_AUTO_POSITION =1; start slave; show slave status\G;
2.2.12、設置快捷登陸方式
[root@my2 local]# /usr/local/mysql/bin/mysql_config_editor set --host=localhost --login-path=8306_localhost_login \ > --user=root --port=8306 --password --socket=/data/mysql/mysql_8306/tmp/mysql_8306.sock Enter password: [root@my2 local]# # 查看 /usr/local/mysql/bin/mysql_config_editor print --all [root@my2 local]# alias mysql.8306.login='/usr/local/mysql/bin/mysql --defaults-file=/data/mysql/mysql_8306/my_8306.cnf --login-path=8306_localhost_login'
2.2.13、快捷關閉資料庫
[root@my2 local]#alias mysql.8306.stop='/usr/local/mysql/bin/mysqladmin --login-path=8306_localhost_login shutdown'
2.2.14、加入備忘錄
[root@my2 ~]# cat >>/root/.bashrc <<EOF alias mysql.8306.start='/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_8306/my_8306.cnf &' alias mysql.8306.login='/usr/local/mysql/bin/mysql --defaults-file=/data/mysql/mysql_8306/my_8306.cnf --login-path=8306_localhost_login' alias mysql.8306.stop='/usr/local/mysql/bin/mysqladmin --login-path=8306_localhost_login shutdown' EOF [root@my2 ~]# source /root/.bash_profile
2.2.15、備份腳本
[root@my2 ~]# cat /root/all_database.sh #!/bin/bash /usr/local/mysql/bin/mysqldump --login-path=8306_localhost_login -R -E --triggers -e --max_allowed_packet=16777216 --net_buffer_length=16384 --master-data=2 --single-transaction --all-databases --quick | gzip >/root/all_database_bak_`date +%Y-%m-%d_%H_%M_%S`.sql.gz [root@my2 ~]#
三、驗證同步情況
3.1、在my1中操作
[root@my1 ~]# mysql.8306.login Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.20-log MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. [root@localhost][(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows