mariadb+MHA+maxcale

MariaDB

https://pan.baidu.com/s/1-sP3ntdK7aa0mUUOUBj9hg
安装时用到的所有包

  1. 删除CentOS7.3默认数据库配置文件

查看默认数据库配置文件

[root@localhost~]# find -H /etc/ | grep my.c


/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/certs/renew-dummy-cert
/etc/my.cnf
/etc/my.cnf.d
/etc/my.cnf.d/mysql-clients.cnf
/etc/my.cnf.d/client.cnf
/etc/my.cnf.d/server.cnf


删除默认数据库配置文件

[root@localhost~]# rm -rf /etc/my.cnf /etc/my.cnf.d/

再次查看默认数据库配置文件

[root@localhost~]# find -H /etc/ | grep my.c


/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/certs/renew-dummy-cert


到目前为止, 系统最小化安装自带的数据库配置文件已经删除干净了!

  1. 卸载系统自带mariadb-libs

查询

[root@localhost~]# rpm -qa|grep mariadb-libs


mariadb-libs-5.5.56-2.el7.x86_64


卸载

[root@localhost~]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps


警告:文件 /etc/my.cnf.d/mysql-clients.cnf: 移除失败: 没有那个文件或目录
警告:文件 /etc/my.cnf.d: 移除失败: 没有那个文件或目录
警告:文件 /etc/my.cnf: 移除失败: 没有那个文件或目录


安装相关包

[root@localhost~]# yum -y install libaio libaio-devel bison bison-deve zlib-devel openssl openssl-devel ncurses ncurses-devel libcurl-devel libarchive-devel boost boost-devel lsof wget gcc gcc-c++ make cmake perl kernel-headers kernel-devel pcre-devel

要再三确定依赖包是否安装完成


1:Libaio:用户空间函数
2:libaio-devel :如果要使用编译源代码要加devel
3:bison :是Linux的基础包之一,用于GNU编译工具包的语法生成,以一系列规则。
4:zlib:zlib 适用于数据压缩的函式库
5:openssl :整个软件包大概可以分成三个主要的功能部分:SSL协议库、应用程序以及密码算法库
6:ncurses:计算机语言,指的是提供字符终端处理库。
7:libcurl:主要功能就是用不同的协议连接和沟通不同的服务器~也就是相当封装了
8:libarchive:
9:boost:他是一个功能强大,结构精良,跨越平台,代码开源,免费的c++程序库。
10:lsof:用途是用来查找 本地套接字 被哪些进程使用?
11:wget:是下载工具
12:gcc:编译器
13:make:常指一条计算机指令,是在安装有GNU Make的计算机上的可执行指令。
14:cmake:CMake是一个比make更高级的编译配置工具,它可以根据不同平台、不同的编译器,生成相应的Makefile或者vcproj项目。
15:perl:是一个模块
16:kernel:内核包
17:是一个用C语言编写的正则表达式函数库


报错


/var/run/yum.pid
已被锁定,PID 为 4132 的另一个程序正在运行。
Another
app is currently holding the yum lock; waiting for it to exit…
另一个应用程序是:PackageKit
内存:167 M RSS (1.1 GB VSZ)
已启动: Tue Nov 20 08:50:18 2018 -
14:35之前
状态
:睡眠中,进程ID:4132

mariadb+MHA+maxcale_第1张图片

解决办法

[root@localhost~]# rm -rf /run/yum.pid 把这个文件删除再重新执行命令

  1. 创建家目录存放软件包目录

[root@localhost~]# mkdir /soft

[root@localhost~]# cd /soft/

  1. MariaDB包上传

上传

[root@localhostsoft]# rz

解压

[root@localhostsoft]# tar -zxf mariadb-10.2.14.tar.gz

  1. 创建MariaDB安装目录、数据库存放目录、建立用户和目录

创建mysql系统用户组

[root@localhostsoft]# groupadd -r mysql

创建系统用户mysql并加入到mysql系统用户组

[root@localhostsoft]# useradd -r -g mysql -s /sbin/nologin -d /usr/local/mysql -M mysql

创建maria安装目录

[root@localhostsoft]# mkdir -p /usr/local/mysql

创建数据库存放目录

[root@localhostsoft]# mkdir -p /data/mysql

改变数据库存放目录所属用户及组为 mysql:mysql

[root@localhostsoft]# chown -R mysql:mysql /data/mysql

执行编译安装

进入到解压后的源码包文件夹

[root@localhostsoft]# cd mariadb-10.2.14/

输入编译参数

[root@localhostsoft#cmake .-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/data/mysql
-DSYSCONFDIR=/etc
-DWITHOUT_TOKUDB=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STPRAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWIYH_READLINE=1
-DWIYH_SSL=system
-DVITH_ZLIB=system
-DWITH_LOBWRAP=0
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci

解释

  1.     -DCMAKE_INSTALL_PREFIX= 指向mysql安装目录
    
  2.     -DINSTALL_SBINDIR=sbin 指向可执行文件目录(prefix/sbin)
    
  3.     -DMYSQL_DATADIR=/var/lib/mysql 指向mysql数据文件目录(/var/lib/mysql)
    
  4.    -DSYSCONFDIR=/etc/mysql 指向mysql配置文件目录(/etc/mysql)
    
  5.  -DINSTALL_PLUGINDIR=lib/mysql/plugin 指向插件目录(prefix/lib/mysql/plugin)
    
  6.     -DINSTALL_MANDIR=share/man 指向man文档目录(prefix/share/man)
    
  7.     -DINSTALL_SHAREDIR=share 指向aclocal/mysql.m4安装目录(prefix/share)
    
  8.     -DINSTALL_LIBDIR=lib/mysql 指向对象代码库目录(prefix/lib/mysql)
    
  9.     -DINSTALL_INCLUDEDIR=include/mysql 指向头文件目录(prefix/include/mysql)
    
  10. -DINSTALL_INFODIR=share/info  指向info文档存放目录(prefix/share/info)
    
  11.  -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1  禁用example引擎
    
  12. -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 禁用federateb引擎

  13. -DWITHOUT_PARTITION_STORAGE_ENGINE=1   禁用partition引擎
    
  14. -DWITH_INNOBASE_STORAGE_ENGINE=1  启用innobase引擎
    
  15. -DWITH_ARCHIVE_STORAGE_ENGINE=1   启用archive引擎 
    
  16. -DWITH_BLACKHOLE_STORAGE_ENGINE=1   启用blackhole引擎
    
  17. -DWITH_READLINE=1 启用readline库支持(提供可编辑的命令行)
    
  18. -DWITH_SSL=system 启用ssl库支持(安全套接层)
    
  19. -DWITH_ZLIB=system 启用libz库支持(zib、gzib相关)
    
  20. -DWTIH_LIBWRAP=0 禁用libwrap库(实现了通用TCP包装的功能,为网络服务守护进程使用)
    
  21. -DMYSQL_TCP_PORT=3306 指定TCP端口为3306
    
  22. -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock 指定mysql.sock路径
    
  23. -DENABLED_LOCAL_INFILE=1  启用本地数据导入支持
    
  24. -DEXTRA_CHARSETS=all 启用额外的字符集类型(默认为all)
    
  25. -DDEFAULT_CHARSET=utf8   指定默认的字符集为utf8
    
  26. -DDEFAULT_COLLATION=utf8_general_ci设定默认排序规则(utf8_general_ci快速/utf8_unicode_ci准确)
    
  27. -DWITH_EMBEDDED_SERVER=1    编译嵌入式服务器支持
    
  28.   -DMYSQL_USER=mysql 指定mysql用户(默认为mysql)
    
  29. -DWITH_DEBUG=0 禁用debug(默认为禁用)
    
  30. -DENABLE_PROFILING=0   禁用Profiling分析(默认为开启)
    
  31. -DWITH_COMMENT=‘string’ 一个关于编译环境的描述性注释


[[email protected]]# echo $?

0 如果是0就没有错误可以继续 不是就有问题了需要检查

如果编译失败请删除CMakeCache.txt

[root@localhostsoft]# rm -f CMakeCache.txt

cmake没问题,可以编译并且安装了: make && make install 时间会有点长根据个人机器吧,你可以干别的事情去!

[root@localhostsoft]# make && make install

  1. 配置MariaDB

进入到 MariaDB 安装目录

[[email protected]]# cd /usr/local/mysql/

使用 mysql 用户执行脚本, 安装数据库到数据库存放目录

[root@localhostmysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql

  1. 复制MariaDB配置文件到/etc目录

进行到 MariaDB 安装目录[root@localhost mysql]# cd /usr/local/mysql/拷贝support-files目录下的文件my-large.cnf到/etc目录并重命名为my.cnf[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf

  1. 创建启动脚本

[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld创建软链接
[root@localhost mysql]# ln -s /etc/rc.d/init.d/mysqld /bin/

  1. 启动mysqld服务

[root@localhost mysql]# /etc/rc.d/init.d/mysqld start

Reloading systemd: [ 确定 ]
Starting mysqld (via systemctl): [ 确定 ]

mariadb+MHA+maxcale_第2张图片

报错

[root@localhostmysql]# /etc/rc.d/init.d/mysqld start


Starting mysqld (via systemctl): Job for mysqld.service failed because the
control process exited with error code. See “systemctl status
mysqld.service” and “journalctl -xe” for details.


解决

[root@localhost mariadb-10.2.14]# cd /usr/local/mysql/

[root@localhostmysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql

  1. 配置环境变量, 以便在任何目录下输入mysql

打开并新建文件[root@localhost mysql]# vim /etc/profile.d/mysql.sh输入以下内容


export PATH=$PATH:/usr/local/mysql/bin/


保存并退出为脚本赋于可执行权限
[root@localhost mysql]# chmod 0777 /etc/profile.d/mysql.sh进行mysql.sh脚本所在目录, 并执行脚本, 以立即生效环境变量
[root@localhost mysql]# source /etc/profile.d/mysql.sh

  1. 初始化MariaDB

运行MariaDB初始化脚本[root@localhost mysql]# ./bin/mysql_secure_installation

以下提示:Enter current password for root (enter for none): 输入当前root密码(没有输入)Set root password? [Y/n] 设置root密码?(是/否)New password: 输入新root密码Re-enter new password: 确认输入root密码Password updated successfully! 密码更新成功By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.默认情况下,MariaDB安装有一个匿名用户,允许任何人登录MariaDB而他们无需创建用户帐户。这个目的是只用于测试,安装去更平缓一些。你应该进入前删除它们生产环境。Remove anonymous users? [Y/n] 删除匿名用户?(是/否)Normally, root should only be allowed to connect from ‘localhost’. Thisensures that someone cannot guess at the root password from the network.通常情况下,root只应允许从localhost连接。这确保其他用户无法从网络猜测root密码。Disallow root login remotely? [Y/n] 不允许root登录远程?(是/否)By default, MariaDB comes with a database named ‘test’ that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.默认情况下,MariaDB提供了一个名为“测试”的数据库,任何人都可以访问。这也只用于测试,在进入生产环境之前应该被删除。Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.重新加载权限表将确保所有到目前为止所做的更改将立即生效。Reload privilege tables now? [Y/n] 现在重新加载权限表(是/否)All done! If you’ve completed all of the above steps, your MariaDBinstallation should now be secure.全部完成!如果你已经完成了以上步骤,MariaDB安装现在应该安全。Thanks for using MariaDB!感谢使用MariaDB!

11进入MariaDB终端

[root@localhost mysql]# mysql -uroot -p111111

mariadb+MHA+maxcale_第3张图片

编译mariadb完成

Mha安装

配置一注双从

放行3306端口

[root@localhostmysql]# firewall-cmd --permanent --add-port=3306/tcp


success


添加完端口需要重启防火墙

[root@localhostmysql]# systemctl restart firewalld

查看防火墙规则

[root@localhostmysql]# firewall-cmd --list-all


public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: ssh dhcpv6-client
ports: 3306/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:


所有节点依赖的配置

[root@localhostmysql]#vim /etc/my.cnf.d


[mysqld]
server-id = 1 #复制集群中的各节点的id均必须唯一;
relay-log =
relay-log #开启中继日志;
log-bin =
master-log #开启二进制日志,因为每一台slave都可能会变成master;
read_only =
ON #开启只读权限;
relay_log_purge
= 0 #是否自动清空不再需要的中继日志;
skip_name_resolve
= ON #不进行域名解析


重启数据库主

[root@localhost~]# /etc/rc.d/init.d/mysqld restart

进入

[root@localhost~]# mysql -uroot -p111111

给权限

MariaDB[(none)]> grant all on . to wang@‘192.168.14.%’ identified by ‘111111’;

刷新权限

MariaDB[(none)]> flush privileges;

查看二进制日志

MariaDB[(none)]> show master status;


±------------------±---------±-------------±-----------------+
| File | Position | Binlog_Do_DB |
Binlog_Ignore_DB |
±------------------±---------±-------------±-----------------+
|
master-log.000001 | 633 | | |
±------------------±---------±-------------±-----------------+
1 row in set
(0.00 sec)


重启数据库从

[root@localhost~]# /etc/rc.d/init.d/mysqld restart

进入

[root@localhost~]# mysql -uroot -p111111

MariaDB[(none)]> stop slave ;


Query OK, 0 rows
affected, 1 warning (0.00 sec)


MariaDB[(none)]> change master to master_host=‘192.168.14.129’,master_user=‘wang’,master_password=‘111111’,master_log_file=‘master-log.000001’,master_log_pos=633;


Query OK, 0 rows
affected (0.02 sec)


MariaDB[(none)]> start slave ;


Query OK, 0 rows
affected (0.05 sec)


MariaDB[(none)]> show slave status \G;


  1. row ***************************
    Slave_IO_State: Waiting for
    master to send event
    Master_Host: 192.168.14.129
    Master_User: wang
    Master_Port: 3306
    Connect_Retry: 60
    Master_Log_File:
    master-log.000001
    Read_Master_Log_Pos: 633
    Relay_Log_File:
    relay-log.000002
    Relay_Log_Pos: 556
    Relay_Master_Log_File:
    master-log.000001
    Slave_IO_Running: Yes
    Slave_SQL_Running: Yes
    Replicate_Do_DB:
    Replicate_Ignore_DB:
    Replicate_Do_Table:
    Replicate_Ignore_Table:
    Replicate_Wild_Do_Table:
    Replicate_Wild_Ignore_Table:
    Last_Errno: 0
    Last_Error:
    Skip_Counter: 0
    Exec_Master_Log_Pos: 633
    Relay_Log_Space: 859
    Until_Condition: None
    Until_Log_File:
    Until_Log_Pos: 0
    Master_SSL_Allowed: No
    Master_SSL_CA_File:
    Master_SSL_CA_Path:
    Master_SSL_Cert:
    Master_SSL_Cipher:
    Master_SSL_Key:
    Seconds_Behind_Master: 0
    Master_SSL_Verify_Server_Cert:
    No
    Last_IO_Errno: 0
    Last_IO_Error:
    Last_SQL_Errno: 0
    Last_SQL_Error:
    Replicate_Ignore_Server_Ids:
    Master_Server_Id: 1
    Master_SSL_Crl:
    Master_SSL_Crlpath:
    Using_Gtid: No
    Gtid_IO_Pos:
    Replicate_Do_Domain_Ids:
    Replicate_Ignore_Domain_Ids:
    Parallel_Mode: conservative
    SQL_Delay: 0
    SQL_Remaining_Delay: NULL
    Slave_SQL_Running_State: Slave has read
    all relay log; waiting for the slave I/O thread to update it
    1 row in set
    (0.00 sec)

ERROR: No query
specified
mariadb+MHA+maxcale_第4张图片

去主给权限

MariaDB[(none)]> grant all on . to wangyu@‘192.168.14.%’ identified by ‘111111’;


Query OK, 0 rows
affected (0.00 sec)


MariaDB[(none)]> flush privileges;

在所有节点进行ssh认证

[root@localhost~]# ssh-keygen -t rsa (完后一路回车)

mariadb+MHA+maxcale_第5张图片

[root@localhost~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
mariadb+MHA+maxcale_第6张图片
[root@localhost~]# ssh-copy-id -i /root.ssh/id_rsa.pub [email protected]

[root@localhost~]# ssh-copy-id -i /root.ssh/id_rsa.pub [email protected]

上传包

Manager上传的包

mariadb+MHA+maxcale_第7张图片

其他节点上传的包

在这里插入图片描述

在这里插入图片描述

rpm安装包

[root@localhost~]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm


准备中…
################################# [100%]
正在升级/安装…
1:mha4mysql-node-0.56-0.el6 #################################
[100%]


[root@localhost~]# rpm -ivh perl-Mail-Sender-0.8.23-1.el7.noarch.rpm


警告:perl-Mail-Sender-0.8.23-1.el7.noarch.rpm:
头V3
RSA/SHA256 Signature, 密钥
ID 352c64e5: NOKEY
准备中…
################################# [100%]
正在升级/安装…
1:perl-Mail-Sender-0.8.23-1.el7 ################################# [100%]


[root@localhost~]# rpm -ivh perl-Mail-Sendmail-0.79-21.el7.noarch.rpm


警告:perl-Mail-Sendmail-0.79-21.el7.noarch.rpm:
头V3
RSA/SHA256 Signature, 密钥
ID 352c64e5: NOKEY
准备中… #################################
[100%]
正在升级/安装…
1:perl-Mail-Sendmail-0.79-21.el7 ################################# [100%]


[root@localhost~]# rpm -ivh perl-Parallel ForkManager-1.18-2.el7.noarch.rpm


警告:perl-Parallel-ForkManager-1.18-2.el7.noarch.rpm:
头V3
RSA/SHA256 Signature, 密钥
ID 352c64e5: NOKEY
准备中…
################################# [100%]
正在升级/安装…

1:perl-Parallel-ForkManager-1.18-2.#################################
[100%]


[root@localhost~]# rpm -ivh perl-Time-HiRes-1.9725-3.el7.x86_64.rpm


准备中…
################################# [100%]
软件包 perl-Time-HiRes-4:1.9725-3.el7.x86_64 已经安装


[root@localhost ~]# rpm -ivh
perl-Log-Dispatch-2.41-1.el7.1.noarch.rpm --nodeps --force


警告:perl-Log-Dispatch-2.41-1.el7.1.noarch.rpm:
头V3
RSA/SHA256 Signature, 密钥
ID 352c64e5: NOKEY
准备中…
################################# [100%]
正在升级/安装…
1:perl-Log-Dispatch-2.41-1.el7.1 ################################# [100%]


[root@localhost ~]# yum -y install perl-Config-Tiny perl-DBD-MySQL

[root@localhost ~]# rpm -ivh mha4mysql-manager-0.56-0.el6.noarch.rpm


准备中…
################################# [100%]
正在升级/安装…
1:mha4mysql-manager-0.56-0.el6 ################################# [100%]


报错

[root@localhostsoft]# rpm -ivh mha4mysql-manager-0.56-0.el6.noarch.rpm


错误:依赖检测失败:
mha4mysql-node >= 0.54 被 mha4mysql-manager-0.56-0.el6.noarch 需要
perl(MHA::BinlogManager) 被 mha4mysql-manager-0.56-0.el6.noarch 需要
perl(MHA::NodeConst) 被 mha4mysql-manager-0.56-0.el6.noarch 需要
perl(MHA::NodeUtil) 被 mha4mysql-manager-0.56-0.el6.noarch 需要
perl(MHA::SlaveUtil) 被 mha4mysql-manager-0.56-0.el6.noarch 需要


解决

前面rpm包有没安装的 再仔细看看那个包没有安装

[root@localhost~]# wget https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm

[root@localhost~]# mv cpanm /usr/bin/

[root@localhost~]# chmod 755 /usr/bin/cpanm

[root@localhost~]# cpanm install DBD::mysql

[root@localhost~]# cpanm install Config::Tiny

[root@localhost~]# cpanm install Log::Dispatch

[root@localhost~]# cpanm install Parallel::ForkManager

[root@localhost~]# cpanm install Time::HiRes

[root@localhost~]# mkdir /etc/mha_master

编辑配置文件

[root@localhost~]# vim /etc/mha_master/app1.cnf


[server default]
//适用于server1,2,3个server的配置
user=mhaadmin
//mha管理用户
password=mhapass
//mha管理密码
manager_workdir=/etc/mha_master/app1
//mha_master自己的工作路径
manager_log=/etc/mha_master/manager.log
// mha_master自己的日志文件
remote_workdir=/mydata/mha_master/app1
//每个远程主机的工作目录在何处
master_binlog_dir=/data/mysql
ssh_user=root //
基于ssh的密钥认证
repl_user=slave//数据库用户名
repl_password=Redhat
//数据库密码
ping_interval=1
// ping间隔时长

[server1] //节点1,[server1]节点必须设置成master
hostname=192.168.166.31
//节点1主机地址
ssh_port=22 //节点1的ssh端口
candidate_master=1
// 将来可不可以成为master候选节点/主节点

[server2] //节点2
hostname=192.168.166.32
//节点2主机地址
ssh_port=22 //节点2的ssh端口
candidate_master=1
// 将来可不可以成为master候选节点/主节点

[server3] //节点3
hostname=192.168.166.33
ssh_port=22
candidate_master=1


Ssh测试

[root@localhost~]# masterha_check_ssh -conf=/etc/mha_master/app1.cnf


Thu Nov 15
17:53:29 2018 - [warning] Global configuration file /etc/masterha_default.cnf
not found. Skipping.
Thu Nov 15
17:53:29 2018 - [info] Reading application default configuration from
/etc/mha_master/app1.cnf…
Thu Nov 15
17:53:29 2018 - [info] Reading server configuration from
/etc/mha_master/app1.cnf…
Thu Nov 15 17:53:29
2018 - [info] Starting SSH connection tests…
Thu Nov 15
17:53:32 2018 - [debug]
Thu Nov 15
17:53:29 2018 - [debug] Connecting via
SSH from [email protected](192.168.14.129:22) to
[email protected](192.168.14.130:22)…
Thu Nov 15
17:53:31 2018 - [debug] ok.
Thu Nov 15
17:53:31 2018 - [debug] Connecting via
SSH from [email protected](192.168.14.129:22) to
[email protected](192.168.14.131:22)…
Thu Nov 15
17:53:32 2018 - [debug] ok.
Thu Nov 15
17:53:33 2018 - [debug]
Thu Nov 15
17:53:30 2018 - [debug] Connecting via
SSH from [email protected](192.168.14.131:22) to
[email protected](192.168.14.129:22)…
Thu Nov 15
17:53:32 2018 - [debug] ok.
Thu Nov 15
17:53:32 2018 - [debug] Connecting via
SSH from [email protected](192.168.14.131:22) to
[email protected](192.168.14.130:22)…
Thu Nov 15
17:53:33 2018 - [debug] ok.
Thu Nov 15
17:53:33 2018 - [debug]
Thu Nov 15
17:53:30 2018 - [debug] Connecting via
SSH from [email protected](192.168.14.130:22) to [email protected](192.168.14.129:22)…
Thu Nov 15
17:53:31 2018 - [debug] ok.
Thu Nov 15
17:53:31 2018 - [debug] Connecting via
SSH from [email protected](192.168.14.130:22) to
[email protected](192.168.14.131:22)…
Thu Nov 15
17:53:32 2018 - [debug] ok.
Thu Nov 15 17:53:33
2018 - [info] All SSH connection tests passed successfully.
Use of
uninitialized value in exit at /usr/bin/masterha_check_ssh line 44.


mariadb+MHA+maxcale_第8张图片
报错

[root@localhostsoft]# masterha_check_ssh -conf=/etc/mha_master/app1.cnf


Tue Nov 20
14:29:33 2018 - [warning] Global configuration file /etc/masterha_default.cnf
not found. Skipping.
Tue Nov 20
14:29:33 2018 - [info] Reading application default configuration from
/etc/mha_master/app1.cnf…
Tue Nov 20
14:29:33 2018 - [info] Reading server configuration from
/etc/mha_master/app1.cnf…
Tue Nov 20
14:29:33 2018 - [info] Starting SSH connection tests…
Tue Nov 20
14:29:39 2018 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln63]
Tue Nov 20
14:29:33 2018 - [debug] Connecting via
SSH from [email protected](192.168.0.129:22) to
[email protected](192.168.14.130:22)…
ssh: connect to
host 192.168.0.129 port 22: Connection timed out
Tue Nov 20
14:29:38 2018 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln111]
SSH connection from [email protected](192.168.0.129:22) to
[email protected](192.168.14.130:22) failed!
Tue Nov 20
14:29:40 2018 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm,
ln63]
Tue Nov 20
14:29:34 2018 - [debug] Connecting via
SSH from [email protected](192.168.14.130:22) to
[email protected](192.168.0.129:22)…
ssh: connect to
host 192.168.0.129 port 22: Connection timed out
Tue Nov 20
14:29:39 2018 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln111]
SSH connection from [email protected](192.168.14.130:22) to [email protected](192.168.0.129:22)
failed!
Tue Nov 20
14:29:40 2018 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm,
ln63]
Tue Nov 20
14:29:34 2018 - [debug] Connecting via
SSH from [email protected](192.168.14.131:22) to
[email protected](192.168.0.129:22)…
ssh: connect to
host 192.168.0.129 port 22: Connection timed out
Tue Nov 20
14:29:40 2018 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln111]
SSH connection from [email protected](192.168.14.131:22) to
[email protected](192.168.0.129:22) failed!
SSH
Configuration Check Failed!
at /usr/bin/masterha_check_ssh line 44.


解决

配置文件写错了 仔细调对

[root@localhost~]# masterha_check_repl -conf=/etc/mha_master/app1.cnf
mariadb+MHA+maxcale_第9张图片出现is OK就对了

报错

[root@localhostsoft]# masterha_check_replconf=/etc/mha_master/app1.cnf


Tue Nov 20
14:40:15 2018 - [error][/usr/share/perl5/vendor_perl/MHA/ServerManager.pm,
ln492] Server
192.168.14.130(192.168.14.130:3306) is dead, but must be alive! Check server
settings.
Tue Nov 20
14:40:15 2018 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm,
ln424] Error happened on checking configurations. at
/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm line 399.
Tue Nov 20
14:40:15 2018 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm,
ln523] Error happened on monitoring servers.
Tue Nov 20
14:40:15 2018 - [info] Got exit code 1 (Not master dead).

MySQL
Replication Health is NOT OK!


解决办法

防火墙放行

其他节点

上传包

[root@localhost~]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm


准备中…
################################# [100%]
正在升级/安装…
1:mha4mysql-node-0.56-0.el6 #################################
[100%]


启动MHA

[root@localhost~]# nohup masterha_manager -conf=/etc/mha_master/app1.cnf &>
/etc/mha_master/manager.log &


[1] 25430


查看服务状态

[root@localhost~]# masterha_check_status -conf=/etc/mha_master/app1.cnf


app1 (pid:25430)
is running(0:PING_OK), master:192.168.14.129


停止主

[root@localhost~]# /etc/rc.d/init.d/mysqld stop

查看日志

[root@localhost~]# tail -100 /etc/mha_master/manager.log
mariadb+MHA+maxcale_第10张图片

Mha安装完成

Maxscale读写分离

https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-22-readwrite-splitting-with-mariadb-maxscale/
官方网址

上传包

Rpm安装

rpm -ivh maxscale-2.2.16-1.centos.7.x86_64_(1).rpm

复制配置文件

cp /etc/maxscale.cnf /etc/maxscale.cnf.bak

修改配置文件

vim /etc/maxscale.cnf


MaxScale documentation:

https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-22/

Global parameters

Complete list of configuration options:

https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-22-mariadb-maxscale-configuration-usage-scenarios/

[maxscale]
threads=auto

Server definitions

Set

the address of the server to the network

address of a MariaDB server.

[server1]
type=server
address=192.168.14.129
port=3306
protocol=MariaDBBackend
serv_weight=1
[server2]
type=server
address=192.168.14.130
port=3306
protocol=MariaDBBackend
serv_weight=1

[server3]
type=server
address=192.168.14.131
port=3306
protocol=MariaDBBackend
serv_weight=1

Monitor for the servers

This

will keep MaxScale aware of the state of the servers.

MariaDB Monitor documentation:

https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-22-mariadb-monitor/

[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2,server3
user=wang
passwd=111111
monitor_interval=2000

Service definitions

Service Definition for a read-only service and

a

read/write splitting service.

ReadConnRoute documentation:

https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-22-readconnroute/

[Read-Only-Service]
type=service
router=readconnroute
servers=server2,server3
user=wang
passwd=111111
router_options=slave
weightby=serv_weight

ReadWriteSplit documentation:

https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-22-readwritesplit/

[Read-Write-Service]
type=service
router=readwritesplit
servers=server1,server2,server3
user=wang
passwd=111111

This

service enables the use of the MaxAdmin interface

MaxScale administration guide:

https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-22-maxadmin-admin-interface/

[MaxAdmin-Service]
type=service
router=cli

Listener definitions for the services

These

listeners represent the ports the

services will listen on.

[Read-Only-Listener]
type=listener
service=Read-Only-Service
protocol=MariaDBClient
port=6044

[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=MariaDBClient
port=6033

[MaxAdmin-Listener]
type=listener
service=MaxAdmin-Service
protocol=maxscaled
socket=default


启动maxscale

[root@localhost~]# systemctl start maxscale

查看错误日志

[root@localhost~]# tail -100 /var/log/maxscale/maxscale.log

没有报错就成功了

Maxadmin是登陆maxscale管理界面的命令

blog.csdnimg.cn/20181121134558383.png)

查看maxscale列表服务

在这里插入图片描述

查看服务器状态

mariadb+MHA+maxcale_第11张图片

mariadb+MHA+maxcale_第12张图片

查看监听列表

                          Keepalived

安装keepalived

yum -y install keepalived

备份配置文件

cp
/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak

修改配置文件

mariadb+MHA+maxcale_第13张图片

启动keepalived

systemctl start keepalived

ip addr show ens33
mariadb+MHA+maxcale_第14张图片

你可能感兴趣的:(架构)