快速实验Kong的promethus插件

2020-05-20  本文已影响0人  印随2018

一、安装 Docker

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum -y install docker-ce
systemctl daemon-reload && systemctl restart docker

二、安装 Httpbin

port: 80

docker run -itd --net=host --name httpbin kennethreitz/httpbin

三、安装 Promethus

port: 9000

docker rm -f prometheus
docker run -itd --name prometheus prom/prometheus
docker cp prometheus:/etc/prometheus/prometheus.yml /tmp/prometheus.yml
docker rm -f prometheus
echo "  - job_name: 'kong'" >> /tmp/prometheus.yml
echo "    static_configs:"  >> /tmp/prometheus.yml
echo "    - targets: ['127.0.0.1:8001']" >> /tmp/prometheus.yml
docker run -itd --name prometheus --net=host \
   -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml \
   prom/prometheus

四、安装 Grafana

port: 3000

docker run -d --name=grafana --net=host grafana/grafana

dashboard id: 7424

五、安装 Kong

sudo yum install -y wget jq
wget https://bintray.com/kong/kong-rpm/rpm -O bintray-kong-kong-rpm.repo
export major_version=`grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release | cut -d "." -f1`
sed -i -e 's/baseurl.*/&\/centos\/'$major_version''/ bintray-kong-kong-rpm.repo
sudo mv bintray-kong-kong-rpm.repo /etc/yum.repos.d/
sudo yum install -y kong

六、配置 routes&services&plugins

cat > /tmp/apis.yaml <<EOF
_format_version: '1.1'

routes:
- name: route-httpbin
  protocols:
  - http
  paths:
  - /httpbin
  strip_path: true
  preserve_host: false
  regex_priority: 1
  service: service-httpbin

services:
- name: service-httpbin
  host: upstream-httpbin
  protocol: http
  port: 80
  connect_timeout: 60000
  read_timeout: 60000
  write_timeout: 60000
  retries: 5

upstreams:
- name: upstream-httpbin
  algorithm: round-robin

targets:
- upstream: upstream-httpbin
  target: 127.0.0.1:80
  weight: 100

plugins:
- name: correlation-id
  config:
    generator: tracker
    header_name: X-Kong-Request-ID
    echo_downstream: true
- name: prometheus
EOF

七、启动 Kong

# 配置
cp /etc/kong/kong.conf.default /etc/kong/kong.conf

# 使用db-lessmode
sed -i "/^#database/i\database = off" /etc/kong/kong.conf
sed -i "/^#declarative_config/i\declarative_config = /tmp/apis.yaml" /etc/kong/kong.conf

# 启动
kong start

# 验证
curl http://127.0.0.1:8001 2>/dev/null | jq .configuration.database

八、查看 Promethus/Grafana

browser http://127.0.0.1:9090
browser http://127.0.0.1:3000
上一篇下一篇

猜你喜欢

热点阅读