设为首页 收藏本站
查看: 362|回复: 0

[经验分享] mysql 主从配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-6-8 09:13:19 | 显示全部楼层 |阅读模式
                      近期部分机器要求做主从,之前都是每天定时全备份,但是影响到线上服务。所以对部分活跃的服务器做了主从,解决mysql备份的时候导致玩家卡壳问题。
slave 物理机,多实例,一台物理机基本开到6个实例。

master配置文件  my.cnf


[client]
port                = 3306
socket                = /log/mysql/mysql.sock

[mysqld]
skip-name-resolve = ON
port                = 3306
#bind-address    = 127.0.0.1

log-error        = /log/mysql/mysqld.log
pid-file         = /log/mysql/mysqld.pid
socket           = /log/mysql/mysql.sock
datadir          = /data/mysql

slow-query_log   = ON
slow_query_log_file   = /log/mysql/slow.log
long_query_time = 1

back_log = 512
max_connections = 16384
max_connect_errors = 100
interactive_timeout = 86400
wait_timeout = 86400
table_cache = 65535
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 5461
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
memlock
thread_stack = 192K
tmp_table_size = 64M

skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 16M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

#skip-networking

server-id       = 1
log-bin         = /data/bin_log/3306/mysql-bin-3306
max_binlog_size = 256M
log-slave-updates = 0
expire_logs     = 7
binlog_format   = "MIXED"

innodb_buffer_pool_size = 8G
innodb_additional_mem_pool_size = 20M
innodb_data_file_path = ibdata1:1G:autoextend
innodb_autoextend_increment = 500M
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 3
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_thread_concurrency = 16
innodb_data_home_dir  = /data/mysql
innodb_log_group_home_dir = /data/mysql
innodb_open_files = 65535

[mysqldump]
quick
max_allowed_packet = 64M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
open-files-limit = 65535
pid-file         = /log/mysqlmysqld.pid

slave配置文件  my.cnf
[client]
port                = 3306
#socket                = /log/mysql/mysql.sock

[mysqld_multi]
mysqld = /app/mysql/bin/mysqld_safe
mysqladmin = /app/mysql/bin/mysqladmin
log = /log/mysql/mysqld_multi.log
user = admin
password = admin

[mysqld3306]
skip-name-resolve = ON
port                = 3306
#bind-address    = 127.0.0.1
basedir          = /app/mysql

log-error        = /log/mysql/3306/mysqld.log
pid-file         = /log/mysql/3306/mysqld.pid
socket           = /log/mysql/3306/mysql.sock
datadir          = /data/mysql/3306

slow-query_log   = ON
slow_query_log_file   = /log/mysql/3306/slow.log
long_query_time = 1

back_log = 512
max_connections = 16384
max_connect_errors = 100
interactive_timeout = 86400
wait_timeout = 86400
table_cache = 65535
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 5461
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
memlock
thread_stack = 192K
tmp_table_size = 64M

skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 16M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

#skip-networking

server-id       = 2
replicate-wild-ignore-table=mysql.%
#log-bin         = /data/mysql/3306/bin-log/mysql-bin-3306
#max_binlog_size = 256M
#binlog_cache_size       = 128k
#binlog-ignore           = mysql
#log-slave-updates = 0
#expire_logs     = 7
#binlog_format   = "MIXED"

innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 20M
innodb_data_file_path = ibdata1:1G:autoextend
innodb_autoextend_increment = 500M
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 3
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_thread_concurrency = 16
innodb_data_home_dir  = /data/mysql/3306
innodb_log_group_home_dir = /data/mysql/3306
innodb_open_files = 65535
innodb_file_per_table = 1

[mysqld3307]
skip-name-resolve = ON
port                = 3307
#bind-address    = 127.0.0.1
basedir          = /app/mysql

log-error        = /log/mysql/3307/mysqld.log
pid-file         = /log/mysql/3307/mysqld.pid
socket           = /log/mysql/3307/mysql.sock
datadir          = /data/mysql/3307

slow-query_log   = ON
slow_query_log_file   = /log/mysql/3307/slow.log
long_query_time = 1

back_log = 512
max_connections = 16384
max_connect_errors = 100
interactive_timeout = 86400
wait_timeout = 86400
table_cache = 65535
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 5461
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
memlock
thread_stack = 192K
tmp_table_size = 64M

skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 16M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

#skip-networking

server-id       = 2
replicate-wild-ignore-table=mysql.%
#log-bin         = /data/mysql/3307/bin-log/mysql-bin-3307
#max_binlog_size = 256M
#binlog_cache_size       = 128k
#binlog-ignore           = mysql
#log-slave-updates = 0
#expire_logs     = 7
#binlog_format   = "MIXED"

innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 20M
innodb_data_file_path = ibdata1:1G:autoextend
innodb_autoextend_increment = 500M
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 3
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_thread_concurrency = 16
innodb_data_home_dir  = /data/mysql/3307
innodb_log_group_home_dir = /data/mysql/3307
innodb_open_files = 65535
innodb_file_per_table = 1


[mysqld3308]
skip-name-resolve = ON
port                = 3308
#bind-address    = 127.0.0.1
basedir          = /app/mysql

log-error        = /log/mysql/3308/mysqld.log
pid-file         = /log/mysql/3308/mysqld.pid
socket           = /log/mysql/3308/mysql.sock
datadir          = /data/mysql/3308

slow-query_log   = ON
slow_query_log_file   = /log/mysql/3308/slow.log
long_query_time = 1

back_log = 512
max_connections = 16384
max_connect_errors = 100
interactive_timeout = 86400
wait_timeout = 86400
table_cache = 65535
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 5461
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
memlock
thread_stack = 192K
tmp_table_size = 64M

skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 16M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

#skip-networking

server-id       = 2
replicate-wild-ignore-table=mysql.%
#log-bin         = /data/mysql/3306/bin-log/mysql-bin-3306
#max_binlog_size = 256M
#binlog_cache_size       = 128k
#binlog-ignore           = mysql
#log-slave-updates = 0
#expire_logs     = 7
#binlog_format   = "MIXED"

innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 20M
innodb_data_file_path = ibdata1:1G:autoextend
innodb_autoextend_increment = 500M
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 3
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_thread_concurrency = 16
innodb_data_home_dir  = /data/mysql/3308
innodb_log_group_home_dir = /data/mysql/3308
innodb_open_files = 65535
innodb_file_per_table = 1

[mysqld3309]
skip-name-resolve = ON
port                = 3309
#bind-address    = 127.0.0.1
basedir          = /app/mysql

log-error        = /log/mysql/3309/mysqld.log
pid-file         = /log/mysql/3309/mysqld.pid
socket           = /log/mysql/3309/mysql.sock
datadir          = /data/mysql/3309

slow-query_log   = ON
slow_query_log_file   = /log/mysql/3309/slow.log
long_query_time = 1

back_log = 512
max_connections = 16384
max_connect_errors = 100
interactive_timeout = 86400
wait_timeout = 86400
table_cache = 65535
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 5461
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
memlock
thread_stack = 192K
tmp_table_size = 64M

skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 16M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

#skip-networking

server-id       = 2
replicate-wild-ignore-table=mysql.%
#log-bin         = /data/mysql/3309/bin-log/mysql-bin-3309
#max_binlog_size = 256M
#binlog_cache_size       = 128k
#binlog-ignore           = mysql
#log-slave-updates = 0
#expire_logs     = 7
#binlog_format   = "MIXED"

innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 20M
innodb_data_file_path = ibdata1:1G:autoextend
innodb_autoextend_increment = 500M
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 3
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_thread_concurrency = 16
innodb_data_home_dir  = /data/mysql/3309
innodb_log_group_home_dir = /data/mysql/3309
innodb_open_files = 65535
innodb_file_per_table = 1

[mysqld3310]
skip-name-resolve = ON
port                = 3310
#bind-address    = 127.0.0.1
basedir          = /app/mysql

log-error        = /log/mysql/3310/mysqld.log
pid-file         = /log/mysql/3310/mysqld.pid
socket           = /log/mysql/3310/mysql.sock
datadir          = /data/mysql/3310

slow-query_log   = ON
slow_query_log_file   = /log/mysql/3310/slow.log
long_query_time = 1

back_log = 512
max_connections = 16384
max_connect_errors = 100
interactive_timeout = 86400
wait_timeout = 86400
table_cache = 65535
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 5461
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
memlock
thread_stack = 192K
tmp_table_size = 64M

skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 16M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

#skip-networking

server-id       = 2
replicate-wild-ignore-table=mysql.%
#log-bin         = /data/mysql/3310/bin-log/mysql-bin-3310
#max_binlog_size = 256M
#binlog_cache_size       = 128k
#binlog-ignore           = mysql
#log-slave-updates = 0
#expire_logs     = 7
#binlog_format   = "MIXED"

innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 20M
innodb_data_file_path = ibdata1:1G:autoextend
innodb_autoextend_increment = 500M
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 3
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_thread_concurrency = 16
innodb_data_home_dir  = /data/mysql/3310
innodb_log_group_home_dir = /data/mysql/3310
innodb_open_files = 65535
innodb_file_per_table = 1

[mysqld3311]
skip-name-resolve = ON
port                = 3311
#bind-address    = 127.0.0.1
basedir          = /app/mysql

log-error        = /log/mysql/3311/mysqld.log
pid-file         = /log/mysql/3311/mysqld.pid
socket           = /log/mysql/3311/mysql.sock
datadir          = /data/mysql/3311

slow-query_log   = ON
slow_query_log_file   = /log/mysql/3311/slow.log
long_query_time = 1

back_log = 512
max_connections = 16384
max_connect_errors = 100
interactive_timeout = 86400
wait_timeout = 86400
table_cache = 65535
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 5461
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
memlock
thread_stack = 192K
tmp_table_size = 64M

skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 16M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

#skip-networking

server-id       = 2
replicate-wild-ignore-table=mysql.%
#log-bin         = /data/mysql/3311/bin-log/mysql-bin-3311
#max_binlog_size = 256M
#binlog_cache_size       = 128k
#binlog-ignore           = mysql
#log-slave-updates = 0
#expire_logs     = 7
#binlog_format   = "MIXED"

innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 20M
innodb_data_file_path = ibdata1:1G:autoextend
innodb_autoextend_increment = 500M
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 3
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_thread_concurrency = 16
innodb_data_home_dir  = /data/mysql/3311
innodb_log_group_home_dir = /data/mysql/3311
innodb_open_files = 65535
innodb_file_per_table = 1

[mysqldump]
quick
max_allowed_packet = 64M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
open-files-limit = 65535
pid-file         = /log/mysqlmysqld.pid


从多实例我使用了 mysqld_multi

多实例启动脚本

#!/bin/sh  
#  
# A simple startup script for mysqld_multi by Tim Smith and Jani Tolonen.  
# This script assumes that my.cnf file exists either in /etc/my.cnf or  
# /root/.my.cnf and has groups [mysqld_multi] and [mysqldN]. See the  
# mysqld_multi documentation for detailed instructions.  
#  
# This script can be used as /etc/init.d/mysql.server  
#  
# Comments to support chkconfig on RedHat Linux  
# chkconfig: 2345 64 36  
# description: A very fast and reliable SQL database engine.  
#  
# Version 1.0  
#
basedir=/app/mysql
bindir=/app/mysql/bin
conf=/app/conf/mysql/my.cnf
export PATH=$PATH:$bindir
if test -x $bindir/mysqld_multi
then
  mysqld_multi="$bindir/mysqld_multi";
else
  echo "Can't execute $bindir/mysqld_multi from dir $basedir";
  exit;
fi
case "$1" in
    'start' )
        "$mysqld_multi" --defaults-extra-file=$conf start $2
        ;;
    'stop' )
        "$mysqld_multi" --defaults-extra-file=$conf stop $2
        ;;
    'report' )
        "$mysqld_multi" --defaults-extra-file=$conf report $2
        ;;
    'restart' )
        "$mysqld_multi" --defaults-extra-file=$conf stop $2
        "$mysqld_multi" --defaults-extra-file=$conf start $2
        ;;
    *)
        echo "Usage: $0 {start|stop|report|restart}" >&2
        ;;
esac

mysql初始化
/app/mysql/scripts/mysql_install_db --basedir=/app/mysql --datadir=/data/mysql/3311 --user=mysql

master同步用户权限设置
GRANT SUPER, REPLICATION SLAVE ON *.* TO 'sync'@'%' IDENTIFIED BY 'sync';
flush privileges;
多实例数据库关闭
grant shutdown on *.* to 'admin'@'localhost' identified by 'admin';
flush privileges;

根据master bin-log 点进行同步

CHANGE MASTER TO master_host='192.168.1.2',master_user='sync',master_password='sync',master_port=3306,master_log_file='mysql-bin-3306.000001',master_log_pos=2946738;
                   


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-74886-1-1.html 上篇帖子: 源码安装mysql5.6.20&&mysql主从设置(多实例做多个主从) 下篇帖子: Centos6.5 源码搭建MYSQL5.5+MySQL主从复制 mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表