MySQL 之 MHA + ProxySQL + keepalived 实现读写分离,高可用(三)
设置Keepalived VIP切换邮件告警
修改keepalived.conf配置:
[root@server01 keepalived]# cat keepalived.conf
! Configuration File for keepalived global_defs {
notification_email {
saltstack@163.com
}
notification_email_from dba@dbserver.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id MySQL-HA
}
vrrp_script vs_mysql_100 {
script "python /etc/keepalived/checkProxySQL.py -h localhost -P 6033"
interval 5
}
vrrp_instance VI_1 {
state BACKUP
nopreempt
interface eth0
virtual_router_id 51
priority 150
advert_int 1
nopreempt authentication {
auth_type PASS
auth_pass 1111
}
track_script {
vs_mysql_100
}
virtual_ipaddress {
10.200.22.178
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
通知 notify.sh:
#!/bin/bash contact='root@localhost' notify() {
local mailsubject="$(hostname) to be $1, vip floating"
local mailbody="$(date +'%F %T'): vrrp transition, $(hostname) changed to be $1"
python /etc/keepalived/sendMail.py "$mailsubject" "$mailbody"
echo $mailbody >> /etc/keepalived/notify.log
} case $ in
master)
notify master
;;
backup)
notify backup
;;
fault)
notify fault
;;
*)
echo "Usage: $(basename $0) {master|backup|fault}"
exit
;;
esac
发送邮件 sendMail.py:
#!/usr/bin/python
# -*- coding: utf- -*-
# author xuaiqi
# date import os
import time
import shutil
import MySQLdb
import smtplib
#import requests
import datetime from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import Encoders
from datetime import datetime import sys
default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
reload(sys)
sys.setdefaultencoding(default_encoding) # email info
mailserver = "smtp.vcredit.com"
EMAIL_USERNAME = 'dbmonitor@vcredit.com'
EMAIL_PASSWORD = 'dbmonitor1234!!' title=sys.argv[]
contents=sys.argv[] #发送邮件
def send_mail(title, to_list):
me = "dbmonitor@vcredit.com" def _create_msg():
msg = MIMEMultipart('related')
msg['Subject'] = title
msg['From'] = me
msg['To'] = ';'.join(to_list)
msg['date'] = '2012-3-16' #解决邮件发送时间不对
msg.preamble = 'This is a multi-part message in MIME format.'
msg_text = MIMEText(contents, 'html','utf-8')
msg_alternative = MIMEMultipart('alternative')
msg_alternative.attach(msg_text)
msg.attach(msg_alternative)
#print msg
return msg
try:
server = smtplib.SMTP()
server.connect(mailserver)
server.login(EMAIL_USERNAME, EMAIL_PASSWORD)
server.sendmail(me, to_list, _create_msg().as_string())
server.close()
print 'send mail Ok!'
except Exception, e:
print e print"--------------------------------------", datetime.now().strftime('%Y-%m-%d %H:%M:%S'),"Start sending mail --------------------"
if __name__ == '__main__':
user=['yujun02@vcredit.com','zhanglin04@vcredit.com','xuaiqi@vcredit.com']
print "发送的用户",user
print "内容",contents
send_mail(title, user)
print"---------------------------------", datetime.now().strftime('%Y-%m-%d %H:%M:%S'),"Sucessfull sending mail --------------------"
设置MHA切换邮件通知
报告脚本 send_report.py:
#!/usr/bin/env python
#-*- encoding:utf- -*-
#-------------------------------------------------------------------------------
# Name: send_report.py
# Author: zhoujy
#----------------------------------------------
import os
import sys
import time
import datetime
import smtplib
import subprocess
import fileinput
import getopt
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.Utils import COMMASPACE, formatdate reload(sys)
sys.setdefaultencoding('utf8') def send_mail(to, subject, text, from_mail, server="localhost"):
message = MIMEMultipart()
message['From'] = from_mail
message['To'] = COMMASPACE.join(to)
message['Date'] = formatdate(localtime=True)
message['Subject'] = subject
message.attach(MIMEText(text,_charset='utf-8'))
smtp = smtplib.SMTP(server)
smtp.login(from_mail, 'dbmonitor1234!!')
smtp.sendmail(from_mail, to, message.as_string())
smtp.close() if __name__ == "__main__":
opts,args = getopt.getopt(sys.argv[:],"h",["orig_master_host=","new_master_host=","new_slave_hosts=","conf=","subject=","body=","app_vip=","new_master_ssh_port=","ssh_user="])
# print opts,args
for lines in opts:
key,values = lines
if key == '--orig_master_host':
orig_master_host = values
if key == '--new_master_host':
new_master_host = values
if key == '--new_slave_hosts':
new_slave_hosts = values
if key == '--subject':
subject = values
if key == '--body':
body = values
# text = sys.stdin.read()
mail_list = ['xuaiqi@vcredit.com','yujun02@vcredit.com','zhanglin04@vcredit.com']
send_mail(mail_list, subject.encode("utf8"), body, "dbmonitor@vcredit.com", server="smtp.vcredit.com")
Master基础配置:
[server default]
user=root
password=iforgot
ssh_user=root
repl_user=repl
repl_password=repl
ping_interval=
#master_binlog_dir= /var/lib/mysql,/var/log/mysql
secondary_check_script=masterha_secondary_check -s 10.200.22.136 -s 10.200.22.138 -s 10.200.22.223
master_ip_failover_script="/etc/mha/scripts/master_ip_failover"
master_ip_online_change_script="/etc/mha/scripts/master_ip_online_change"
report_script="/etc/mha/scripts/send_report.py"
测试验证
keepalived vip切换
mha切换
MySQL 之 MHA + ProxySQL + keepalived 实现读写分离,高可用(三)的更多相关文章
- MySQL 之 MHA + ProxySQL + keepalived 实现读写分离,高可用(二)
ProxySQL安装 yum/rpm安装 在github或官网上可以下载rpm包,wiki的Getting start章节有详细介绍. cat <<EOF | tee /etc/yum.r ...
- MySQL 之 MHA + ProxySQL + keepalived 实现读写分离,高可用(一)
准备服务器: docker network create --subnet=192.168.0.0/16 staticnetdocker run -d --privileged -v `pwd`/my ...
- MHA+ProxySQL实现读写分离高可用
最近在研究ProxySQL,觉得还挺不错的,所以就简单的折腾了一下,ProxySQL目前也是Percona在推荐的一个读写分离的中间件.关于详细的介绍可以参考官方文档.https://github.c ...
- MHA+ProxySQL 读写分离高可用
文档结构如下: 1.ProxySQL说明 ProxySQL是mysql的一款中间件的产品,是灵活的mysql代理层,可以实现读写分离,支持query路由器的功能,支持动态指定sql进行缓存,支持动态加 ...
- MySQL for OPS 09:MHA + Atlas 实现读写分离高可用
写在前面的话 前面做了 MHA 高可用,但是存在这样一个问题,我们花了 4 台机器,但是最终被利用起来的也就一台,主库.这样硬件利用率才 25%,这意味着除非发生故障,不然其他几台机器都是摆设.明显的 ...
- MySQL中间件之ProxySQL(10):读写分离方法论
返回ProxySQL系列文章:http://www.cnblogs.com/f-ck-need-u/p/7586194.html 1.不同类型的读写分离 数据库中间件最基本的功能就是实现读写分离,Pr ...
- MySQL读写分离高可用集群及读操作负载均衡(Centos7)
目录 概述 keepalived和heartbeat对比 一.环境 二.部署 部署lvs代理和keepalived MySQL+heartbeat+drbd的部署 MySQL主从复制 web服务器及a ...
- mysql读写分离[高可用]
顾名思义, 在mysql负载均衡中有多种方式, 本人愚钝,只了解驱动中间件和mysql_proxy两种方式, 对于驱动,利用的是ReplicationDriver,具体请看远哥的这篇文章: MySQL ...
- Atlas读写分离[高可用]
Atlas下载地址: https://github.com/Qihoo360/Atlas/releases Atlas是出于360的, 比mysql-proxy更稳定, 部署起来更方便. 环境: pr ...
随机推荐
- CSV空行问题
当写入CSV时生成的数据会有空行如果加入 newline =‘’ 不会新增空行 writefile = open('result.csv','w',newline =‘’) 原贴 https://bl ...
- 浅谈ES6新增数据类型:Symbol
面试中喜闻乐见的问题就是问我们的ES6新增了哪些个新特性 这篇文章一起学习一下新增的数据类型:Symbol JS的原始数据类型:6种Boolean,String,Undefined,NULL,Numb ...
- JavaScript中常用的BOM对象(属性、方法)
window对象 定义: 一个浏览器窗口实例 与窗口有关的信息(应用程序编程接口) ECMAScript规定的Global对象 方法 open(url),返回标识符 引用 即将打开窗口的.(调用该引用 ...
- 【EMV L2】Select PSE应用选择相关的卡片数据格式
The data field of the response message contains the FCI specific to the selected PSE, DDF, or ADF. 一 ...
- oc语言的Foundation框架(学习笔记2)
紧接上文…… 4.集合对象 4.1数组 1.基本概念 Foundation中的数组(NSArray,NSMutableArray)是一组有序的对象集合,通过索引下标获取到数组中的各个元素,也分可变和不 ...
- Java中PO、DO、TO、DTO、 VO、 BO、POJO 、DAO的概念
本文系转载-原创@HollisChuang :http://www.hollischuang.com/archives/553 1.PO(persistant object) 持久对象 在 o/r ...
- UVa 712
这个题根本不用建树,因为是完全二叉树,可以把这个想成二进制.对于根是二进制数的首位,之后依次类推.到最后的叶子节点就是从0到pow(2,n)-1. 关键在于在第一次输入的不是按照x1,x2,x3,x4 ...
- Centos7编译opencv3.4.1
Centos7编译opencv3.4.1 参考博客 https://blog.csdn.net/wjbwjbwjbwjb/article/details/79111996 1.配置epel源 yum ...
- 12集合(3)-----Map
一.总体分类 Collection(包括方法add,remove,contains,clear,size) List(接口) LinkedList ArrayList Vector---Stack 2 ...
- linux 修改配色
PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\\$ " ORvim ~/ ...