MariaDB10.0執行個體部署和多源複製配置

來源:互聯網
上載者:User

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.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的好。

2、MariaDB的安裝部署
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
3、MariaDB的設定檔
這個設定檔適用於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
 
[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
4、資料庫初始化和啟動
資料庫初始化和啟動指令碼如下:
#/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  #加入到系統啟動項中
二、MariaDB多源複製相關配置
1、初始化資料庫使用者
初始化多源從庫的使用者,建議刪除初始所有使用者,建立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,線上的任何寫操作最好做好備份,給自己留個後路
2、備份多個主庫的資料庫
MariaDB的多源複製,要求各個同步主庫中的資料庫名字各不相同,備份的話只備份需要同步的資料庫即可,不需要同步的資料庫可以在多源的從庫中使用參數過濾掉,預設不會同步mysql、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 &
#放入後台備份
3、匯入備份資料
分別匯入各個主庫的備份資料導多源的從庫中,命令如下:
/data/mariadb/bin/mysql–uxxxx –pxxxxx db_name < db_name_20150320.sql &
4、建立主從關係
這裡重點在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_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:

更多詳情見請繼續閱讀下一頁的精彩內容:

--------------------------------------分割線 --------------------------------------

在 CentOS/RHEL/Scientific Linux 6 下安裝 LAMP (Apache with MariaDB and PHP)

MariaDB Proxy讀寫分離的實現

Linux下編譯安裝配置MariaDB資料庫的方法

CentOS系統使用yum安裝MariaDB資料庫

安裝MariaDB與MySQL並存

Ubuntu 上如何將 MySQL 5.5 資料庫遷移到 MariaDB 10 

[翻譯]Ubuntu 14.04 (Trusty) Server 安裝 MariaDB  http://www.bkjia.com/Linux/2014-12/110048htm

  • 1
  • 2
  • 下一頁

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.