利用mysqld_multi启动管理多实例

利用mysqld_multi启动管理多实例

官方管理多实例的一个脚本peer

#将之前的目录清空

[[email protected] mysql]# tree /data/mysql/

/data/mysql/

├── mysql_3306

│   ├── data

│   ├── logs

│   ├── my3306.cnf

│   └── tmp

├── mysql_3307

│   ├── data

│   ├── logs

│   ├── my3307.cnf

│   └── tmp

└── yejr_3306

#3307目录规划

3306

/data/mysql/mysql_3306/{data,logs,tmp}

/data/mysql/mysql_3306/my3306.cnf

3307

/data/mysql/mysql_3307/{data,logs,tmp}

/data/mysql/mysql_3307/my3307.cnf

[[email protected] ~]# cat /etc/my.cnf

#my.cnf

[client]

port            = 3306

socket          = /tmp/mysql.sock

[mysql]

prompt="\\[email protected]\\h [\\d]>"

#pager="less -i -n -S"

#tee=/opt/mysql/query.log

no-auto-rehash

[mysqld_multi]

mysqld = /usr/local/mysql/bin/mysqld_safe

mysqladmin = /usr/local/mysql/bin/mysqladmin

log = /opt/mysql/mysqld_multi.log

user = mdev

password = mdev4admin

[mysqld]

#misc

user = mysql

basedir = /usr/local/mysql

datadir = /data/mysql/mysql_3306/data

port = 3306

socket = /tmp/mysql.sock

event_scheduler = 0

tmpdir = /data/mysql/mysql_3306/tmp

#timeout

interactive_timeout = 300

wait_timeout = 300

#character set

character-set-server = utf8

open_files_limit = 65535

max_connections = 100

max_connect_errors = 100000

#lower_case_table_names =1

#logs

log-output=file

slow_query_log = 1

slow_query_log_file = slow.log

log-error = error.log

log_warnings = 2

pid-file = mysql.pid

long_query_time = 1

#log-slow-admin-statements = 1

#log-queries-not-using-indexes = 1

log-slow-slave-statements = 1

#binlog

#binlog_format = STATEMENT

binlog_format = row

server-id = 23306

log-bin = /data/mysql/mysql_3306/logs/mysql-bin

binlog_cache_size = 4M

max_binlog_size = 256M

max_binlog_cache_size = 1M

sync_binlog = 0

expire_logs_days = 10

#procedure

log_bin_trust_function_creators=1

#

gtid-mode = 0

#relay log

skip_slave_start = 1

max_relay_log_size = 128M

relay_log_purge = 1

relay_log_recovery = 1

relay-log=relay-bin

relay-log-index=relay-bin.index

log_slave_updates

#slave-skip-errors=1032,1053,1062

#skip-grant-tables

#buffers & cache

table_open_cache = 2048

table_definition_cache = 2048

table_open_cache = 2048

max_heap_table_size = 96M

sort_buffer_size = 128K

join_buffer_size = 128K

thread_cache_size = 200

query_cache_size = 0

query_cache_type = 0

query_cache_limit = 256K

query_cache_min_res_unit = 512

thread_stack = 192K

tmp_table_size = 96M

key_buffer_size = 8M

read_buffer_size = 2M

read_rnd_buffer_size = 16M

bulk_insert_buffer_size = 32M

#myisam

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

#innodb

innodb_buffer_pool_size = 100M

innodb_buffer_pool_instances = 1

innodb_data_file_path = ibdata1:100M:autoextend

innodb_flush_log_at_trx_commit = 2

innodb_log_buffer_size = 8M

innodb_log_file_size = 100M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 50

innodb_file_per_table = 1

innodb_rollback_on_timeout

innodb_status_file = 1

innodb_io_capacity = 2000

transaction_isolation = READ-COMMITTED

innodb_flush_method = O_DIRECT

#端口号为3306的实例特殊配置

[mysqld3306]

port = 3306

datadir = /data/mysql/mysql_3306/data

tmpdir = /data/mysql/mysql_3306/tmp

log-bin = /data/mysql/mysql_3306/logs/mysql-bin

server-id = 1003306

socket = /tmp/mysql_3306.sock

#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置

innodb_buffer_pool_size = 500M

[mysqld3307]

port = 3307

datadir = /data/mysql/mysql_3307/data

tmpdir = /data/mysql/mysql_3307/tmp

log-bin = /data/mysql/mysql_3307/logs/mysql-bin

server-id = 1003307

socket = /tmp/mysql_3307.sock

#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置

innodb_buffer_pool_size = 500M

#对3306、3307进行初始化

/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3306/my3306.cnf --initialize

/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3307/my3307.cnf --initialize

#记住这个初始密码

cat /data/mysql/mysql_3306/data/error.log |grep password

2016-08-21T03:34:16.214559Z 1 [Note] A temporary password is generated for [email protected]: &%mh9C(jsbTF

cat /data/mysql/mysql_3307/data/error.log |grep password

2016-08-21T03:34:25.835638Z 1 [Note] A temporary password is generated for [email protected]: YMgbgJLkB9)r

#使用mysqld_multi启动方式二选一,均可启动:

mysqld_multi start 3306

mysqld_multi start 3307

/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3306/my3306.cnf &

/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3306/my3306.cnf &

#检查启动之后有无启动错误

cat /data/mysql/mysql_3306/data/error.log

cat /data/mysql/mysql_3307/data/error.log

mysql -S /tmp/mysql_3306.sock -p   #输入密码: &%mh9C(jsbTF

mysql -S /tmp/mysql_3307.sock -p   #输入密码: YMgbgJLkB9)r

#进入每个实例只有要修改密码并创建关闭账号

在mysql5.7里用户名与密码不能一样,否则会报错。

(unknown)@localhost [(none)]> alter user user() identified by ‘redhat‘;  #修改密码

[email protected] [(none)]> create user ‘mdev‘@‘localhost‘ identified by ‘mdev4admin‘;

[email protected] [(none)]> grant shutdown on *.* to ‘mdev‘@‘localhost‘;

[email protected] [(none)]>select user,host,authentication_string from mysql.user;

+-----------+-----------+-------------------------------------------+

| user      | host      | authentication_string                     |

+-----------+-----------+-------------------------------------------+

| root      | localhost | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |

| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |

| mdev      | localhost | *947A6520F0A2FD9A631D42B10246B03F392B35C2 |

+-----------+-----------+-------------------------------------------+

[email protected] [(none)]>flush privileges;

Query OK, 0 rows affected (0.00 sec)

[email protected] [(none)]>show grants for ‘mdev‘@localhost;

+---------------------------------------------+

| Grants for [email protected]                   |

+---------------------------------------------+

| GRANT SHUTDOWN ON *.* TO ‘mdev‘@‘localhost‘ |

+---------------------------------------------+

1 row in set (0.00 sec)

#手工验证密码关闭3306数据库

mysqladmin -S /tmp/mysql_3306.sock -p -u mdev shutdown   #输入密码 mdev4admin

mysqladmin -S /tmp/mysql_3307.sock -p -u mdev shutdown

#关闭3307数据库

mysqladmin -S /tmp/mysql_3306.sock -p shutdown

#因为必须加上-s,才能获取对应端口的密码。

[[email protected] ~]# my_print_defaults -s mysqld_multi mysqld3307

--mysqld=/usr/local/mysql/bin/mysqld_safe

--mysqladmin=/usr/local/mysql/bin/mysqladmin

--log=/opt/mysql/mysqld_multi.log

--user=mdev

--password=mdev4admin

--port=3307

--datadir=/data/mysql/mysql_3307/data

--tmpdir=/data/mysql/mysql_3307/tmp

--log-bin=/data/mysql/mysql_3307/logs/mysql-bin

--server-id=1003307

--socket=/tmp/mysql_3307.sock

--innodb_buffer_pool_size=500M

#所以得修改mysqld_multi的默认脚本

[[email protected] ~]# vi /usr/local/mysql/bin/mysqld_multi

#####################################################################

216#my $com= join ‘ ‘, ‘my_print_defaults‘, @defaults_options, $group;

217my $com= join ‘ ‘, ‘my_print_defaults -s‘, @defaults_options, $group;

[[email protected] ~]# mysqld_multi stop 3306

[[email protected] ~]# cat /opt/mysql/mysqld_multi.log

Stopping MySQL servers

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

2016-08-21T04:50:39.315023Z mysqld_safe mysqld from pid file /data/mysql/mysql_3306/data/mysql.pid ended

[[email protected] ~]# mysqld_multi stop 3307

[[email protected] ~]# cat /opt/mysql/mysqld_multi.log       #检查是否成功关闭

Stopping MySQL servers

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

2016-08-21T04:47:55.397112Z mysqld_safe mysqld from pid file /data/mysql/mysql_3307/data/mysql.pid ended

[[email protected] ~]# mysqld_multi start    #后面什么都不带,意味着将所有mysql实例启动。

[[email protected] ~]# mysqld_multi start 3306-3310     #3306到3310的全部实例都启动。

[[email protected] ~]# ps -ef|grep mysql     #查看启东进程

[[email protected] ~]# cat /opt/mysql/mysqld_multi.log  #检查日志确保启动成功

Starting MySQL servers

2016-08-21T04:59:41.925014Z mysqld_safe Logging to ‘/data/mysql/mysql_3306/data/error.log‘.

2016-08-21T04:59:41.932341Z mysqld_safe Logging to ‘/data/mysql/mysql_3307/data/error.log‘.

2016-08-21T04:59:41.946622Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3306/data

2016-08-21T04:59:41.952334Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3307/data

[[email protected] ~]# mysql -S /tmp/mysql_3307.sock -p

Enter password:

[email protected] [(none)]>show global variables like "%innodb_buffer_pool%";

+-------------------------------------+----------------+

| Variable_name                       | Value          |

+-------------------------------------+----------------+

| innodb_buffer_pool_chunk_size       | 134217728      |

| innodb_buffer_pool_dump_at_shutdown | ON             |

| innodb_buffer_pool_dump_now         | OFF            |

| innodb_buffer_pool_dump_pct         | 25             |

| innodb_buffer_pool_filename         | ib_buffer_pool |

| innodb_buffer_pool_instances        | 1              |

| innodb_buffer_pool_load_abort       | OFF            |

| innodb_buffer_pool_load_at_startup  | ON             |

| innodb_buffer_pool_load_now         | OFF            |

| innodb_buffer_pool_size             | 536870912|  #大概是500M,单独定义的。

+-------------------------------------+----------------+

10 rows in set (0.00 sec)

来自为知笔记(Wiz)

时间: 2024-11-05 03:57:15

利用mysqld_multi启动管理多实例的相关文章

02.利用Shell开发Redis多实例启动脚本

一.Redis部署情况 ## 软件部署情况 [[email protected] ~]# ls -ld /data/apps/redis <==目录本身及以下所有文件的属主/组为redis lrwxrwxrwx 1 root root 24 Oct 26 11:33 /data/apps/redis -> /data/apps/redis-4.0.14/ ## 实例部署情况 [[email protected] ~]# tree /data/redis/ <==目录本身及以下所有文件的属

MySQL 使用mysqld_multi部署单机多实例详细过程

序言:多实例?Why? 随着硬件层面的发展,linux系统多核已经是普通趋势,而mysql是单进程多线程,所以先天上对多进程的利用不是很高,虽然5.6版本已经在这方面改进很多,但是也没有达到100%,所以为了充分的利用系统资源,mysql有自己的补充,那就是可以部署多实例,一个实例一个端口. 1,准备好mysql环境 源码安装mysql参考blog:http://blog.csdn.net/mchdba/article/details/35994251,源码包下载地址:http://downlo

基于mysqld_multi实现MySQL多实例配置

环境: 操作系统  CentOS7.5(已安装MySQL) 主机名    localhost 本机安装路径为 /usr/local/mysql 实验初始配置:所有主机关闭防火墙与selinux [[email protected] ~]# iptables -F [[email protected] ~]# systemctl stop firewalld [[email protected] ~]# setenforce 0 MySQL多实例的原理 mysql多实例,简单理解就是在一台服务器上

利用Python脚本管理Windows服务

Windows服务常用的功能就是启动服务,关闭服务,重启服务和查询服务运行状态,其中查询服务运行状态是其他三种操作的基础. 本文中提到的使用Python脚本管理Windows服务实际上是调用win32serviceutil模块,此模块来自pywin32包,此模块本身有管理服务的功能,有兴趣的可以去阅读它的部分源码. 本脚本存在的目的是为了熟练Python的语法和基本操作,Windows下有更好的命令行工具来管理服务,如sc.Powershell等.通常命令行工具的执行速度要比services.m

[转]Oracle DB 管理ASM实例

? 描述使用ASM 的好处 ? 管理ASM 实例 ? 创建和删除ASM 磁盘组 ? 扩展ASM 磁盘组 ? 通过使用各种实用程序检索ASM 元数据 Automatic Storage Management Automatic Storage Management (ASM) 将文件系统与卷管理器纵向集成在一起,这是一项专门为Oracle DB 文件建立的技术.使用ASM 可管理单个对称多处理(SMP) 计算机,或通过管理集群的多个节点来支持Oracle Real Application Clus

GRUB启动管理器

Linux学习笔记之 5 Linux GRUB启动管理器 1.GRUB简介 1.1grub与启动引导器 启动引导器是计算机启动过程中运行的第一个真正的软件,通常计算机启动时在通过BIOS自检后读取并运行硬盘的主引导扇中的启动引导器程序,启动引导器再负责加载启动硬盘分区中的操作系统. 1.2 grub的功能 提供了真正的命令行交互界面,能够使用户以最大灵活性使用各种参数引导操作系统和收集系统信息. 支持LBA模式 GRUB能够访问ext2分区 2 安装GRUB 安装GRUB有两个层次的含义: 安装

记一次写Java项目启动管理脚本

最近将大概每天三分之一的精力放到了改造Ambry上(改造后的叫AmbryX,项目地址),Ambry原来最蛋疼的一点就是居然没有启动shell脚本和终止shell脚本,对于运维太不友好了.昨天下午做了个Ambry的启动管理脚本,并且推到了github上,记录下写的思路. 首先,确定下需求. 需求 网上有一个标准的java启动脚本模板,感觉上和我的需求不太符合.他的脚本一个机器上限制只能启动一个JVM进程,我的不是这样,Ambry可能在同一个机器上启动多个JVM进程,每个JVM进程的主类不一样的.我

Zabbix的启动管理方式

1)一般启动方式 启动:[[email protected] ~]# /usr/local/zabbix-3.2.6/sbin/zabbix_server [[email protected] core5]# netstat -tulpnActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:

Linux - 利用systemctl命令管理服务

systemctl命令是系统服务管理器指令,融合了service和chkconfig的功能,可以查看和设置服务. 这里以docker服务为例. 利用systemctl命令管理 显示服务状态:systemctl status docker.service 列出服务层级和依赖关系:systemctl list-dependencies docker.service 启动服务:systemctl start docker.service 关闭服务:systemctl stop docker.servi