博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
day_ha配置文件
阅读量:4964 次
发布时间:2019-06-12

本文共 3064 字,大约阅读时间需要 10 分钟。

流程图:

 

 

代码

1 #!/sur/bin/env python 2 # -*- coding: utf-8 -*- 3 #{"backend": "www.oldboy.org","record":{"server": "100.1.7.90","weight": 20,"maxconn": 30}} 4 import json 5 import sys 6  7 def add_ha(backend_de): 8     backend_dic = json.loads(backend_de) 9     backend_add = 'server %s weight %s maxconn %s'%(backend_dic['record']['server'],backend_dic['record']['weight'],+backend_dic['record']['maxconn'])10     with open("haproxy.conf") as read_f,open("ceshi","w") as write_f :11         for lines in read_f.readlines():12             write_f.write(lines)13         write_f.write('backend'' '+backend_dic['backend']+'\n')14         write_f.write(' '*8+backend_add) #15 16 def delet_ha(backend_de):17     backend_dic = json.loads(backend_de) ##将字符串转换为相印的数据类型18     backned_check=list(bakcned_dic['backend']) #www.oldboy.org19     backend_del = '        server %s weight %s maxconn %s\n'%(backend_dic['record']['server'],backend_dic['record']['weight'],+backend_dic['record']['maxconn']) ##数据类容20     with open("haproxy.conf") as read_f,open("ceshi","w") as write_f :21         for lines in read_f.readline():22             backend_list=[]23             backend_list.append(lines.strip())24             backend_list.append(lines)25             if lines.strip().split()[2] == backned_check:26                 continue27             elif backend_del == lines :28                 backend_list.remove(lines)29         write_f.write(backend_list)30 31 def change_ha(backend_de):32     backend_dic = json.loads(backend_de) ##将字符串转换为相印的数据类型33     backned_check=list(bakcned_dic['backend']) #www.oldboy.org34     backend_del = '        server %s weight %s maxconn %s\n'%(backend_dic['record']['server'],backend_dic['record']['weight'],+backend_dic['record']['maxconn']) ##数据类容35     with open("haproxy.conf") as read_f,open("ceshi","w") as write_f :36         for lines in read_f.readline():37             backend_list=[]38             backend_list.append(lines.strip())39             backend_list.append(lines)40             if lines.strip().split()[2] == backned_check:41                 write_f.write(backend_del)42                 continue43             elif backend_del == lines :44                 print("类容已存在,请确定后再修改")45                 sys.exit()46         write_f.write(backend_list)47 48 while True:49     number_ha = int(input("1、添加\n2、删除\n3、修改\n请输入以上阿拉伯数字:"))50     if number_ha == 1:51         backend_de=input("请输入backend:") #如输入:["bakcend","www.oldboy.org"]52         add_ha(add_file)53     elif number_ha == 2:54         backend_de=input("请输入要删除的bakcned:") #如 www.oldboy.org55         delet_ha(delet_file)56     elif number_ha == 3:57         backend_de=input("请输入要删除的bakcned:")58         change_ha()59     else:60         print("你输入的功能有误,请重新输入")61         continue
代码

ha配置文件

1 frontend oldboy.org2         bind 0.0.0.0:803 4 backend www.oldboy.org5         server 100.1.7.9 1020.1.7.9 weight 20 maxconn 30006 7 backend buy.oldboy.org8         server 100.1.7.90 100.1.7.90 weight 20 maxconn 30000
HA配置文件代码

 

转载于:https://www.cnblogs.com/heweiblog/p/5443608.html

你可能感兴趣的文章
struts2.x + Tiles2.x读取多个xml 配置文件
查看>>
表单校验之datatype
查看>>
python第六篇文件处理类型
查看>>
hdu 3183 A Magic Lamp 贪心
查看>>
ubuntu16系统磁盘空间/dev/vda1占用满的问题
查看>>
面试题14 调整数组顺序使奇数位于偶数前面
查看>>
grid网格布局
查看>>
flask简单的注册功能
查看>>
JSP常用标签
查看>>
dashucoding记录2019.6.7
查看>>
IOS FMDB
查看>>
编码总结,以及对BOM的理解
查看>>
九涯的第一次
查看>>
PHP5.3的VC9、VC6、Thread Safe、Non Thread Safe的区别
查看>>
Android中全屏或者取消标题栏
查看>>
处理器管理与进程调度
查看>>
页面懒加载
查看>>
向量非零元素个数_向量范数详解+代码实现
查看>>
java zip 中文文件名乱码_java使用zip压缩中文文件名乱码的解决办法
查看>>
java if 用法详解_Java编程中的条件判断之if语句的用法详解
查看>>