运维平台化saltstack和jinja2模板构建高可用集群配置平台

前言:

    最近正在做一个集群配置平台,以前也做过类似的demo,记得是去年做的时候用的是paramiko模块,先说他的连接配置是用ssh,交互也有时用pexpect。在复杂的配置下会经常出问题的。 配置主要是出在正则匹配的方面。


   现在到了新公司,第一件是就是重构代码,目的是做成一个全网集群的配置工具,支持nginx、lvs、haproxy多种集群配置的平台。 里面含有流程的自动流转审批,在测试服务器上做测试,配置文件的操作之前的配置,及出问题时候的回滚。


因为新公司的环境是puppet,打算推广下saltstack !  我还是喜欢saltsatck那种简便的二次开发。

自己现在的思路是:  

通过web框架的模板来渲染配置配置,最好是把nginx.conf keepalived.conf 整形到 yaml类似的格式里面。推送到客户端只是get url,通过接口的ip和类型,给你渲染出配置文件,直接下载就行了。


这能说是没招呀~  哎。。。。   saltstack 这东西不错 !


下面的集群管理平台,我自己也就写了两天,把前端页面及后端的mysql库做了设计。  我会把后续思路和解决方案更新给大家下。  还没有上线,只是给大家一个样子参考 ~



前端没啥东西,就是写了点表单的验证,及美化的js特效。

wKiom1M6ekyARktGAATtBF09qOY127.jpg


对于集群的参数,做了特定的格式规范 !

wKiom1LSryTTW3E5AAOKH9yeokI259.jpg


特殊说明,这里可以填写一些特殊的需求 !

wKioL1LSr0PyLbBHAAOsh6w7FW0163.jpg


点提交后,会给领导发邮件等待确认~

wKiom1LSr1uCRJ1QAAOaHZOWLbw197.jpg


数据是随便写的 ~

wKiom1LTpS2QdnojAAKS8XHPWaI010.jpg


mysqldb 获取timestamp的出现点问题,大家可以参考下 ~


ValueError
ValueError: unsupported format character 'm' (0x6d) at index 138
Traceback (most recent call last)


对于%的符号,尤其格式化时间用的多,需要这么搞

FROM_UNIXTIME(unix_timestamp(ltime),"%%m-%%d %%H:%%i")


wKioL1LTt6ij5BNqAALSOwDK3SY134.jpg

领导说,页面看起来不舒服,改版

wKioL1LU8dPTvIzyAAWIuyfVO1w614.jpg



wKioL1LWITbQGBJRAAQHXGoCUpk601.jpg


wKioL1LXrA6jFcHCAAMZUWP0OwQ803.jpg



wKiom1LZDsvga53tAAK6gaoIwL0240.jpg

关于saltstack这边对于lvs yaml的过程


global_defs: [email protected]
vrrp_sync_group: [VI_1,VI_2]
vrrp_instance:
    VI_1:
        state: master
        interface: eth0
        virtual_router_id: 51
        priority: 100
        advert_int: 1
        authentication:
            auth_type: PASS
            auth_pass: 1111
        virtual_ipaddress:
            vip: 192.168.1.100
        virtual_server:
            delay_loop: 5
            lb_algo rr: wlc
            lb_kind DR: DR
            persistence_timeout: 50
            protocol: TCP
            - real_server:
                ip: 192.168.1.236
                port: 80
                weight: weight
                mode: HTTP_GET
                heathmonitor:
                    path: /mo/monitor.html
                    connect_timeout: 3
                    nb_get_retry: 3
                    delay_before_retry: 3
            - real_server:
                ip: 192.168.1.236
                port: 80
                weight: weight
                mode: HTTP_GET
                heathmonitor:
                    path: /mo/monitor.html
                    connect_timeout: 3
                    nb_get_retry: 3
                    delay_before_retry: 3


wKioL1Lc16DjfiqUAANifrJPvJg099.jpg

遇到了一个问题,jinja2的list循环的时候取出他的index 。

这里是用在lvs haproxy nginx的数据渲染的 !


{% for i in ldata['vrrp_sync_group'] %}
       {{ ldata['vrrp_instance']['VI_1']['virtual_ipaddress'][loop.index0]['vip_server']['vip'] }}
{% endfor %}
{% for i in range(ldata['vrrp_sync_group']|count) %}
       {{ ldata['vrrp_instance']['VI_1']['virtual_ipaddress'][loop.index0]['vip_server']['vip'] }}
{% endfor %}


已经渲染好keepalived.conf 的测试页面

wKioL1LfGYKhRMniAAHP6cUoIDA018.jpg


wKiom1LkyazAnk1rAAXnpn5obao825.jpg

wKiom1Lk2Q-AfgfSAAN2FEhYrw4712.jpg



样式更新了下,都放在一起,确实有点紧

wKioL1M6GWGjkZdAAALnrHD7agc602.jpg



wKiom1L5ozaQiEISAAdjWaajjBA886.jpg


又加了几个功能,把昨天写的逻辑重新变更下,明天开始做后端 !


wKiom1L67BrSEYg8AAfk0OOSZBU935.jpg


实时流量图


wKioL1L8c0eRu8aIAAZ_E2uyt9E732.jpg


wgetconf


jinja2的一个问题    {% if type == "kkk" %} 里面的type是jinja2里面的关键字  大家避开这个关键字就行了。。。 原本以为是自己逻辑的问题,搞了半天是关键字的冲突 !!!




wKioL1MBvELy4G0EAAUh_GX0tig162.jpg

这个实现的原理就是利用saltstack的pubsub速度,实现实时数据收集 !


wKiom1MC-_XhfrdiAAMpZ8eHE54321.jpg


这两天在忙dba的平台,这个东西进展有点缓慢!

wKiom1MQbA7CtDZ5AAKc9L0E00M995.jpg


wKiom1MQbBixiOD7AAPB8MqMQsw535.jpg


加了表单验证

wKioL1MZgpvTk_NuAALhO-TV04k330.jpg

针对返回值的各种判断,和连续ajax

wKiom1MZg8rRkccWAAN__tAhorU183.jpg


服务器的本身调试页面!

wKiom1Mi2OrQ9RbnAAeL2oXLUwU317.jpg

日志图表分析

wKiom1MlPUzRXqObAAQDcpFVtUA937.jpg



wKiom1MlRQXQf0UzAAZSOoJddl0817.jpg


wKioL1Mz5k7DpLUJAAW5xcm1CqM466.jpg


如果你的uwsgi碰见 500的错误,请一定要先检查你的app程序。


--- no python application found, check your startup logs for errors ---
[pid: 19956|app: -1|req: -1/25] 10.58.102.250 () {46 vars in 1025 bytes} [Tue Apr  8 11:24:00 2014] POST /dataapi => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 19958|app: -1|req: -1/26] 10.58.102.250 () {46 vars in 1025 bytes} [Tue Apr  8 11:24:05 2014] POST /dataapi => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 19958|app: -1|req: -1/27] 10.58.101.248 () {38 vars in 931 bytes} [Tue Apr  8 11:24:07 2014] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 19958|app: -1|req: -1/28] 10.58.102.250 () {46 vars in 1025 bytes} [Tue Apr  8 11:24:10 2014] POST /dataapi => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 19956|app: -1|req: -1/29] 10.58.102.250 () {46 vars in 1025 bytes} [Tue Apr  8 11:24:15 2014] POST /dataapi => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 19956|app: -1|req: -1/30] 10.58.102.250 () {46 vars in 1025 bytes} [Tue Apr  8 11:24:20 2014] POST /dataapi => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 19956|app: -1|req: -1/31] 10.58.102.250 () {46 vars in 1025 bytes} [Tue Apr  8 11:24:25 2014] POST /dataapi => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 19958|app: -1|req: -1/32] 10.58.101.248 () {36 vars in 604 bytes} [Tue Apr  8 11:24:28 2014] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 19936|app: -1|req: -1/33] 10.58.101.248 () {36 vars in 555 bytes} [Tue Apr  8 11:24:28 2014] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 19956|app: -1|req: -1/34] 10.58.102.250 () {46 vars in 1025 bytes} [Tue Apr  8 11:24:30 2014] POST /dataapi => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

陆续更新 ~


本文出自 “峰云,就她了。” 博客,谢绝转载!

你可能感兴趣的:(nginx,LVS,haproxy,saltstack,saltstack,saltstack,saltstack,jinja2)