Linux下安装Mysql多实例作为数据备份服务器实现多主到一从多实例的备份
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下安装Mysql多实例作为数据备份服务器实现多主到一从多实例的备份相关的知识,希望对你有一定的参考价值。
参考技术A 1、从MYSQL官方下载MYSQL的源码版本【一定要是源码版本】2、按以下代码键入LINUX命令行
复制代码
代码如下:
[注]
添加mysql组和用户
#groupadd
mysql
#useradd
-g
mysql
mysql
[注]
解包到/usr/local
#
tar
-xzf
mysql-standard-4.1.9-pc-linux-gnu-i686.tar.gz
-C
/usr/local
[注]
建立软链接,方便操作(此处给此连接命名为mysql001,也可为其它的名字)
#cd
/usr/local
#ln
-s
mysql-standard-5.0.15-linux-i686-glibc23
mysql001
#cd
mysql001
#scripts/mysql_install_db
#chown
-R
root
.
#chown
-R
mysql
data
#chgrp
-R
mysql
.
[注]
复制data,以供单版本多实例分配
#cp
-a
data
data_1
#cp
-a
data
data_2
[注]
添加多实例配置文件
#cd
/usr/local/mysql001/bin
#cat
>my_multi.cnf
[注]
以下是my_multi.cnf的配置信息,可依此复制
[mysqld_multi]
mysqld
=
/usr/local/mysql001/bin/mysqld_safe
mysqladmin
=
/usr/local/mysql001/bin/mysqladmin
user
=
root
password
=
root
[mysqld1]
socket
=
/tmp/mysql_001.sock
port
=
3301
pid-file
=
/usr/local/mysql001/data_1/hostname.pid
datadir
=
/usr/local/mysql001/data_1
log
=
/usr/local/mysql001/data_1/hostname.log
user
=
mysql
#
slave
setting
server-id
=
2
master-host
=
192.168.1.85
master-port
=
3306
master-user
=
backup
master-password
=
123456
replicate-do-db
=
gs_database
replicate-do-db
=
gs_log
master-connect-retry=30
[mysqld2]
socket
=
/tmp/mysql_5_2.sock
port
=
3302
pid-file
=
/usr/local/mysql001/data_2/hostname.pid
datadir
=
/usr/local/mysql001/data_2
log
=
/usr/local/mysql001/data_2/hostname.log
user
=
mysql
#
slave
setting
server-id
=
3
master-host
=
192.168.1.69
master-port
=
3306
master-user
=
backup
master-password
=
123
replicate-do-db
=
gs_databaes
replicate-do-db
=
gs_log
master-connect-retry=30
CTRL+D退出。
复制代码
代码如下:
#vi
/etc/profile
#
添加系统环境变量。
export
MYSQL_HOME=/usr/local/mysql001/bin
export
PATH=$PATH:$MYSQL_HOME
重启系统让环境变量生效。
添加至开机自动启动【此处可不添加,依个人情况决定是否需要设置开机自动启动】
复制代码
代码如下:
vi
/etc/rc.local
#
添加
mysqld_multi
--defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf
start
1,2
3、其它一些技巧
#
访问某个实例:
mysql
-u
root
-S
/tmp/mysql_5_1.sock
-p
#
设置各个实例密码:
mysqladmin
-u
root
password
'root'
-S
/tmp/mysql_5_1.sock
#
手动启动各个实例:
mysqld_multi
--defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf
start
1,2
#
停止各个实例:
mysqld_multi
--defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf
stop
1,2
#
参考文章
http://blog.liuts.com/post/13/
由于第一次接触LINUX,花了三天时间才算有所成就,发出来希望可以给大伙带来方便
centos 安装多实例数据库
在Centos下安装多个MySql 5.7
① 下载MySql 解压版安装包
② 编写安装脚本
③ 将脚本和安装包放置同一目录
④ 编写my.cnf文件并放置在/etc/ 目录下
⑤ 赋予脚本运行权限并运行
⑥ 修改默认密码
① 下载MySql 解压版安装包
点击传送门:MySql下载 下载对应系统的MySql, Centos选 Linux - Generic <64位> (本人Centos是64位,32位的请选择32位)
② 编写安装脚本
#!/bin/bash baseMysqlDir=/usr/local/tarsPkg/mysql-5.7.22-linux-glibc2.12-x86_64 yum install mysql-devel ## 创建 MySQL 软链接 ln -s ${baseMysqlDir} /usr/local/mysql ##创建 MySQL 用户 useradd -r -s /sbin/nologin mysql ## 在 MySQL 二进制包目录中创建 mysql-files 目录 mkdir -v /usr/local/mysql/mysql-files ## 创建多实例数据目录 mkdir -vp /data/mysql_data{1..4} ## 修改 MySQL 二进制包目录的所属用户与所属组 chown root.mysql -R ${baseMysqlDir} ## 修改 MySQL 多实例数据目录与 数据导入/导出专放目录的所属用户与所属组 chown mysql.mysql -R /usr/local/mysql/mysql-files /data/mysql_data{1..4} ## 初始化各个实例 [ 初始化完成后会自带随机密码在输出日志中 ] /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data1 /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data2 /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data3 /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data4 ## 各实例开启 SSL 连接 /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data1 /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data2 /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data3 /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data4 ## 添加mysql 到path echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile source /etc/profile ## 复制多实例脚本到服务管理目录下 [ /etc/init.d/ ] cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi ## 添加脚本执行权限 chmod +x /etc/init.d/mysqld_multi ## 添加进service服务管理 chkconfig --add mysqld_multi export PATH=/usr/local/mysql/bin:$PATH ## 查个多实例状态 /etc/init.d/mysqld_multi report
③ 将脚本和安装包放置同一目录
④ 编写my.cnf文件并放置在/etc/ 目录下
[mysqld_multi] mysqld = /usr/local/mysql/bin/mysqld mysqladmin = /usr/local/mysql/bin/mysqladmin log = /tmp/mysql_multi.log [mysqld1] federated # 设置数据目录 [多实例中一定要不同] datadir = /data/mysql_data1 # 设置sock存放文件名 [多实例中一定要不同] socket = /tmp/mysql.sock1 # 设置监听开放端口 [多实例中一定要不同] port = 3306 # 设置运行用户 user = mysql # 关闭监控 performance_schema = off # 设置innodb 缓存大小 innodb_buffer_pool_size = 32M # 设置监听IP地址 bind_address = 0.0.0.0 # 关闭DNS 反向解析 skip-name-resolve = 0 max_connections=1000 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES explicit_defaults_for_timestamp=true tmpdir=/data/mysql_data1 character_set_server = utf8mb4 [mysqld2] datadir = /data/mysql_data2 socket = /tmp/mysql.sock2 tmpdir=/data/mysql_data2 port = 3307 user = mysql performance_schema = off innodb_buffer_pool_size = 32M bind_address = 0.0.0.0 skip-name-resolve = 0 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES explicit_defaults_for_timestamp=true lower_case_table_names = 1 [mysqld3] datadir = /data/mysql_data3 socket = /tmp/mysql.sock3 tmpdir=/data/mysql_data3 port = 3308 user = mysql performance_schema = off innodb_buffer_pool_size = 32M bind_address = 0.0.0.0 skip-name-resolve = 0 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES explicit_defaults_for_timestamp=true lower_case_table_names = 1 [mysqld4] datadir = /data/mysql_data4 socket = /tmp/mysql.sock4 tmpdir=/data/mysql_data4 port = 3309 user = mysql performance_schema = off innodb_buffer_pool_size = 32M bind_address = 0.0.0.0 skip-name-resolve = 0 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES explicit_defaults_for_timestamp=true
⑤ 赋予脚本运行权限并运行
执行结果:
⑥ 修改默认密码
记得修改每一个默认密码哦
以上是关于Linux下安装Mysql多实例作为数据备份服务器实现多主到一从多实例的备份的主要内容,如果未能解决你的问题,请参考以下文章