Mysql 5.7 多实例 部署

MySQL 5.7 使用systemd 来部署多实例

步骤如下

1.更改my.cnf(直接在mysql 正在使用的配置上增加)

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysqld@3308]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql3308
socket=/var/lib/mysql3308/mysql.sock
#innodb使用O_DIRECT打开数据文件,使用fsync()刷写数据文件跟redo log
#write操作是从MySQL innodb buffer里直接向磁盘上写
innodb_flush_method=O_DIRECT
#avoid ibdata1  too big
innodb_file_per_table=1

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

user=mysql
port=3308
log-error=/var/log/mysqld3308.log
pid-file=/var/run/mysqld3308/mysqld.pid
character-set-server=utf8
collation-server=utf8_general_ci
explicit_defaults_for_timestamp=1

2.执行命令 systemctl start mysqld@3308.service 

3.开机启用 systemctl enable mysqld@3308.service 

4.访问新实例 mysql -uroot -p -S /var/lib/mysql3308/mysql.sock (root用户密码会在第一次启动成功之后写入log-error文件)

完成

遇到的坑

1.权限问题

主要是ibdata1文件

更改文件权限即可(两种方式:更改所属用户组chown -R mysql:mysql xxx,更改用户权限chmod 777 xxx)

2.swap 空间不足或没有

关键异常信息如下

[ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
[ERROR] InnoDB: Cannot allocate memory for the buffer pool

3.SELinux导致的权限问题

setenforce 0 #关闭SELinux(SELinux比较复杂,后续慢慢研究,先关掉再说)

所有失败原因均可查看相关日志文件 (实例中指定的 log-error文件)

 

参考文档

https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html#systemd-multiple-mysql-instances

https://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html

https://dev.mysql.com/doc/refman/5.7/en/mysqld-multi.html

https://github.com/abel1225/DevOps-Configuration/blob/master/server_build/database/mysql/mysql多实例部署.txt

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值