测试环境:F5-Ltm V11.6.0版本

目的:自动化发布铺垫,通过远程Api命令调用F5 Rest 实现 查看,增加,开关,节点和配置Irule规则。

资源地址:https://devcentral.f5.com iControl REST API Reference Version 12.0.Pdf

测试F5地址:10.129.9.222

备注:官方文档PDFjson有部分错误



#########F5 iControl REST  APi Url 控制方法#####

curl -k -u username:password -H "Content-Type: application/json"

-X http-method uri


##########标准方法+Json输出即可###########

http-method  GET  PUT POST DEL

uri  https://F5-IP/mgmt/tm/*



#########查看pool_member当前连接数#############

#查看pool全部成员连接状态,curConns":{"value":0}

curl -k -u admin:mysecret -X GET 

https://10.129.9.222/mgmt/tm/ltm/pool/xzm_pool/members/stats/


#查看单独xzm-pool成员连接状态,curConns":{"value":0}

https://10.129.9.222/mgmt/tm/ltm/pool/xzm_pool/members/stats/



##########修改查看pool和member########


#查看所有Pool和member

curl -k -u admin:mysecret -X GET https://10.129.9.222/mgmt/tm/ltm/pool


#增加tcb-pool和member,192.168.25.32:80

curl -k -u admin:mysecret -H "Content-Type: application/json" -X POST -d '{"name":"tcb-pool","partition":"Common", "members":[{"name":"192.168.25.32:80","description":"Web server"}]}' https://10.129.9.222/mgmt/tm/ltm/pool


#修改mem成员描述  ,此操作是覆盖配置,请注意

curl -k -u admin:mysecret -H "Content-Type: application/json" -X PUT -d '{"name":"tcb-pool2","partition":"Common","members":[{"name":"192.168.25.32:80","session":"user-enabled"}]}' https://10.129.9.222/mgmt/tm/ltm/pool/tcb-pool2


#设置Member_enable,会清空之前member

curl -k -u admin:mysecret -H "Content-Type: application/json" -X PUT -d '{"name":"tcb-pool2","partition":"Common","members":[{"name":"192.168.25.32:80","session":"user-enabled"}]}' https://10.129.9.222/mgmt/tm/ltm/pool/tcb-pool2


#设置Member_disable,会清空之前member

curl -k -u admin:mysecret -H "Content-Type: application/json" -X PUT -d '{"name":"tcb-pool2","partition":"Common","members":[{"name":"192.168.25.32:80","session":"user-disabled"}]}' https://10.129.9.222/mgmt/tm/ltm/pool/tcb-pool2


#设置Pool增加2个 Member

curl -k -u admin:mysecret -H "Content-Type: application/json" -X POST -d '{"name":"xzm_pool","partition":"Common","members":[{"name":"a:80","session":"user-enabled"},{"name":"b:80","session":"user-enabled"}]}' https://10.129.9.222/mgmt/tm/ltm/pool/xzm_pool


#########单独控制member状态#########


#单独管理Member_disabled控制a:80节点

curl -k -u admin:mysecret -H "Content-Type: application/json" -X PUT -d '{"session":"user-disabled"}' https://10.129.9.222/mgmt/tm/ltm/pool/xzm_pool/members/a:80


#单独启动Member_enabled控制a:80节点

curl -k -u admin:mysecret -H "Content-Type: application/json" -X PUT -d '{"session":"user-enabled"}' https://10.129.9.222/mgmt/tm/ltm/pool/xzm_pool/members/a:80





#########查看和修改Vs_rule规则#####

#查看某vs_Rule规则 irule

curl -k -u admin:mysecret -X GET https://10.129.9.222/mgmt/tm/ltm/virtual/~Common~vs_tms?


#查看所有Virtual Servers_irule规则

curl -k -u admin:mysecret -X GET https://10.129.9.222/mgmt/tm/ltm/virtual

#查看Virtual Servers实例vs_tms规则

curl -k -u admin:mysecret -X GET https://10.129.9.222/mgmt/tm/ltm/virtual/vs_tms

#增加Vs实例Irule规则,

curl -k -u admin:mysecret -H "Content-Type: application/json" -X PUT -d '{"rules":["/Common/out_log","/Common/out_log2"]}' https://10.129.9.222/mgmt/tm/ltm/virtual/vs_tms

curl -k -u admin:mysecret -H "Content-Type: application/json" -X PUT -d '{"rules":["/Common/out_log"]}' https://10.129.9.222/mgmt/tm/ltm/virtual/vs_tms


补充:中间还有很多参数可以,查看官方说明文档,这种方式虽然是结构化JSson,需要有又一个集中存储所有pool和member的地方

  1. 通过遍历所有,保存pool和member发布服务器清单https://10.129.9.222/mgmt/tm/ltm/pool/xzm_pool/members/stats/ 

  2. 通过清单,生成发布滚动脚本,滚动中需要定期监控节点连接数


#不过感觉这样效率比较慢全不流畅相对负载,

在测试2款自动配置管理工具,ansibler和saltstack

  1. ansbile F5控制模板

    优点:1.SSH安装简单,2.f5官方社区支持,6个人维护,松散维护,但是f5官方模板目前看功能没啥帮助,并且官方没有收录,社区版本目前有一个bug 对pythong 2.7.9以上版本需要手动导入import ssl解决证书问题 

    缺点:支持windows不是特别好,开原版不支持计划调度任务

  2. saltstack F5控制模板

    有点: 1.可以windows客户端和SSH双模式管理,2.支持计划调度 3.F5模块 3个人维护管控严格

    缺点:1.社区模块较少,没有ansbile社区活跃度高,2.功能还没测试暂时保留,

3.  puppet F5控制模板 功能太重,学习成本较高,但是windows支持成熟