温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

100台redis如何批量关闭主库aof开启从库aof

发布时间:2021-11-15 10:25:45 来源:亿速云 阅读:183 作者:小新 栏目:编程语言

这篇文章主要介绍100台redis如何批量关闭主库aof开启从库aof,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

#!/usr/bin/env python
#encoding = utf-8
 
"""
author: luhuijun
create on time: 20171002
config File Mode
127.0.0.1,6379,xxxxxxxx,0
127.0.0.1,6380,xxxxxxxx,0
"""

import datetime
import redis
 
def redis_conect(host,port,passwd,db):
    r = redis.Redis(
        host=host,
        port=port,
        db=0)
    return r
 
 
def readconfig(path):
    file=open(path,"r")
    result=file.readlines()
    return result
    file.close()
 
def main():
    try:
        result = readconfig('../etc/check_redis_cluster_config.ini')
        for i in result:
            i=i.split(",")
            mhost, mport, mpasswd, mdb = i[0], i[1], i[2], i[3]
            m = redis_conect(mhost,mport,mpasswd,mdb)
            #此句忽略,这会写一个带日期的key,用来监控主从同步,基于业务的监控.
            k,v= 'dba_check',datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            roles = m.info("replication")['role']
            if roles == 'master':
                # print m.info()
                if m.config_get("appendonly")['appendonly'] == 'yes':
                    m.config_set('appendonly','no')
                    m.config_rewrite()
                else:
                    continue
            else:
                if m.config_get("appendonly")['appendonly'] == 'no':
                    m.config_set("appendonly", "yes")
                    m.config_rewrite()
                else:
                    continue
    except Exception,ex:
        print Exception,":",ex
 
 
if __name__=="__main__":
    main()

以上是“100台redis如何批量关闭主库aof开启从库aof”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI