• Python从零搭建Conf_Web配置管理平台


    环境

    CentOS 6/7 x64

    Python:2 .7.6

    Etcd: 3.2.18

    Confd:0 .16.0

    Nginx: 1.12.1

    效果演示

    yanshi.gif

    一,拓扑图:

    tuopu.png

    二、涉及软件

    ETD: 。分布式KV存储系统,一般用于共享配置和服务注册与发现是ETOS存储格式类似于文件系统,以根“/”开始下面一级级目录,最后一个是重点,一个关键对应一个值。

    ETCD 集群:使用筏协议保证每个节点数据一致,由多个节点对外提供服务这里只用单台。

    confd:管理本地应用配置文件,使用etcd或consul存储的数据渲染模板,还支持redis,zookeeper等.confd有一个手表功能,通过HTTP API定期监测对应的etcd中目录变化,获取最新的价值,然后竟染模板

    Nginx: Nginx是一款轻量级的Web服务器/反向代理服务器以及电子邮件代理服务器,并在一个BSD-like协议下发行。来自俄罗斯的程序设计师l gor Sysoev所开发,供俄国大型的入口网站及搜索引擎联系Rambler使用。其特点是占有内存少,并发能力强,事实上nginx的的并发能力确实在同类型的网页服务器中表现较好。

    三、软件部署

    环境说明:建议使用 Cento7.X X64

    1)安装 etcd(这里安装的单机,集群环境根据自己的需求选取)

    1
    2
    3
    #yum install etcd -y
    #sed -i's / localhost / 0.0.0.0 / g'/etc/etcd/etcd.conf#配置监听地址
    #systemctl start etcd && systemctl enable etcd#启动服务设置开机动

    2)安装 nginx

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    #cd / usr / local / src
     #wget http://nginx.org/download/nginx-1.12.1.tar.gz
     #git clone https://github.com/yaoweibin/nginx_upstream_check_module.git  
     #tar -zxvf nginx-1.12.1.tar.gz 
     #cd nginx-1.12.1
     #patch -p1 </usr/local/src/nginx_upstream_check_module/check_1.12.1+.patch
     #。/ configure --prefix = / usr / local / nginx --add-module = / usr / local / src / nginx_upstream_check_module /
     make && make install
     #mkdir / usr / local / nginx / conf / vhost /
     Nginx的主配置文件修改为这个样子,增加包括目录配置
     #vi /usr/local/nginx/conf/nginx.conf
      
      
       #user nobody;
       worker_processes 1;
       #error_log logs / error.log;
       #error_log logs / error.log通知;
       #error_log logs / error.log info;
       #pid logs / nginx.pid;
       事件{
         worker_connections 1024;
       }
       http {
         包括mime.types;
         default_type application / octet-stream;
         #log_format main'$ remote_addr  -  $ remote_user [$ time_local]“$ request”'
         '$ status $ body_bytes_sent“$ http_referer”'
         '“$ http_user_agent”“$ http_x_forwarded_for”';
         #access_log logs / access.log main;
         sendfile on;
         #tcp_nopush on;
         #keepalive_timeout 0;
         keepalive_timeout 65;
         #gzip on;
       包括vhost / * .conf;
       }

    3)安装 confd

    地址下载https://github.com/kelseyhightower/confd/releases

    下载完毕丢到系统里面

    1
    2
    3
    #cp confd / usr / bin / confd 
    #哪个confd
    / usr / bin/ confd

    4)创建配置文件目录

    #mkdir -p /etc/confd/{conf.d,templates}

     conf.d#资源模板,下面文件必须以toml后缀

     templates#配置文件模板,下面文件必须以tmpl后缀

    5)创建 confd 配置文件

    1
    2
    3
    4
    5
    6
    7
      #vi /etc/confd/conf.d/app01.conf.toml
       src =“app01.conf.tmpl”#默认在/ etc / confd / templates目录下
       dest =/ usr / local / nginx / conf / vhost / app01.conf”#要更新的配置文件
       = [
          / Shopping”,#监测的关键
       ]
       reload_cmd =/ usr / local / nginx / sbin / nginx -reload”#最后执行的命令

    6)创建 confd 模板

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
      #vi /etc/confd/templates/app01.conf.tmpl 
        
       upstream {{getv“/ Shopping / nginx / cluster1 / proxy_name”}} {
         {{range getvs“/ Shopping / nginx / cluster1 / upstream / *”}}
           server {{。}};
         {{结束}}
         check interval = 5000 rise = 1 fall = 5 timeout = 4000 type = http;
         check_http_send“HEAD / HTTP / 1.0  r  n  r  n”;
         check_http_expect_alive http_2xx http_3xx;
       }
          
       服务器{
          server_name {{range getvs“/ Shopping / nginx / cluster1 / server_name / *”}} {{。}} {{end}};
          位置 / {
            proxy_pass http:// {{getv“/ Shopping / nginx / cluster1 / proxy_name”}};
            proxy_redirect off;
            proxy_set_header Host $ host;
            proxy_set_header X-Real-IP $ remote_addr;
            proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
         }
           位置/状态{
               检查状态;
               access_log off;
              }
       }

    7)启动 confd 并设置开机启动

    开机启动脚本会随文档附带

    拷贝至 /etc/init.d/confd,只需要更改等改为连接地址即可

    1
    / etc / init.d / confd start && chkconfig --add confd && chkconfig confd on

    四、配置平台部署

    1)Github克隆平台代码安装平台依赖

    1
    2
    3
    4
    5
     #git clone https://github.com/1032231418/Conf_Web.git
     #cd Conf_Web / ospweb /
     #virtualenv env#建议创建一个沙盒环境跑该平台
     #source env / bin / activate#使用沙盒环境
     #pip install -r requirement.txt#安装相关软件

    2)创建数据库并将表刷入数据库

    1
    #vi opsweb / settings.py#这里数据库信息改为自己的数据库信息DATABASES = {'default':{'ENGINE':'django.db.backends.mysql','NAME':'confd','HOST' :'192.168.8.114','USER':'root','PASSWORD':'123456','PORT':3306,}} ETCD_Server =“192.168.0.221”#这里改为自己etcd的ip地址ETCD_Port = 2379 #python manage.py migrate#提交迁移文件至数据库,将表刷入数据库

    3)创建超级管理员账号

    1
    #python manage.py createsuperuser

    4)运行平台

    1
    #python manage.py runserver 0:8000

    访问地址就是http:// ip:8000账号密码就是上一步创建的超级管理员账号密码5)登录平台为nginx创建键/值

    例子:购物平台为例

    项目创建:

    1.创建商城项目/购物

    2.创建商城项目里面的/ Shopping / nginx nginx服务

    3.创建nginx集群目录/ Shopping / nginx / cluster1

    4.给我们的商城nginx的集群1项目创建配置文件

    5.域名和节点名称可能是多个,这里我们需要创建目录/ Shopping / nginx / cluster1 / server_name和/ Shopping / nginx / cluster1 / upstream

    0 (1).png

    etcd里面存储的值

    0 (2).jpg

    配置创建:

    1.反向代理/ Shopping / nginx / cluster1 / proxy_name

    2.绑定一个域名/ Shopping / nginx / cluster1 / server_name / 1

    3.创建一个集群节点/ Shopping / nginx / cluster1 / upstream / web1

    0 (3).jpg

    etcd 里面存储的值

    0 (4).jpg

    生成的配置文件

    0 (5).png

    通过主机文件我们可以查看节点状态(虽然这个节点不是最高状态但是由此可见,我们可以动态添加节点)

    0 (6).png

  • 相关阅读:
    R_Studio(关联)使用apriori函数简单查看数据存在多少条关联规则,并按支持度降序排序输出
    Unity3D_(游戏)2D坦克大战 像素版
    R_Studio(cart算法决策树)对book3.csv数据用测试集进行测试并评估模型
    R_Studio(决策树算法)鸢尾花卉数据集Iris是一类多重变量分析的数据集【精】
    R_针对churn数据用id3、cart、C4.5和C5.0创建决策树模型进行判断哪种模型更合适
    R_Studio(教师经济信息)逻辑回归分析的方法和技巧
    JavaWeb_Get和Post方法传输数据区别
    JavaWeb_响应和请求数据包
    JavaWeb_使用dom4j解析、生成XML文件
    JavaWeb_ XML文件
  • 原文地址:https://www.cnblogs.com/aiaitie/p/9294053.html
Copyright © 2020-2023  润新知