CentOS   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了centos6.10中部署percona-mysql双实例的方法大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

centos6.10中部署percona-mysql双实例的方法 数据库的同步关系:192.168.11.53(master) --> slave(192.168.10.189) --> task slave:3307(192.168.11.53) 1.新增配置文件 2.使用新的配置文件初始化数据库 3.启动数据库 4.升级root密码并新增task系统的用户 背景:cms内容管理系统和task任

centos6.10中部署percona-MysqL双实例的方法

数据库的同步关系:192.168.11.53(master) --> slave(192.168.10.189) --> task slave:3307(192.168.11.53)

1.新增配置文件
2.使用新的配置文件初始化数据库
3.启动数据库
4.升级root密码并新增task系统的用户


背景:cms内容管理系统和task任务发布系统(即把html/css/js/图片内容发布到海外的系统)在同一台服务器中

使用相同的MysqL数据库实例,不同数据库

观察发现系统做了大量的关于task系统的查询,耗费了数据库性能

为了避免task和cmsx不相互影响,启用新的MysqL实例,将数据库剥离开

不同的应用使用不同的数据库实例


即在cms服务器中同时启动监听 3306 和 3307 的MysqL数据库


一、启动新的3307示例,并把task作为192.168.10.189的slave

1.将目标数据库task从 192.168.10.189 从库中备份出来,并记录position作为新实例同步依据
MysqLdump -uroot -p -S /tmp/MysqL.sock -B -F -R --skip-add-locks --single-transaction --triggers --routInes --events --skip-tz-utc task > /opt/task_$(date +%F).@L_450_27@

# 记录下主库的position
MysqL> show master status;
+------------------+-----------+--------------+------------------+-------------------+
| File             | Position  | binlog_Do_DB | binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+-----------+--------------+------------------+-------------------+
| MysqL-bin.000532 | 100722038 |              |                  |                   |
+------------------+-----------+--------------+------------------+-------------------+
1 row in set (0.00 seC)

2.启动新的实例,并导入task数据库
新增数据库配置(启动3307端口使用的配置)
注意:需要将不同步的数据库排除:
Replicate-ignore-db                                         = MysqL
Replicate_wild_ignore_table                                = MysqL.%

[[email protected]:/usr/local/MysqL-sniffer]# cat /etc/my_3307.cnf
# Example MysqL config file for medium systems.
# 8核 16G
# This is for a system with little memory (16G) where MysqL plays
[client]
#password       = your_password
port                                                        = 3307
socket                                                      = /tmp/MysqL3307.sock

# The MysqL server
[MysqLd]
user                                                        = MysqL
port                                                        = 3307
bind-address                                                = 0.0.0.0
socket                                                      = /tmp/MysqL3307.sock
datadir                                                     = /data/MysqL_data_3307
pid-file                                                    = /data/MysqL_data_3307/MysqL.pid
basedir                                                     = /usr/local/MysqL3307
tmpdir                                                      = /tmp

#此开关认为NULL,即不允许导入导出。
#secure-file-priv                                           = /opt/upload

#-------------------------------gobal variables------------------------#
#关闭,涉及到timestamp类型的列自动更新的问题
explicit_defaults_for_timestamp                 = 1
###transaction_write_set_extraction              = XXHASH64  #以便在server收集写集合的同时将其记录到二进制日志。并且是行更改后的唯一标识此标识将用于检测冲突。
###loose-group_Replication_group_name            = ‘ce9be252-2b71-11e6-b8f4-00212889f856‘ #组的名字可以随便起,但不能用主机的GTID
###loose-group_Replication_start_on_boot         = off  #为了避免每次启动自动引导具有相名称的第二个组,所以设置为OFF。
###loose-group_Replication_bootstrap_group       = off #同上
###loose-group_Replication_local_address         = ‘192.168.1.88:33071‘ #写自己主机所在IP
###loose-group_Replication_group_seeds           =‘192.168.1.88:33071,192.168.1.89:33071,192.168.1.90:33071‘
###loose-group_Replication_single_priMary_mode   = off  #关闭单主模式的参数
###loose-group_Replication_enforce_update_everywhere_checks = on #开启多主模式的参数

skip-external-locking
skip-name-resolve
skip-ssl

#memory is 16G
key_buffer_size                                             = 32M
table_open_cache                                            = 2048
table_deFinition_cache                                      = 1024
sorT_Buffer_size                                            = 4M
neT_Buffer_length                                           = 32K
read_buffer_size                                            = 4M
read_rnd_buffer_size                                        = 16M

open_files_limit                                            = 10000
thread_cache_size                                           = 400
query_cache_type                                            = 0
query_cache_size                                            = 32M@H_679_19@max_write_lock_count                                        = 300
wait_timeout                                                = 120
interactive_timeout                                         = 120
net_read_timeout                                            = 120
net_write_timeout                                           = 120
@H_679_19@max_connections                                             = 800@H_679_19@max_user_connections                                        = 750@H_679_19@max_connect_errors                                          = 10000@H_679_19@max_allowed_packet                                          = 512M
BACk_log                                                    = 2048
log_timestamps                                              = system
perfoRMANce_scheR_195_11845@a                                          = OFF
character_set_server                                        = utf8mb4

##当链接数耗尽后,通过设置别用端口,让root可以登录
extra_max_connections                                       = 2
extra_port                                                  = 13307

###让MysqL不区分大小写敏感
lower_case_table_names                                      = 1

#explicit_defaults_for_timestamp                            = 1

#----------------Myisam--------------------------------#@H_679_19@myisam_recover_options                                      = DEFAULT
bulk_inserT_Buffer_size                                     = 64M@H_679_19@myisam_sorT_Buffer_size                                     = 128M@H_679_19@myisam_max_sort_file_size                                   = 512M@H_679_19@myisam_repair_threads                                       = 1

#if the query is exec time great than 2 seconds,the query will log to slow log if slowlog is enabled.
long_query_time                                             = 1
slow_query_log                                              = On
slow-query-log-file                                         = /data/MysqL_data_3307/slow.log
show_compatibility_56                                       = on

# Don‘t listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to MysqLd run on the same host.
# All interaction with MysqLd must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render MysqLd uSELEss!
#
#skip-networking

#----------------------------MysqL Log----------------#
# Replication Master Server (default)
# binary logging is required for Replication
log-bin                                                     = MysqL-bin
expire_logs_days                                            = 20
log_error                                                   = error.log
log_error_verbosity                                         = 1
log_warnings                                                = 1

# binary logging format - mixed recommended
binlog_format                                               = row
relay-log                                                   = MysqL-relay-bin
relay-log-index                                             = relay.index
# required unique id between 1 and 2^32 - 1
server-id                                                   = 1
@L_450_27@-mode                                                    = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
#@L_450_27@-mode                                                    = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
sync_binlog                                                 = 1
log_slave_updates                                           = 1
#binlog_checksum                                            = NONE

#------------------------------Replicate--------------#
#排除不需要同步的库表
Replicate-ignore-db                                        = MysqL
Replicate-ignore-db                                        = sys
Replicate-ignore-db                                         = information_scheR_195_11845@a
Replicate-ignore-db                                         = perfoRMANce_scheR_195_11845@a
Replicate-ignore-db                                         = undolog
Replicate-ignore-db                                         = for_nagios
Replicate-ignore-db                                         = undolog
Replicate-ignore-db                                         = akamai_task
Replicate-ignore-db                                         = bugfree
Replicate-ignore-db                                         = cart_jp
Replicate-ignore-db                                         = cms123
Replicate-ignore-db                                         = cms_com_br
Replicate-ignore-db                                         = cms_com_mx
Replicate-ignore-db                                         = cms_de
Replicate-ignore-db                                         = cms_de_new
Replicate-ignore-db                                         = cms_es
Replicate-ignore-db                                         = cms_fr
Replicate-ignore-db                                         = cms_freecms
Replicate-ignore-db                                         = cms_global
Replicate-ignore-db                                         = cms_it
Replicate-ignore-db                                         = cms_traffic
Replicate-ignore-db                                         = cmscouponcode
Replicate-ignore-db                                         = cmsnet
Replicate-ignore-db                                         = cmsphoto
Replicate-ignore-db                                         = cmstask
Replicate-ignore-db                                         = ftp_db
Replicate-ignore-db                                         = pt_monitor
Replicate-ignore-db                                         = task_bak
Replicate-ignore-db                                         = test
Replicate-ignore-db                                         = ws_amvdb
Replicate-ignore-db                                         = ws_dm_device
Replicate-ignore-db                                         = ws_fantashow30
Replicate-ignore-db                                         = wsjp_cart

Replicate_wild_ignore_table                                = MysqL.%
Replicate_wild_ignore_table                                = sys.%
Replicate_wild_ignore_table                                 = information_scheR_195_11845@a.%
Replicate_wild_ignore_table                                 = perfoRMANce_scheR_195_11845@a.%
Replicate_wild_ignore_table                                 = undolog.%
Replicate_wild_ignore_table                                 = for_nagios.%
Replicate_wild_ignore_table                                 = undolog.%
Replicate_wild_ignore_table                                 = akamai_task.%
Replicate_wild_ignore_table                                 = bugfree.%
Replicate_wild_ignore_table                                 = cart_jp.%
Replicate_wild_ignore_table                                 = cms123.%
Replicate_wild_ignore_table                                 = cms_com_br.%
Replicate_wild_ignore_table                                 = cms_com_mx.%
Replicate_wild_ignore_table                                 = cms_de.%
Replicate_wild_ignore_table                                 = cms_de_new.%
Replicate_wild_ignore_table                                 = cms_es.%
Replicate_wild_ignore_table                                 = cms_fr.%
Replicate_wild_ignore_table                                 = cms_freecms.%
Replicate_wild_ignore_table                                 = cms_global.%
Replicate_wild_ignore_table                                 = cms_it.%
Replicate_wild_ignore_table                                 = cms_traffic.%
Replicate_wild_ignore_table                                 = cmscouponcode.%
Replicate_wild_ignore_table                                 = cmsnet.%
Replicate_wild_ignore_table                                 = cmsphoto.%
Replicate_wild_ignore_table                                 = cmstask.%
Replicate_wild_ignore_table                                 = ftp_db.%
Replicate_wild_ignore_table                                 = pt_monitor.%
Replicate_wild_ignore_table                                 = task_bak.%
Replicate_wild_ignore_table                                 = test.%
Replicate_wild_ignore_table                                 = ws_amvdb.%
Replicate_wild_ignore_table                                 = ws_dm_device.%
Replicate_wild_ignore_table                                 = ws_fantashow30.%
Replicate_wild_ignore_table                                 = wsjp_cart.%

#主主复制需要开启
#auto_increment_offset= 2
#auto_increment_increment= 2

#GTID模式复制,需要开启如下
#gtid_mode                                                  = ON
#enforce_gtid_consistency                                   = ON

#并发复制
slave-parallel-type                                         = LOGICAL_CLOCK
slave-parallel-workers                                      = 0@H_679_19@master_info_repository                                      = TABLE
relay_log_info_repository                                   = TABLE
relay_log_recovery                                          = ON

#跳过slave进程启动参数
#skip-slave-start

#如果实例为从库,则需要设置为on
#read_only                                                   = on

#skip-grant-tables

#--------------------------------------------------------innoDB------------#
innodb_rollBACk_on_timeout
# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir                                        = /data/MysqL_data_3307
innodb_data_file_path                                       = ibdata1:1G;ibdata2:1G:autoextend
innodb_log_group_home_dir                                   = /data/MysqL_data_3307
innodb_undo_directory                                       = /data/MysqL_data_3307/undolog/
innodb_undo_logs                                            = 128
innodb_undo_tablespaces                                     = 3

# You can set .._buffer_pool_size up to 50 - 80 %
#innodb_use_sys_malloc = 0
#innodb_page_size = 8192
innodb_buffer_pool_size                                     = 32G
innodb_buffer_pool_instances                                = 1
#innodb_additional_mem_pool_size = 8M

# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size                                        = 256M
innodb_log_buffer_size                                      = 64M
innodb_log_files_in_group                                   = 3
#每次事务提交时MysqL都会把log buffer的数据写入log file,并且flush(刷到磁盘)中去,该模式为系统
innodb_flush_log_at_trx_commit                              = 1
innodb_lock_wait_timeout                                    = 120
#启用独立表空间
innodb_file_per_table                                       = 1

#cpu是1颗8核的,那么可以设置
innodb_read_io_threads                                      = 8
innodb_write_io_threads                                     = 8

#认是0,则表示没有并发线程数限制,所有请求都会直接请求线程执行,当并发用户线程数量小于64,建议设置innodb_thread_concurrency=0,在大多数情况下,最佳的值是小于并接近虚拟cpu的个数
innodb_thread_concurrency                                   = 12
innodb_max_dirty_pages_pct                                  = 75
innodb_flush_method                                         = O_DIRECT

innodb_purge_threads                                        = 10
innodb_large_prefix                                         = 1

#参数待测试
#innodb_io_capacity                                         = 20000
#innodb_io_capacity_max                                     = 40000

#根据cpu核心数来设定
thread_pool_size                                            = 8
#thread_handling = pool-of-threads
thread_pool_oversubscribe                                   = 24

#thread_handling                             = pool-of-threads
thread_pool_stall_limit                                     = 100
thread_pool_max_threads                                     = 30

#解释: 在启动时把热数据加载到内存。
innodb_buffer_pool_load_at_startup                          = 1
#解释: 在关闭时把热数据dump到本地磁盘
innodb_buffer_pool_dump_at_shutdown                         = 1

##认是8M,如果一次insert数据量比较多的话,可以适当增加
innodb_autoextend_increment                                 = 32

[MysqLdump]
quick@H_679_19@max_allowed_packet                                          = 512M

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

[myisamchk]
#key_buffer_size = 20M
#sorT_Buffer_size = 20M
key_buffer_size                                             = 200M
sorT_Buffer_size                                            = 200M
read_buffer                                                 = 2M
write_buffer                                                = 2M

[MysqLd_safe]
#控制文件打开数的show global status like ‘open%file%‘;比较合适的设置:Open_files / open_files_limit * 100% <= 75%
open-files-limit                                            = 65535
log-error                                                   = /data/MysqL_data_3307/error.log

[MysqLhotcopy]
interactive-timeout


3.初始化并启动3307示例数据库
/usr/local/MysqL3307/bin/MysqLd --defaults-file=/etc/my_3307.cnf --initialize-insecure --user=MysqL --basedir=/usr/local/MysqL3307 --datadir=/data/MysqL_data_3307

nohup /usr/local/percona-server-5.7.24/bin/MysqLd_safe --defaults-file=/etc/my_3307.cnf &

4.导入task库到新实例中

5.启动主从同步 3307 的task --> 192.168.10.189(master)

MysqL> show master status;
+------------------+-----------+--------------+------------------+-------------------+
| File             | Position  | binlog_Do_DB | binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+-----------+--------------+------------------+-------------------+
| MysqL-bin.000532 | 100722038 |              |                  |                   |
+------------------+-----------+--------------+------------------+-------------------+

change master to master_host=‘192.168.10.189‘,master_user=‘rep‘,master_password=‘wsdb123‘,master_log_file=‘MysqL-bin.000532‘,master_log_pos=100722038;


# @L_450_27@ sHell命令行 下执行 关闭数据库的命令
# shutdown;


# 添加备份用户
GRANT RELOAD,PROCESS,SUPER,LOCK TABLES,ReplicatION CLIENT,create tableSPACE ON *.* TO ‘xtraBACkup‘@‘localhost‘ identified by ‘pass‘;
flush privileges;

# 新增只对127.0.0.1有权限的root链接账号
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘127.0.0.1‘ IDENTIFIED BY ‘pass‘ WITH GRANT OPTION;
flush privileges;

# 修改root用户密码
update MysqL.user set authentication_String = password(‘pass‘),password_expired = ‘N‘,password_last_changed = Now() where user = ‘root‘;

# 对单个数据库授权
grant SELEct,insert,update,delete on task.* to [email protected]"%" identified by "pass";

大佬总结

以上是大佬教程为你收集整理的centos6.10中部署percona-mysql双实例的方法全部内容,希望文章能够帮你解决centos6.10中部署percona-mysql双实例的方法所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。