当前位置: 首页 > news >正文

三合一网站是什么广东seo推广

三合一网站是什么,广东seo推广,用.net做视频网站的案例,网站建设吗2019独角兽企业重金招聘Python工程师标准>>> Python days3作业 作业需求 HAproxy配置文件操作 根据用户输入,输出对应的backend下的server信息可添加backend 和sever信息可修改backend 和sever信息可删除backend 和sever信息操作配置文件前进行备份添加s…

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

Python days3作业

作业需求 HAproxy配置文件操作

  1. 根据用户输入,输出对应的backend下的server信息
  2. 可添加backend 和sever信息
  3. 可修改backend 和sever信息
  4. 可删除backend 和sever信息
  5. 操作配置文件前进行备份
  6. 添加server信息时,如果ip已经存在则修改;如果backend不存在则创建;若信息与已有信息重复则不操作
  • [x] 博客
  • [x] 查询backend下的server信息
  • [x] 添加backend和server信息
  • [ ] 修改backend 和sever信息
  • [x] 删除backend和server信息

博客地址

ygqygq2的博客地址

基本流程图

HAproxy配置文件操作

程序代码

#!/usr/bin/env python
# _*_coding:utf-8_*_
'''* Created on 2016/11/7 21:24.* @author: Chinge_Yang.
'''import shutil
import jsondef list_function():print("Please choice the ID of a action.".center(50, "#"))print("【1】.Fetch haproxy.cfg backend infomation.")print("【2】.Add haproxy.cfg backend infomation.")print("【3】.Delete haproxy.cfg backend infomation.")print("End".center(50, "#"))def fetch(backend):# 取出backend相关server信息result = []  # 定义结果列表with open("haproxy.cfg", "r", encoding="utf-8") as f:  # 循环读取文件flag = False  # 标记为假for line in f:# 以backend开头line = line.strip()if line.startswith("backend") and line == "backend " + backend:flag = True  # 读取到backend开头的信息,标记为真continue# 下一个backend开头if flag and line.strip().startswith("backend"):flag = Falsebreak# server信息添加到result列表if flag and line.strip():result.append(line.strip())return resultdef writer(backend, record_list):with open("haproxy.cfg", "r") as old, open("new.cfg", "w") as new:flag = Falsefor line in old:if line.strip().startswith('backend') and line.strip() == "backend " + backend:flag = Truenew.write(line)for new_line in record_list:new.write(" " * 4 + new_line + "\n")continue  # 跳到下一次循环,避免下一个backend写二次if flag and line.strip().startswith("backend"):  # 下一个backendflag = Falsenew.write(line)continue  # 退出此循环,避免server信息二次写入if line.strip() and not flag:new.write(line)def add(backend, record):global change_flagrecord_list = fetch(backend)  # 查找是否存在记录if not record_list:  # backend不存在, record不存在with open('haproxy.cfg', 'r') as old, open('new.cfg', 'w') as new:for line in old:new.write(line)# 添加新记录new.write("\nbackend " + backend + "\n")new.write(" " * 4 + record + "\n")print("\033[32;1mAdd done\033[0m")change_flag = Trueelse:  # backend存在,record存在if record in record_list:print("\033[31;1mRecord already in it,Nothing to do!\033[0m")change_flag = Falseelse:  # backend存在,record不存在record_list.append(record)writer(backend, record_list)print("\033[32;1mAdd done\033[0m")change_flag = Truedef delete(backend, record):global change_flagrecord_list = fetch(backend)  # 查找是否存在记录if not record_list:  # backend不存在, record不存在print("Not match the backend,no need delete!".center(50, "#"))change_flag = Falseelse:  # backend存在,record存在if record in record_list:record_list.remove(record)  # 移除元素writer(backend, record_list)  # 写入print("\033[31;1mDelete done\033[0m")change_flag = Trueelse:  # backend存在,record不存在print("Only match backend,no need delete!".center(50, "#"))change_flag = Falsereturn change_flagdef output(servers):# 输出指定backend的server信息print("Match the server info:".center(50, "#"))for server in servers:print("\033[32;1m%s\033[0m" % server)print("#".center(50, "#"))def input_json():# 判断输入,要求为json格式continue_flag = Falsewhile continue_flag is not True:backend_record = input("Input backend info(json):").strip()try:backend_record_dict = json.loads(backend_record)except Exception as e:print("\033[31;1mInput not a json data type!\033[0m")continuecontinue_flag = Truereturn backend_record_dictdef operate(action):global change_flagif action == "fetch":backend_info = input("Input backend info:").strip()result = fetch(backend_info)  # 取出backend信息if result:output(result)  # 输出获取到的server信息else:print("\033[31;1mNot a match is found!\033[0m")elif action is None:print("\033[31;1mNothing to do!\033[0m")else:backend_record_dict = input_json()  # 要求输入json格式for key in backend_record_dict:backend = keyrecord = backend_record_dict[key]if action == "add":add(backend, record)elif action == "delete":delete(backend, record)if change_flag is True:  # 文件有修改,才进行文件更新# 将操作结果生效shutil.copy("haproxy.cfg", "old.cfg")shutil.copy("new.cfg", "haproxy.cfg")result = fetch(backend)output(result)  # 输出获取到的server信息def judge_input():# 判断输入功能编号,执行相应步骤input_info = input("Your input number:").strip()if input_info == "1":  # 查询指定backend记录action = "fetch"elif input_info == "2":  # 添加backend记录action = "add"elif input_info == "3":  # 删除backend记录action = "delete"elif input_info == "q" or input_info == "quit":exit("Bye,thanks!".center(50, "#"))else:print("\033[31;1mInput error!\033[0m")action = Nonereturn actiondef main():exit_flag = Falsewhile exit_flag is not True:global change_flagchange_flag = Falselist_function()action = judge_input()operate(action)if __name__ == '__main__':main()

HAproxy配置文件操作

1.程序说明

实现功能如下

  • [x] 查询backend下的server信息
  • [x] 添加backend和server信息
  • [ ] 修改backend 和sever信息
  • [x] 删除backend和server信息

2.程序测试配置文件

cat haproxy.cfg

globallog 127.0.0.1 local2daemonmaxconn 256log 127.0.0.1 local2 info
defaultslog globalmode httptimeout connect 5000mstimeout client 50000mstimeout server 50000msoption  dontlognull
listen stats :8888stats enablestats uri   /adminstats auth  admin:1234
frontend 51cto.combind 0.0.0.0:80option httplogoption httpcloseoption  forwardforlog globalacl www hdr_reg(host) -i test01.example.comuse_backend test01.example.com if www
backend test01.example.comserver 100.1.7.10 100.1.7.10 weight 20 maxconn 3000
backend test.comserver 100.1.7.90 100.1.7.90 weight 20 maxconn 3000server 100.1.7.66 100.1.7.66 weight 20 maxconn 3000server 100.1.7.27 100.1.7.27 weight 20 maxconn 3000server 100.1.7.13 100.1.7.13 weight 20 maxconn 3000backend www.test.comserver 100.1.7.13 100.1.7.13 weight 20 maxconn 3000

3.程序测试

python config_haproxy.py

执行结果:

########Please choice the ID of a action.#########
【1】.Fetch haproxy.cfg backend infomation.
【2】.Add haproxy.cfg backend infomation.
【3】.Delete haproxy.cfg backend infomation.
#######################End########################
Your input number:1
Input backend info:test.com
##############Match the server info:##############
server 100.1.7.90 100.1.7.90 weight 20 maxconn 3000
server 100.1.7.66 100.1.7.66 weight 20 maxconn 3000
server 100.1.7.27 100.1.7.27 weight 20 maxconn 3000
##################################################
########Please choice the ID of a action.#########
【1】.Fetch haproxy.cfg backend infomation.
【2】.Add haproxy.cfg backend infomation.
【3】.Delete haproxy.cfg backend infomation.
#######################End########################
Your input number:2
Input backend info(json):{"test.com":"testtest.com"}
Add done
##############Match the server info:##############
server 100.1.7.90 100.1.7.90 weight 20 maxconn 3000
server 100.1.7.66 100.1.7.66 weight 20 maxconn 3000
server 100.1.7.27 100.1.7.27 weight 20 maxconn 3000
testtest.com
##################################################
########Please choice the ID of a action.#########
【1】.Fetch haproxy.cfg backend infomation.
【2】.Add haproxy.cfg backend infomation.
【3】.Delete haproxy.cfg backend infomation.
#######################End########################
Your input number:1
Input backend info:test.com
##############Match the server info:##############
server 100.1.7.90 100.1.7.90 weight 20 maxconn 3000
server 100.1.7.66 100.1.7.66 weight 20 maxconn 3000
server 100.1.7.27 100.1.7.27 weight 20 maxconn 3000
testtest.com
##################################################
########Please choice the ID of a action.#########
【1】.Fetch haproxy.cfg backend infomation.
【2】.Add haproxy.cfg backend infomation.
【3】.Delete haproxy.cfg backend infomation.
#######################End########################
Your input number:3
Input backend info(json):{"test.com":"testtest.com"}
Delete done
##############Match the server info:##############
server 100.1.7.90 100.1.7.90 weight 20 maxconn 3000
server 100.1.7.66 100.1.7.66 weight 20 maxconn 3000
server 100.1.7.27 100.1.7.27 weight 20 maxconn 3000
##################################################
########Please choice the ID of a action.#########
【1】.Fetch haproxy.cfg backend infomation.
【2】.Add haproxy.cfg backend infomation.
【3】.Delete haproxy.cfg backend infomation.
#######################End########################
Your input number:4
Input error!
Nothing to do!
########Please choice the ID of a action.#########
【1】.Fetch haproxy.cfg backend infomation.
【2】.Add haproxy.cfg backend infomation.
【3】.Delete haproxy.cfg backend infomation.
#######################End########################
Your input number:3
Input backend info(json):d
Input not a json data type!
Input backend info(json):{"test01.example.com":"server 100.1.7.27 100.1.7.27 weight 20 maxconn 3000"}
########Only match backend,no need delete!########
########Please choice the ID of a action.#########
【1】.Fetch haproxy.cfg backend infomation.
【2】.Add haproxy.cfg backend infomation.
【3】.Delete haproxy.cfg backend infomation.
#######################End########################
Your input number:q
###################Bye,thanks!####################Process finished with exit code 1

转载于:https://my.oschina.net/ygqygq2/blog/794570

http://www.lbrq.cn/news/2597743.html

相关文章:

  • 自已能做网站建设吗网站优化排名软件网
  • 在哪个网站可以做外单衣服网站的推广方案的内容有哪些
  • 信誉好的盐城网站开发搜索引擎优化教材答案
  • 去哪找网站建设公司游戏代理推广渠道
  • 做违法网站媒体邀约
  • 怎样做企业网站建设深圳seo网络优化公司
  • 上海做网站大的公司站长统计网站统计
  • 专业做网站建设公司seo关键词排名优化报价
  • wordpress网站导航菜单插件百度域名查询官网
  • 手机触屏网站幻灯片优化推广关键词
  • 杨浦专业做网站关键词排名代做
  • 新建的网站如何做seo网络推广软文怎么写
  • 微信网站跳转链接怎么做怎么进行推广
  • 网站建设广州营销网站设计
  • 电子商务网站开发技术毕业论文百度首页广告多少钱
  • wordpress移动端底部添加菜单二十条优化疫情措施
  • 医院网站制作好吗合肥seo推广外包
  • 网站建设 成功案例seo自学网app
  • 网站建设策划长沙网络推广外包费用
  • 昆明网站建设公司电话谷歌seo培训
  • 百度网站的网址在线客服系统
  • 怎么让人搜索到自己做的网站2345网址导航桌面版
  • 金华企业自助建站系统友链交换平台
  • 建网站需要备案吗百度网络营销的概念
  • 怎么用自己的服务器做网站免费网站代理访问
  • 网站建设ftp蔡甸seo排名公司
  • 做色流网站要注意什么地方推广产品的方式有哪些
  • 做网站 图片素材怎么找收录查询工具
  • 天津商务网站建设网络关键词
  • 个人网站免费模板百度账户代运营
  • 超轻量级通用人脸检测模型解析:1MB以下的AI如何实现实时检测
  • 百度翻译详解:包括PaddleNLP、百度AI开放平台、接口逆向(包括完整代码)
  • Python中的sys.path与PYTHONPATH全解析:模块导入路径的底层机制与最佳实践
  • 07.config 命令实现动态修改配置和慢查询
  • Spring+K8s+AI实战:3全栈开发指南
  • Jupyter Notebook 中高效处理和实时展示来自 OpenCV 和 Pillow 的图像数据探究