• etcd+confd管理nginx


    1.安装

    wget https://github.com/etcd-io/etcd/releases/download/v3.3.12/etcd-v3.3.12-linux-amd64.tar.gz

    tar zxvf etcd-v3.3.12-linux-amd64.tar.gz

    cd etcd-v3.3.12-linux-amd64

    cp etcd etcdctl /usr/bin/

    2.配置

    vi /usr/lib/systemd/system/etcd.service

    [Unit]
    Description=Etcd Server
    After=network.target
    After=network-online.target
    Wants=network-online.target

    [Service]
    Type=notify
    WorkingDirectory=/var/lib/etcd/
    EnvironmentFile=-/etc/etcd/etcd.conf
    User=etcd
    # set GOMAXPROCS to number of processors
    ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name="${ETCD_NAME}" --data-dir="${ETCD_DATA_DIR}" --listen-client-urls="${ETCD_LISTEN_CLIENT_URLS}""
    Restart=on-failure
    LimitNOFILE=65536

    [Install]
    WantedBy=multi-user.target

    vi  /etc/etcd/etcd.conf

    #[Member]
    ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
    ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
    ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001"
    ETCD_NAME="node1"
    #[Clustering]
    ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.56.14:2380"
    ETCD_ADVERTISE_CLIENT_URLS="http://192.168.56.14:2379,http://192.168.56.14:4001"
    ETCD_INITIAL_CLUSTER="master=http://192.168.56.11:2380,node1=http://192.168.56.14:2380"
    ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
    ETCD_INITIAL_CLUSTER_STATE="new"

    3.启动服务并测试

    systemctl restart etcd

    systemctl status etcd

    etcdctl member list   #查看状态

    etcdctl  set  hello  aaa   #设置测试值

    到另外一台节点 etcdctl get hello  能看到值即可

    4.confd配置

    vi /etc/confd/conf.d/app01.conf.toml

    [template]
    # 默认在/etc/confd/templates目录下
    src = "app01.conf.tmpl"
    # 要更新的配置文件
    dest = "/usr/local/nginx/conf/vhost/app01.conf"
    keys = [
    "/nginx/www/"
    ]
    # 最后执行的命令
    reload_cmd ="echo test"

    vi /etc/confd/templates/app01.conf.tmpl

    upstream www.{{getv "/nginx/www/server_name"}} {
    {{range getvs "/nginx/www/upstream/*"}}
    server {{.}};
    {{end}}
    }

    server {
    server_name www.{{getv "/nginx/www/server_name"}};
    location / {
    proxy_pass http://www.{{getv "/nginx/www/server_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;
    }
    }

    5.在etcd上设置key

    etcdctl -C http://192.168.56.11:2379 set /nginx/www/server_name   123.com

    etcdctl -C http://192.168.56.11:2379 set /nginx/www/upstream/server01 “192.168.1.10:80”

    etcdctl -C http://192.168.56.11:2379 set /nginx/www/upstream/server02 “192.168.1.11:80”

    6.启动confd

    confd -watch -backend etcd -node http://192.168.56.11:2379

  • 相关阅读:
    关于用户体验的几张图片
    上下翻滚JS特效代码
    关注程序员健康之——缺失营养时的六种信号
    C#基础知识系列之——for循环
    关于程序中的需求的变化,责任的分配
    Silverlight学习之——Canvas对象
    还是觉得应该动手写点东西....
    怎样理解“道不同,不相为谋”这句话呢。。。
    UML图中最基本的是类图
    .NET中各种数据库连接大全
  • 原文地址:https://www.cnblogs.com/liumj0305/p/10731464.html
Copyright © 2020-2023  润新知