一、概念
1、热备份和备份的区别
热备份指的是:High Available(HA)即高可用,而备份指的是Backup,数据备份的一种。这是两种不同的概念,应对的产品也是两种功能上完全不同的产品。热备份主要保障业务的连续性,实现的方法是故障点的转移。而备份,主要目的是为了防止数据丢失,而做的一份拷贝,所以备份强调的是数据恢复而不是应用的故障转移。
2、什么是双机热备"htmlcode">
总结 以上所述是小编给大家介绍的阿里云服务器手动实现mysql双机热备的两种方式,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
# coding: utf8
import subprocess
from email.mime.text import MIMEText
import smtplib
import os
#因为这里用的Java的springboot,如果切换备机,需要修改部分yml文件
YML_PATH = ''
NEW_YML = ''
msg_from = '' # 发送方邮箱
passwd = '' # 填入发送方邮箱的授权码
msg_to = []
def check_mysql():
res = subprocess.Popen('docker ps |grep mysql', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = res.communicate()
if stdout:
res_status = subprocess.Popen("docker ps |grep mysql| awk '{print $7}'", stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
out, err = res_status.communicate()
if out.strip() == "Up":
print 'mysql is ok'
else:
print 'mysql is broken, switch standby machine'
flag = judge_mysql_string()
if flag:
print '已经连接备机,无需切换'
else:
switch_mysql()
else:
print 'mysql is broken, switch standby machine'
flag = judge_mysql_string()
if flag:
print '已经连接备机,无需切换'
else:
switch_mysql()
def switch_mysql():
print '---copy yml----'
subprocess.call('cp {} {}'.format(NEW_YML, YML_PATH), shell=True)
subprocess.call('docker restart tomcat', shell=True)
subject = 'mysql主机故障'
info = 'mysql主机故障,已经切换到备机,请查看主机问题,及时修复,如需切换回去,' content = '<html><meta charset="UTF-8"><body><p style="color: red">{}</p> </body></html>'.format(info)
send_email(subject, content)
print '----end switch---'
def send_email(subject, content):
msg = MIMEText(content, 'html', 'utf-8')
msg['Subject'] = subject
msg['From'] = msg_from
msg['To'] = ','.join(msg_to)
try:
s = smtplib.SMTP_SSL("smtp.qq.com", 465)
s.login(msg_from, passwd)
s.sendmail(msg_from, msg_to, msg.as_string())
except Exception as e:
print e
finally:
s.quit()
def judge_mysql_string():
with open(os.path.join(YML_PATH, 'application.yml'),'r') as f:
res = f.read()
if 'your ip' in res:
return True
else:
return False
check_mysql()
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
阿里云服务器,mysql双机热备
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com