├── MySQL 入門 COSCUP Hands-on 2015.key ├── MySQL 入門 COSCUP Hands-on 2015.pdf ├── README.md ├── drbd.d ├── global_common.conf └── r0.res ├── heartbeat ├── authkeys ├── ha.cf ├── haresources └── resource.d │ └── mysql ├── mysql-heartbeat └── mysql └── my.cnf /MySQL 入門 COSCUP Hands-on 2015.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gslin/coscup2015-mysql-hands-on/a9193ed25a429e66258991528e49578c8fba3dd9/MySQL 入門 COSCUP Hands-on 2015.key -------------------------------------------------------------------------------- /MySQL 入門 COSCUP Hands-on 2015.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gslin/coscup2015-mysql-hands-on/a9193ed25a429e66258991528e49578c8fba3dd9/MySQL 入門 COSCUP Hands-on 2015.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | COSCUP 2015 Hands-on MySQL 入門 2 | 3 | * http://coscup2015.kktix.cc/events/handson-mysql 4 | 5 | * http://www.mobile01.com/topicdetail.php?f=506&t=4002081 6 | * http://www.mobile01.com/topicdetail.php?f=506&t=4002292 7 | * http://www.mobile01.com/topicdetail.php?f=506&t=4002571 8 | * http://www.mobile01.com/topicdetail.php?f=506&t=4004889 9 | -------------------------------------------------------------------------------- /drbd.d/global_common.conf: -------------------------------------------------------------------------------- 1 | # 2 | global { 3 | usage-count no; 4 | } 5 | 6 | common { 7 | protocol C; 8 | } 9 | -------------------------------------------------------------------------------- /drbd.d/r0.res: -------------------------------------------------------------------------------- 1 | # 2 | resource r0 { 3 | meta-disk internal; 4 | device /dev/drbd0; 5 | 6 | on db-drbd-1 { 7 | disk /dev/sda3; 8 | address 192.168.50.101:7789; 9 | } 10 | on db-drbd-2 { 11 | disk /dev/sda3; 12 | address 192.168.50.102:7789; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /heartbeat/authkeys: -------------------------------------------------------------------------------- 1 | # 2 | auth 1 3 | 1 md5 abcefghijklmnopqrstuvwxyz 4 | -------------------------------------------------------------------------------- /heartbeat/ha.cf: -------------------------------------------------------------------------------- 1 | # 2 | logfile /var/log/ha.log 3 | keepalive 2 4 | deadtime 10 5 | warntime 5 6 | initdead 20 7 | udpport 694 8 | auto_failback off 9 | ucast eth1 192.168.50.102 10 | node db-drbd-1 11 | node db-drbd-2 12 | -------------------------------------------------------------------------------- /heartbeat/haresources: -------------------------------------------------------------------------------- 1 | # 2 | db-drbd-1 MailTo::me+drbdfailover@gmail.com::HeartbeatFailover_db-drbd-float drbddisk::r0 Filesystem::/dev/drbd0::/srv::ext4::noatime,nodiratime mysql 192.168.50.103 3 | -------------------------------------------------------------------------------- /heartbeat/resource.d/mysql: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script is inteded to be used as resource script by heartbeat 4 | # 5 | # Mar 2006 by Monty Taylor 6 | # 7 | ### 8 | 9 | . /etc/ha.d/shellfuncs 10 | 11 | case "$1" in 12 | start) 13 | res=`/etc/init.d/mysql start` 14 | ret=$? 15 | ha_log $res 16 | exit $ret 17 | ;; 18 | stop) 19 | res=`/etc/init.d/mysql stop` 20 | ret=$? 21 | ha_log $res 22 | exit $ret 23 | ;; 24 | status) 25 | if [[ `ps -ef | grep '[m]ysqld'` > 1 ]] ; then 26 | echo "running" 27 | else 28 | echo "stopped" 29 | fi 30 | ;; 31 | *) 32 | echo "Usage: mysql {start|stop|status}" 33 | exit 1 34 | ;; 35 | esac 36 | 37 | exit 0 38 | -------------------------------------------------------------------------------- /mysql-heartbeat: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 沒有 my.cnf 的時候就不要檢查 4 | if [ ! -r /etc/mysql/my.cnf ]; then 5 | exit 6 | fi 7 | 8 | # 沒有 heartbeat 的時候就不要檢查 9 | if [ ! -r /etc/ha.d/ha.cf ]; then 10 | exit 11 | fi 12 | 13 | CL="$(/usr/bin/cl_status rscstatus 2>&1)" 14 | 15 | # DRBD 中只需要處理當 Heartbeat 確定拿到資源,但 mysql 沒起來的 case 16 | 17 | if /sbin/ifconfig -s | /usr/bin/awk '{print $1}' | /bin/grep : > /dev/null 2>&1; then 18 | if ! /bin/ps -U mysql | /bin/grep mysqld > /dev/null 2>&1; then 19 | /usr/share/heartbeat/hb_standby > /dev/null 2>&1 20 | fi 21 | fi 22 | -------------------------------------------------------------------------------- /mysql/my.cnf: -------------------------------------------------------------------------------- 1 | # 2 | [mysqld_safe] 3 | flush_caches 4 | numa_interleave 5 | # 6 | [mysqld] 7 | back_log = 65535 8 | binlog_format = ROW 9 | character_set_server = utf8mb4 10 | collation_server = utf8mb4_general_ci 11 | datadir = /var/lib/mysql 12 | default_storage_engine = InnoDB 13 | expand_fast_index_creation = 1 14 | expire_logs_days = 7 15 | innodb_autoinc_lock_mode = 2 16 | innodb_buffer_pool_instances = 16 17 | innodb_buffer_pool_populate = 1 18 | innodb_buffer_pool_size = 12G 19 | innodb_data_file_path = ibdata1:64M;ibdata2:64M:autoextend 20 | innodb_file_format = Barracuda 21 | innodb_file_per_table 22 | innodb_flush_log_at_trx_commit = 2 23 | innodb_flush_method = O_DIRECT 24 | innodb_io_capacity = 1600 25 | innodb_large_prefix 26 | innodb_locks_unsafe_for_binlog = 1 27 | innodb_log_file_size = 64M 28 | innodb_print_all_deadlocks = 1 29 | innodb_read_io_threads = 64 30 | innodb_stats_on_metadata = FALSE 31 | innodb_support_xa = FALSE 32 | innodb_write_io_threads = 64 33 | log-bin = mysqld-bin 34 | log-queries-not-using-indexes 35 | log-slave-updates 36 | long_query_time = 1 37 | max_allowed_packet = 64M 38 | max_connect_errors = 4294967295 39 | max_connections = 4096 40 | min_examined_row_limit = 1000 41 | performance-schema-instrument='%=ON' 42 | port = 3306 43 | relay-log-recovery = TRUE 44 | skip-name-resolve 45 | slow_query_log = 1 46 | slow_query_log_timestamp_always = 1 47 | table_open_cache = 4096 48 | thread_cache = 1024 49 | tmpdir = /srv/tmp 50 | transaction_isolation = READ-COMMITTED 51 | updatable_views_with_limit = 0 52 | user = mysql 53 | wait_timeout = 60 54 | --------------------------------------------------------------------------------