Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confd教程 #3

Open
iliuyt opened this issue Nov 30, 2017 · 0 comments
Open

Confd教程 #3

iliuyt opened this issue Nov 30, 2017 · 0 comments

Comments

@iliuyt
Copy link
Owner

iliuyt commented Nov 30, 2017

GitHub项目地址

github项目地址

下载

wget https://github.com/kelseyhightower/confd/releases/download/v0.14.0/confd-0.14.0-linux-amd64

创建目录

mkdir -p /opt/confd/bin
mv confd-0.14.0-linux-amd64 /opt/confd/bin/confd
chmod +x /opt/confd/bin/confd
export PATH="$PATH:/opt/confd/bin"

配置目录

mkdir -p /etc/confd/conf.d
mkdir -p /etc/confd/templates

添加模板配置

[template]
src = "config.json.tmpl"
dest = "/code/config/config.json"
keys = [
    "/mysql/host",
    "/mysql/port",
]

添加模板

{
    mysql:{
        host:{{getv "/mysql/host"}},
        port:{{getv "/mysql/port"}},
    }
}

通过etcd启动

confd -onetime -backend etcd -node http://127.0.0.1:2379

脚本

#!/bin/bash

wget https://github.com/kelseyhightower/confd/releases/download/v0.14.0/confd-0.14.0-linux-amd64
mv confd-0.14.0-linux-amd64 /usr/bin/confd
chmod +x /usr/bin/confd
mkdir -p /etc/confd/conf.d
mkdir -p /etc/confd/templates

cat <<EOF | tee /etc/confd/conf.d/config.toml
[template]
src = "config.json.tmpl"
dest = "/tmp/config.json"
keys = [
    "/mysql/host",
    "/mysql/port",
]
reload_cmd = "echo 'reload' > /tmp/confd.log"
EOF

cat <<EOF | tee //etc/confd/templates/config.json.tmpl
{
    mysql:{
        host:{{getv "/mysql/host"}},
        port:{{getv "/mysql/port"}},
    }
}
EOF

cat <<EOF | tee /etc/systemd/system/confd.service

[Unit]
Description=Confd Server
After=network.target

[Service]
User=root
Type=notify
ExecStart=/usr/bin/etcd --watch -backend etcd -node http://127.0.0.1:2379
Restart=on-failure
RestartSec=10s
LimitNOFILE=40000

[Install]
WantedBy=multi-user.target
EOF

etcdctl set /mysql/host 192.168.0.1
etcdctl set /mysql/port 8888

confd -onetime -backend etcd -node http://127.0.0.1:2379
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant