MariaDB10.0 實例部署和多源復制配置 一、部署 MariaDB10.0.17 1 、 MariaDB 下載和簡單說明 當前 MariaDB 支持多源復制的版本為 10.0 的版本,最新穩定版本為 10.0.17 ,下載連接為: http://mirrors.opencas.cn/mariadb/mariadb-10.0.17/source/mariadb-10
MariaDB10.0實例部署和多源復制配置
當前MariaDB支持多源復制的版本為10.0的版本,最新穩定版本為10.0.17,下載連接為:http://mirrors.opencas.cn/mariadb/mariadb-10.0.17/source/mariadb-10.0.17.tar.gz。MariaDB和PerconaDB在5.5的新版中引進來線程池和關閉NUMA的概念,對數據庫性能提高不少,而MySQL的版本在5.5.23(貌似是)以上的版本中也有這個概念,但是是屬于企業版的功能,開源版本中沒有這個功能;MariaDB10的版本中多了一個新功能就是多源復制,對于一些特殊的場景比較實用:如sharding過的表做數據匯總等,一般對匯總統計比較有用。
注:新的版本固然有很多吸引人的地方,但是其中的坑還沒有挖完,有問題的話不易查找材料,不易于解決,所以不建議生產環境使用最新的版本。目前MySQL、PerconaDB和MariaDB主流版本是5.5,如果非特殊需要,5.5的足夠用,拋開線程池來說,5.6的版本在整體的性能上未必比5.5的好。
MariaDB和MySQL、Percona的基本上完全一樣,5.5以后的版本采用cmake的方式編譯安裝:
#tar –zxfmariadb-10.0.17.tar.gz
#cdmariadb-10.0.17
#cmake .-DCMAKE_INSTALL_PREFIX=/data/percona/ -DMYSQL_DATADIR=/data/percona/data-DSYSCONFDIR=/data/percona/etc -DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci-DMYSQL_UNIX_ADDR=/data/percona/tmp/mysql.sock -DENABLED_LOCAL_INFILE=ON-DENABLED_PROFILING=ON -DWITH_DEBUG=0 -DMYSQL_TCP_PORT=3306
#make&& make install
這個配置文件適用于PerconaDB,去掉線程池和NAMA的參數,同樣適用于MySQL:
[client]
port = 3306
socket = /data/mariadb/tmp/mysql.sock
default-character-set= utf8
[mysqld]
port = 3306
bind-address= 0.0.0.0
lower_case_table_names = 1
basedir = /data/mariadb
datadir = /data/mariadb/data
tmpdir = /data/mariadb/tmp
socket = /data/mariadb/tmp/mysql.sock
#######################################
log-output = FILE
log-error = /data/mariadb/log/error.log
#general_log
general_log_file = /data/mariadb/log/mysql.log
pid-file = /data/mariadb/data/mysql.pid
slow-query-log
slow_query_log_file = /data/mariadb/log/slow.log
tmpdir = /data/mariadb/tmp/
long_query_time = 0.1
#max_statement_time = 1000 #自動殺死超過1s的慢sql,PerconaDB5.6支持,不建議使用,如使用的和業務方溝通好,建議在特殊的情況動態配置使用,默認是0,不限制。
sync_binlog = 1
skip-external-locking
skip-name-resolve
default-storage-engine= INNODB
character-set-server= utf8
wait_timeout= 28400
back_log = 1024
#########################
thread_concurrency = 16
thread_cache_size = 512
table_open_cache = 16384
table_definition_cache = 16384
sort_buffer_size = 2M
join_buffer_size = 2M
read_buffer_size = 4M
read_rnd_buffer_size = 4M
key_buffer_size = 64M
myisam_sort_buffer_size= 64M
tmp_table_size = 256M
max_heap_table_size = 256M
open_files_limit = 65535
#####Network ######################
max_allowed_packet = 16M
interactive_timeout = 28400
wait_timeout = 28400
max-connections = 1000
max_user_connections = 0
max_connect_errors = 100
######Repl #####################
server-id = 1
report-host = 172.16.183.56
log-bin = mysql-bin
binlog_format = mixed
expire_logs_days = 7
relay-log = relay-log
#replicate-wild-do-table= zabbix.%
#replicate-wild-do-table= zabbix_server.%
replicate_wild_ignore_table=mysql.%
replicate_wild_ignore_table=test.%
log_slave_updates
skip-slave-start
#slave-net-timeout = 10
#rpl_semi_sync_master_enabled = 1
#rpl_semi_sync_master_wait_no_slave = 1
#rpl_semi_sync_master_timeout = 1000
#rpl_semi_sync_slave_enabled = 1
relay_log_recovery = 1
##### Innodb ###########
innodb_data_home_dir = /data/mariadb/data
innodb_data_file_path = ibdata1:2G;ibdata2:2G:autoextend
innodb_autoextend_increment = 500
innodb_log_group_home_dir = /data/mariadb/data
innodb_buffer_pool_size = 8G
innodb_buffer_pool_dump_at_shutdown= 1
innodb_buffer_pool_load_at_startup= 1
innodb_buffer_pool_instances = 8
innodb_additional_mem_pool_size= 128M
innodb_log_files_in_group = 3
innodb_log_file_size = 512M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 120
innodb_flush_method = O_DIRECT
innodb_max_dirty_pages_pct = 75
innodb_io_capacity = 1000
innodb_thread_concurrency = 0
innodb_thread_sleep_delay = 500
innodb_concurrency_tickets = 1000
innodb_open_files = 65535
innodb_file_per_table = 1
#########線程池,在高并發高負載情況下表現出出色的數據庫性能 ##
thread_handling = pool-of-threads
######NUMA #########################
innodb_buffer_pool_populate = 1
##################################
[mysqldump]
quick
max_allowed_packet= 16M
[mysql]
no-auto-rehash
default-character-set=utf8
prompt = "MySQL \u@[\d]>"
[myisamchk]
key_buffer_size= 256M
sort_buffer_size= 256M
read_buffer= 2M
write_buffer= 2M
[mysqld_safe]
######CLOSED NUMA ###########
flush_caches
numa_interleave
[mysqlhotcopy]
interactive_timeout = 28400
數據庫初始化和啟動腳本如下:
#/data/mariadb/scripts/mysql_install_db--basedir=/data/mariadb --datadir=/data/mariadb/data --defaults-file=/data/mariadb/etc/my.cnf--user=mysql
#/data/mariadb/bin/mysqld_safe--defaults-file=/data/mariadb/etc/my.cnf --user=mysql &
#echo “/data/mariadb/bin/mysqld_safe--defaults-file=/data/mariadb/etc/my.cnf --user=mysql &”>>/etc/rc.local #加入到系統啟動項中
初始化多源從庫的用戶,建議刪除初始所有用戶,建立4個用戶:DBA root賬戶,備份用戶,監控用戶,主從同步用戶。
創建用戶的相關權限和命令如下:
#創建用戶
GRANT ALLPRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY IDENTIFIED BY '123456'WITH GRANT OPTION;
GRANTREPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'replicater'@'192.168.2.100'IDENTIFIED BY '123456';
GRANTSELECT, RELOAD, SHOW DATABASES, SUPER, LOCK TABLES, REPLICATION CLIENT, SHOWVIEW, EVENT ON *.* TO 'backup'@'localhost' IDENTIFIED BY '123456';
GRANTSELECT, PROCESS, SUPER, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO'monitor'@'127.0.0.1' IDENTIFIED BY '123456';
#刪除用戶建議使用dropuser xxxx@xxxxx;這樣刪除比較徹底。
作為DBA,線上的任何寫操作最好做好備份,給自己留個后路
MariaDB的多源復制,要求各個同步主庫中的數據庫名字各不相同,備份的話只備份需要同步的數據庫即可,不需要同步的數據庫可以在多源的從庫中使用參數過濾掉,默認不會同步information_schema、performance_schema。
備份命令如下:
/data/mariadb/bin/mysqldump--default-character-set=utf8 --hex-blob -R --log-error=/var/log/backup-log--single-transaction --master-data=2 -uxxxx -pxxxx –B db_name > db_name_20150320.sql &
#放入后臺備份
分別導入各個主庫的備份數據導多源的從庫中,命令如下:
/data/mariadb/bin/mysql–uxxxx –pxxxxx db_name < db_name_20150320.sql &
這里重點在connection_name,也就是在以前的語法上增加了connection_name,如果沒加connection_name,那么默認的就是空。connection_name為標識,主要是方便用于管理單個主從關系。建立主從關系的命令如下:
Mysql>changemaster 'percona' to master_host='192.168.2.100',MASTER_PORT=3307,master_user='repl', master_password='xxxxxxx',master_log_file='mysql-bin.000019', master_log_pos=120;
其中的percona為connection_name。每個源的同步一個connection_name,分別執行上述sql命令。
啟動主從同步的命令為:
Mysql>START SLAVE 'percona';
也可以在建立全部的同步關系后一起啟動:
Mysql>START ALL SLAVES;
停止單個同步的命令:
Mysql>STOP SLAVE 'percona';
停止全部的同步的命令為:
Mysql>STOP ALL SLAVES;
當同步建立并正常運行時,會產生relay-log,relay-log的名字為:relay-log-percona.000001,會自動的加上connection_name。
可以使用show all slaves status來查看所有的同步狀態,狀態信息如下:
MariaDB[(none)]> show all slaves status\G
***************************1. row ***************************
Connection_name: percona
Slave_SQL_State: Slave has readall relay log; waiting for the slave I/O thread to update it
Slave_IO_State: Waiting formaster to send event
Master_Host: 192.168.2.200
Master_User: repl
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000021
Read_Master_Log_Pos: 450752689
Relay_Log_File:relay-log-percona.000011
Relay_Log_Pos: 135537605
Relay_Master_Log_File: mysql-bin.000021
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table: mysql.%,test.%
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 450752689
Relay_Log_Space: 135537904
。。。。。。。。。。。。。。。。。。。。。。。。。。
Master_Server_Id: 111156
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Retried_transactions: 0
Max_relay_log_size: 1073741824
Executed_log_entries: 106216
Slave_received_heartbeats: 12
Slave_heartbeat_period: 1800.000
Gtid_Slave_Pos:
***************************2. row ***************************
Connection_name: percona
Slave_SQL_State: Slave has readall relay log; waiting for the slave I/O thread to update it
Slave_IO_State: Waiting formaster to send event
Master_Host: 192.168.2.201
Master_User: repl
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000021
Read_Master_Log_Pos: 450752689
Relay_Log_File:relay-log-percona.000011
Relay_Log_Pos: 135537605
Relay_Master_Log_File: mysql-bin.000021
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table: mysql.%,test.%
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 450752689
Relay_Log_Space: 135537904
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Master_Server_Id: 111156
Master_SSL_Crl:
Master_SSL_Crlp
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com