Redis过滤器如何与Envoy代理一起使用

1.克隆源码到机器

[root@cx--0002 ~]# git clone https://github.com/envoyproxy/envoy
Cloning into 'envoy'...
remote: Enumerating objects: 70, done.
remote: Counting objects: 100% (70/70), done.
remote: Compressing objects: 100% (58/58), done.
remote: Total 93652 (delta 13), reused 28 (delta 11), pack-reused 93582
Receiving objects: 100% (93652/93652), 35.16 MiB | 601.00 KiB/s, done.
Resolving deltas: 100% (70765/70765), done.
[root@cx--0002 ~]# ls
anaconda-ks.cfg  envoy  wordpress-mysql
[root@cx--0002 ~]# ls envoy/
api    ci                  configs          DEPRECATED.md  examples             include            NOTICE            PULL_REQUEST_TEMPLATE.md  REPO_LAYOUT.md  SECURITY_RELEASE_PROCESS.md  support  VERSION
bazel  CODE_OF_CONDUCT.md  CONTRIBUTING.md  DEVELOPER.md   EXTENSION_POLICY.md  ISSUE_TEMPLATE.md  OWNERS.md         README.md                 restarter       source                       test     windows
BUILD  CODEOWNERS          DCO              docs           GOVERNANCE.md        LICENSE            PULL_REQUESTS.md  repokitteh.star           security        STYLE.md                     tools    WORKSPACE
[root@cx--0002 ~]# cd envoy/examples/redis/
[root@cx--0002 redis]# ls 
docker-compose.yaml  Dockerfile-proxy  Dockerfile-redis  envoy.yaml  README.md

2.安装docker-compose

[root@cx--0002 redis]# curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    650      0 --:--:-- --:--:-- --:--:--   650
100 15.4M  100 15.4M    0     0  1353k      0  0:00:11  0:00:11 --:--:-- 2355k
[root@cx--0002 redis]# chmod +x /usr/local/bin/docker-compose
[root@cx--0002 redis]# docker-compose ps
Name   Command   State   Ports
------------------------------

3.创建redis沙箱

[root@cx--0002 redis]# docker-compose up -d
Creating network "redis_envoymesh" with the default driver
Building proxy
Step 1/2 : FROM envoyproxy/envoy-dev:latest
Trying to pull repository docker.io/envoyproxy/envoy-dev ... 
latest: Pulling from docker.io/envoyproxy/envoy-dev
35b42117c431: Already exists
ad9c569a8d98: Already exists
293b44f45162: Already exists
0c175077525d: Already exists
720b18d7211c: Pull complete
7e82cb71a605: Pull complete
8dd5fbb71c59: Pull complete
cd8d5f15933d: Pull complete
e7e9de9472a4: Pull complete
Digest: sha256:5d558d699eeb219f672e771d9ab7d455f0c23ecf8cbe81e2fed2bcc4d16fbe21
Status: Downloaded newer image for docker.io/envoyproxy/envoy-dev:latest
 ---> 66dad96a6e23
Step 2/2 : CMD /usr/local/bin/envoy -c /etc/envoy.yaml -l debug --service-cluster proxy
 ---> Running in 91d0aa4af229
 ---> 939322cd01f3
Removing intermediate container 91d0aa4af229
Successfully built 939322cd01f3
WARNING: Image for service proxy was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Building redis
Step 1/1 : FROM redis
Trying to pull repository docker.io/library/redis ... 
latest: Pulling from docker.io/library/redis
fc7181108d40: Already exists
3e0ac67cad82: Pull complete
6ee495cb7235: Pull complete
9f7206d08b9d: Pull complete
a8354ef8cccb: Pull complete
53afb10d81c2: Pull complete
Digest: sha256:ca2d9251c2818df48c6598e01a5bdeab46040dc7ab236abe075d7c7343465177
Status: Downloaded newer image for docker.io/redis:latest
 ---> 3c41ce05add9
Successfully built 3c41ce05add9
WARNING: Image for service redis was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating redis_proxy_1 ... done
Creating redis_redis_1 ... done
[root@cx--0002 redis]# docker-compose build
Building proxy
Step 1/2 : FROM envoyproxy/envoy-dev:latest
 ---> 66dad96a6e23
Step 2/2 : CMD /usr/local/bin/envoy -c /etc/envoy.yaml -l debug --service-cluster proxy
 ---> Using cache
 ---> 939322cd01f3
Successfully built 939322cd01f3
Building redis
Step 1/1 : FROM redis
 ---> 3c41ce05add9
Successfully built 3c41ce05add9


[root@cx
--0002 redis]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ef3799105b89 redis_redis "docker-entrypoint..." About a minute ago Up About a minute 0.0.0.0:6379->6379/tcp redis_redis_1 d851feb8d172 redis_proxy "/docker-entrypoin..." About a minute ago Up About a minute 0.0.0.0:1999->1999/tcp, 0.0.0.0:8001->8001/tcp, 10000/tcp redis_proxy_1

4.使用redis-cli发出一些Redis命令,并验证它们是否通过envoy路由

//注意端口号
> redis-cli -h localhost -p 1999 set foo foo
OK
> redis-cli -h localhost -p 1999 set bar bar
OK
> redis-cli -h localhost -p 1999 get foo
"foo"
> redis-cli -h localhost -p 1999 get bar
"bar"

转到http://localhost:8001/stats?usedonly&filter=redis.egress_redis.command并验证以下统计信息

redis.egress_redis.command.get.total: 2
redis.egress_redis.command.set.total: 2

 其他链接可查看帮助

[root@cx--0002 ~]# curl http://localhost:8001/help
admin commands are:
  /: Admin home page
  /certs: print certs on machine
  /clusters: upstream cluster status
  /config_dump: dump current Envoy configs (experimental)
  /contention: dump current Envoy mutex contention stats (if enabled)
  /cpuprofiler: enable/disable the CPU profiler
  /healthcheck/fail: cause the server to fail health checks
  /healthcheck/ok: cause the server to pass health checks
  /heapprofiler: enable/disable the heap profiler
  /help: print out list of admin commands
  /hot_restart_version: print the hot restart compatibility version
  /listeners: print listener info
  /logging: query/change logging levels
  /memory: print current allocation/heap usage
  /quitquitquit: exit the server
  /ready: print server state, return 200 if LIVE, otherwise return 503
  /reset_counters: reset all counters to zero
  /runtime: print runtime values
  /runtime_modify: modify runtime values
  /server_info: print server version/status information
  /stats: print server stats
  /stats/prometheus: print server stats in prometheus format
原文地址:https://www.cnblogs.com/linyouyi/p/11120901.html