本博文出自Bkjia博客王偉博主,有任何問題請進入博主頁面互動討論!
博文地址:http://wangtianfa.blog.51cto.com/5281093/1621797
一、部署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 #加入到系統啟動項中