CoreDNS
# 关闭防火墙
systemctl stop firewalld
systemctl daemon-reload
systemctl restart docker
# 删除容器
docker rm etcd1 etcd2 etcd3 -f
#构建容器
docker run \
-d \
--name etcd1 \
-p 12379:2379 -p 12380:2380 \
-v /etc/etcd1:/etcd-data \
quay.io/coreos/etcd:v3.3.12 \
/usr/local/bin/etcd \
--data-dir=/etcd-data \
--name node1 \
--advertise-client-urls http://192.168.2.139:12379 --listen-client-urls http://0.0.0.0:2379 \
--initial-advertise-peer-urls http://192.168.2.139:12380 --listen-peer-urls http://0.0.0.0:2380 \
--initial-cluster-state new \
--initial-cluster-token etcd-cluster \
--initial-cluster node1=http://192.168.2.139:12380,node2=http://192.168.2.139:22380,node3=http://192.168.2.139:32380
docker run \
-d \
--name etcd2 \
-p 22379:2379 -p 22380:2380 \
-v /etc/etcd2:/etcd-data \
quay.io/coreos/etcd:v3.3.12 \
/usr/local/bin/etcd \
--data-dir=/etcd-data \
--name node2 \
--advertise-client-urls http://192.168.2.139:22379 --listen-client-urls http://0.0.0.0:2379 \
--initial-advertise-peer-urls http://192.168.2.139:22380 --listen-peer-urls http://0.0.0.0:2380 \
--initial-cluster-state new \
--initial-cluster-token etcd-cluster \
--initial-cluster node1=http://192.168.2.139:12380,node2=http://192.168.2.139:22380,node3=http://192.168.2.139:32380
docker run \
-d \
--name etcd3 \
-p 32379:2379 -p 32380:2380 \
-v /etc/etcd3:/etcd-data \
quay.io/coreos/etcd:v3.3.12 \
/usr/local/bin/etcd \
--data-dir=/etcd-data \
--name node3 \
--advertise-client-urls http://192.168.2.139:32379 --listen-client-urls http://0.0.0.0:2379 \
--initial-advertise-peer-urls http://192.168.2.139:32380 --listen-peer-urls http://0.0.0.0:2380 \
--initial-cluster-state new \
--initial-cluster-token etcd-cluster \
--initial-cluster node1=http://192.168.2.139:12380,node2=http://192.168.2.139:22380,node3=http://192.168.2.139:32380
# 测试集群
docker exec etcd1 etcdctl member list
docker exec -it etcd1 sh
export ETCDCTL_API=3
etcdctl put key 123
docker exec -it etcd2 sh
export ETCDCTL_API=3
etcdctl get key
# 创建corefile
cat << EOF > /etc/corefile/Corefile
.:53{
log
etcd {
path /skydns
endpoint http://192.168.2.139:12379 http://192.168.2.139:22379 http://192.168.2.139:32379
}
prometheus 0.0.0.0:9153
}
EOF
# 创建coredns容器
docker run -d \
--name coredns \
-p 53:53/udp \
-p 9153:9153 \
-v /etc/corefile/:/etc/coredns/ \
coredns/coredns:1.6.1 \
-conf /etc/coredns/Corefile
# 测试
etcdctl put /skydns/com/app/test '{"host":"192.168.180.7","ttl":60}'
curl -L 192.168.2.139:12379/v3beta/kv/range -X POST -d '{"key":"L3NreWRucy94L2FwcA=="}'
nslookup test.app.com 192.168.2.139
cat << EOF > /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
- job_name: 'coredns'
scrape_interval: 5s
static_configs:
- targets: ['192.168.2.139:9153']
EOF
# 创建容器
docker rm -f prometheus
docker run --name=prometheus -d \
-p 9090:9090 \
-v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
-v /etc/prometheus/rules.yml:/etc/prometheus/rules.yml \
prom/prometheus:v2.11.0 \
--config.file=/etc/prometheus/prometheus.yml \
--web.enable-lifecycle
# 测试
curl 192.168.2.139:9153/metrics
http://192.168.2.139:9090
docker run -d -p 3000:3000 --name grafana grafana/grafana:6.3.2
docker run -d \
--name etcdkeeper \
-p 8080:8080 \
jim3ma/etcdkeeper3:latest