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

时间:2021-08-06 05:20:16

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).sql

# 记录下主库的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.%

[root@newcms:/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
max_write_lock_count                                        = 300
wait_timeout                                                = 120
interactive_timeout                                         = 120
net_read_timeout                                            = 120
net_write_timeout                                           = 120

max_connections                                             = 800
max_user_connections                                        = 750
max_connect_errors                                          = 10000
max_allowed_packet                                          = 512M
back_log                                                    = 2048
log_timestamps                                              = system
performance_schema                                          = 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--------------------------------#
myisam_recover_options                                      = DEFAULT
bulk_insert_buffer_size                                     = 64M
myisam_sort_buffer_size                                     = 128M
myisam_max_sort_file_size                                   = 512M
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
sql-mode                                                    = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
#sql-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_schema
replicate-ignore-db                                         = performance_schema
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_schema.%
replicate_wild_ignore_table                                 = performance_schema.%
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
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
max_allowed_packet                                          = 512M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#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;

# sql 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 task_user_write@"%" identified by "pass";

centos6.10中部署percona-mysql双实例的方法的更多相关文章

  1. Mysql multi实现mysql双实例

    Mysql multi实现mysql双实例 1.添加mysql用户 以root登录,新建mysql用户组 groupadd mysql useradd -d /data/mariadb -g mysq ...

  2. centos6&period;5中部署Zeppelin并配置账号密码验证

    centos6.5中部署Zeppelin并配置账号密码验证1.安装JavaZeppelin支持的操作系统如下图所示.在安装Zeppelin之前,你需要在部署的服务器上安装Oracle JDK 1.7或 ...

  3. MyEclipse 10 中安装Android ADT 22插件的方法

    MyEclipse 10 中安装Android ADT 22插件的方法 下载ADT包:http://dl.google.com/android/ADT-22.0.0.zip 将ADT-22.0.0.z ...

  4. CentOS6&period;5中部署java web环境

    原来在linux中部署java web环境,没有做好总结,这次在部署的过程中,将部署的过程做了记录,希望对大家有帮助.主要内容包括CentOS安装以后的网络设置,系统自带jdk的卸载,新版本jdk的安 ...

  5. MYSQL多实例配置方法 mysqld&lowbar;multi方法

    在实际的开发过程中,可能会需要在一台服务器上部署多个MYSQL实例,那建议使用MYSQL官方的解决方案 mysqld_multi 1.修改my.cnf 如一个定义两个实例的参考配置: [mysqld_ ...

  6. MySql 双实例安装

    1.官网下载压缩包 https://dev.mysql.com/downloads/mysql/ 2.解压到D盘 3.修改my.ini 文件 [mysql] # 设置mysql客户端默认字符集 def ...

  7. 在Ubuntu14&period;10中部署Hadoop2&period;6&period;0单节点伪分布集群

    1. 环境信息如下: ubuntu:14.10 jdk:openjdk-1.7.0 hadoop:2.6.0 2. 下载hadoop2.6.0, http://apache.fayea.com/had ...

  8. CentOS6&period;7安装部署之Tomcat多实例

    Tomcat单机多实例配置 操作前的准备:关闭防火墙,配置好IP地址,安装好JAVA环境 1.首先创建tomcat所有实例共同的工作目录/data/webapps以及tomcat所有实例的所在目录/d ...

  9. Winform中只运行运行一个实例的方法

    在Program类的main方法按如下代码编写即可 1 static void Main() 2 { 3 if (Process.GetProcessesByName(Process.GetCurre ...

随机推荐

  1. Oracle 9 - 分析undo和snapshot too old错误

    什么操作会生成undo INSERT生成的UNDO最少,只要记录新的rowid UPDATE生成的undo多一点,它要记录修改前的数据中的那部分. DELETE生成最多的undo, 因为它要记录整行被 ...

  2. 图片轮换cycle插件的运用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. python运维开发&lpar;十七&rpar;----jQuery续&lpar;示例&rpar;web框架django

    内容目录: jQuery示例 前端插件 web框架 Django框架 jQuery示例 dom事件绑定,dom绑定在form表单提交按钮地方都会绑定一个onclick事件,所有查看网站的人都能看到代码 ...

  4. C&num;中抽象类与接口的区别

    1.面向接口编程和面向对象编程是什么关系 首先,面向接口编程和面向对象编程并不是平级的,它并不是比面向对象编程更先进的一种独立的编程思想,而是附属于面向对象思想体系,属于其一部分.或者说,它是面向对象 ...

  5. 11 Django REST Framework 针对基于类的视图添加 &commat;csrf&lowbar;exempt

    01-在类的 dispatch 方法上使用 @csrf_exempt from django.views.decorators.csrf import csrf_exempt class MyView ...

  6. Django(二)路由系统、视图、模板

    大纲 一.内容概要: 二.上节回顾 三.Django 视图–views  1.获取用户多个数据及文件上传  2.FBV 和 CBV  3.装饰器 四.Django模板补充  - Django模板语言循 ...

  7. 基于openssl搭建https服务器

    1. 搭建web环境 我这里使用源码编译安装方式安装httpd.详情可以参加我的一篇博客http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_1 ...

  8. js中session操作

    // 保存数据到sessionStorage sessionStorage.setItem('key', 'value');   // 从sessionStorage获取数据 var data = s ...

  9. 跟angular2学一键开启项目--关于上个react-redux项目的一键调试

    一键调试类似于webpack的hot-loader,但是这个hot-loader并不怎么好用,想省事的同学可以配置一下就完了. 今天介绍browser-sync,用它来一键开启项目.它可以监听任意文件 ...

  10. web集成高德地图

    1.使用高德地图API需到官网添加一个Key,http://lbs.amap.com/dev/key/app 2.页面头引入 <div id="addressMap"> ...