码迷,mamicode.com
首页 > 数据库 > 详细

一次mysql MHA架构搭建过程

时间:2018-05-17 15:22:57      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:-o   --   nsis   logic   mysqldb   lock   run   数据库   cte   

【环境介绍】

系统环境:Red Hat Enterprise Linux 7 + 5.7.18 + MHA version 0.57

系统

IP

主机名

备注

版本

 

 

xx系统

192.168.142.111

mysqlmha1

主库

5.7.18 -log MySQL Community Server (GPL)

192.168.142.112

mysqlmha2

备库(预主库)

192.168.142.113

mysqlmha3

备库/MHA MGM

192.168.142.111

mysqlmha3

VIP

 

【搭建步骤:软件部署】

用户目录创建

 #groupadd mysql

 #useradd mysql -g mysql

 #mkdir /home/mysql/logs //创建日志目录

 #mkdir /home/mysql/tmp //创建pid目录

 

将其置于/var/lib下并解压安装包

#tar -xvf mysql-5.7.18-linux-glibc2.12-x86_64.tar.gz

#mv mysql-5.7.20-linux-glibc2.12-x86_64  mysql //改名为mysql目录

#mkdir -p /var/lib/mysql/data //创建数据目录

#chown -R mysql:mysql  /var/lib/mysql/data /home/mysql/tmp  /home/mysql/logs //修改权限

 

初始化mysql数据库

# cd /var/lib/mysql

# ./bin/mysqld --initialize --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql /data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp

 

创建配置文件,注意文件目录及server_id,其他参数可根据具体情况调整

cat >/etc/mymha.cnf
#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=/mysqldata/mysql01
socket=/mysqldata/mysql01/mysql01.sock
port = 3306
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/mysql/mysql57/logs/mysql01.err
pid-file=/mysqldata/mysqldb01.pid

server-id = 111
basedir=/mysql/mysql57
explicit_defaults_for_timestamp

default_storage_engine=InnoDB
default_tmp_storage_engine=InnoDB
character_set_server=utf8
user=mysql
log_timestamps=system
sync_binlog=1

innodb_flush_log_at_trx_commit=1
innodb_buffer_pool_size=1G
innodb_thread_concurrency=32
innodb_flush_method=O_DIRECT
innodb_io_capacity=200
innodb_file_per_table=1

max_connections=1000
max_user_connections=100
long_query_time=1
lower_case_table_names=1
slow_query_log=1
slow_query_log_file=/mysqlslowlog/slow01.log
tmpdir=/mysql/mysql57/tmp
wait_timeout=300
thread_cache_size=100
expire_logs_days=30

#binlog set
log-bin=/mysql/mysql57/logs/binlog01
relay-log=/mysql/mysql57/repaylog/relaylog01
binlog-format = ROW
gtid-mode = ON
enforce-gtid-consistency = ON
log-slave-updates = ON
master-info-repository = TABLE
relay-log-info-repository = TABLE
binlog-checksum = NONE

slave-parallel-workers=4
slave-preserve-commit-order=1
slave-parallel-type=LOGICAL_CLOCK

 

设置开机启动并启动mysql服务

#cp /var/lib/mysql/support_files/mysql.server /etc/init.d/mysql

#service mysql start

#service mysql status

配置环境变量并加载环境变量

#vi /etc/profile

PATH=/var/lib/mysql/bin:$PATH

#source /etc/profile

 

或者直接使用mysql启动指定配置文件,一台主机多个mysql实例时可以使用这种方式启动

#mysqld --defaults-file=/etc/mymha.cnf &

 

查看数据库初始化密码

#cat /home/mysql/logs/mysql.err|grep -i ‘temporary password‘

使用root用户进入数据库后修改密码

Mysql>set password = password(‘mysql‘);

 

其他主机安装mysql步骤跟上面一致,注意修改/etc/my.cnf 中的server_id参数

 

其他备库或者直接使用拷贝的方法安装mysql

#scp -r /var/lib/mysql 192.168.142.xxx: /var/lib/

#chown -R mysql:mysql /var/lib/mysql

#vi /etc/my.cnf

server_id = xxx

#cd /var/lib/mysql/data

#rm auto.cnf

初始化mysql数据库

#./bin/mysqld --initialize --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql /data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp

 

使用root用户进入数据库后修改密码

#cat /home/mysql/logs/mysql.err|grep -i ‘temporary password‘

Mysql>set password = password(‘mysql‘);

执行以上后完成mysql安装

 

【搭建步骤:主从配置】

所有节点创建同步用户repl,ip%表示范围(1对多),密码为repl

mysql>create user repl@‘192.168.142.%‘ IDENTIFIED BY ‘repl‘;

赋予该用户同步所有数据库的表的权限

mysql>GRANT REPLICATION SLAVE ON *.* TO repl@‘192.168.142.%‘;

mysql>flush privileges;

 

两个备库节点执行

mysql>change master to master_user= ‘repl‘,master_host=‘192.168.142.111‘,master_password=‘repl‘,master_port=3306,MASTER_AUTO_POSITION=1;

启动从库服务

mysql> slave start;

查看主从复制状态

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.142.111
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog01.000011
          Read_Master_Log_Pos: 529
               Relay_Log_File: relaylog01.000002
                Relay_Log_Pos: 395
        Relay_Master_Log_File: binlog01.000011
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

    ......

            Executed_Gtid_Set: 42f239e7-5908-11e8-8214-000c2926d694:1,
4651522f-5908-11e8-807d-000c293193c4:1,
8d7abed9-d4cd-11e7-a165-000c29c913a2:1-7,
aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1-15:1000002-1000075
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)

 查看Slave_IO_Running和Slave_SQL_Running运行正常则完成主从复制搭建

 

【配置MHA高可用】

 

一次mysql MHA架构搭建过程

标签:-o   --   nsis   logic   mysqldb   lock   run   数据库   cte   

原文地址:https://www.cnblogs.com/zetanchen/p/9050776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!