聚合国内IT技术精华文章,分享IT技术精华,帮助IT从业人士成长

API网关apisix试用

2020-05-19 01:46 浏览: 3905974 次 我要评论(0 条) 字号:

API网关有什么作用?
路由:根据上下文或消息内容将请求发送到不同的目的地(可能需要借助Service Registry来查询具体的目的地在哪里)。
转换:负责转换或屏蔽某些数据。
监控:出入站流量监控。
安全:身份验证、授权和加密。
其他:限速,负载均衡等。

API网关有很多(见参考链接),这里试用下apisix,没什么特别的理由,基于春哥OpenResty的东东,肯定值得一看。
官方说明:https://github.com/apache/incubator-apisix/blob/master/README_CN.md

一,测试环境
$ cat /etc/issue
Ubuntu 18.04.3 LTS n l
$ uname -a
Linux lenky-virtual-machine 5.0.0-27-generic #28~18.04.1-Ubuntu SMP Thu Aug 22 03:00:32 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

二,安装依赖
参考这里:https://github.com/apache/incubator-apisix/blob/master/doc/install-dependencies-cn.md#ubuntu-1604–1804
具体操作如下,不过我的这台虚拟机之前安装过nginx,因此需要先执行sudo service nginx stop停掉nginx服务,然后再按如下操作即可。

# 添加 OpenResty 源
wget -qO – https://openresty.org/package/pubkey.gpg | sudo apt-key add –
sudo apt-get update
sudo apt-get -y install software-properties-common
sudo add-apt-repository -y “deb http://openresty.org/package/ubuntu $(lsb_release -sc) main”
sudo apt-get update
# 安装 OpenResty, etcd 和 编译工具
sudo apt-get install -y git etcd openresty curl luarocks
# 开启 etcd server
sudo service etcd start

三,通过源码安装apisix
# 下载apisix源码包
mkdir ~/apisix
cd ~/apisix/

wget http://www.apache.org/dist/incubator/apisix/1.2/apache-apisix-1.2-incubating-src.tar.gz
tar zxvf apache-apisix-1.2-incubating-src.tar.gz
# 安装运行时依赖的 Lua 库:
cd apache-apisix-1.2-incubating
make deps

四,运行
# init nginx config file and etcd
$ cd ~/apisix/apache-apisix-1.2-incubating/
$ make init

# start APISIX server
$ make run
$ ps aux | grep apisix

# stop APISIX server
$ make stop
$ ps aux | grep apisix

# more actions find by `help`
$ make help

正常启动后,可以通过ps aux | grep openresty 或 netstat -natp| grep nginx 看到对应的运行信息。

五,先看跑起来没有,简单测试
$ cd ~/apisix/apache-apisix-1.2-incubating/
$ vi dashboard/index.html
$ cat dashboard/index.html

<hr color="red" />

浏览器访问:http://192.168.214.140:9080/apisix/dashboard/
看到显示一条红色线条,基本OK。

六,安装Dashboard
1,因为本地nodejs版本为v8.10.0,所以首先升级nodejs
$ nodejs –version
v8.10.0
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –
$ sudo apt-get install -y nodejs
$ nodejs –version
v10.20.1

2,安装yarn
$ curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add –
$ echo “deb https://dl.yarnpkg.com/debian/ stable main” | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt-get update && sudo apt-get install yarn
$ yarn –version
1.22.4

3,下载构建Dashboard
因为我这里的apisix源码没有携带git信息,所以直接执行
git submodule update –init –recursive
会出现如下错误:
fatal: not a git repository (or any of the parent directories): .git

直接wget下载源码后进行构建
$ cd ~
$ wget https://github.com/apache/incubator-apisix-dashboard/archive/1.0.tar.gz
$ tar xf incubator-apisix-dashboard-1.0.tar.gz
$ cd incubator-apisix-dashboard-1.0/
$ yarn && yarn build:prod

将构建完毕后的内容拷贝到apisix的dshboard目录
$ cp -r dist/* ~/apisix/apache-apisix-1.2-incubating/dashboard/

4,登录Dashboard

http://192.168.214.140:9080/apisix/dashboard

默认账号密码都已填上,直接点登录即可。登录后看到如下错误提示:
Request failed with status code 401
据官方信息是由于Dashboard默认只允许127.0.0.1访问?在Linux本机访问http://localhost:9080/apisix/dashboard
仍然同样错误。

算了,Over~

PS:
最近接触了很多东西,所以也就顺便把一些接触到的内容简单Mark了一下,这些技术或开源目前我都研究得很肤浅,大多只是简单试用下,但我当前的目的并不在于要研究某个技术或某个开源多深入,而只是在拓展相关概念和知识,从更宏观或更上层的角度稍微掌握和理解这些技术,能够在大方向上做出判断和有所把握与指引,就达到了我的当前目的。

如果有网友不巧刚好看到我的文章,觉得不够深入,没关系,我文章末尾一般都带有不少参考链接,请移步,:)

参考:
1,【实践】5种微服务开源API网关对比,为什么我选择了TRY

https://www.jianshu.com/p/aed87837e9ae

2,API网关的开源解决方案那么多,为什么我们却还要选择自研?

https://mp.weixin.qq.com/s?__biz=MzI4MTY5NTk4Ng==&mid=2247489163&idx=1&sn=4b0cda4848606deedaf094c367955a2c&source=41#wechat_redirect

3,开源API网关大全20款+

https://www.iamle.com/archives/2591.html

4,开源API网关,你选对了么?

https://www.cnblogs.com/wwek/p/12173909.html

5,API 网关 Apache APISIX 和 Kong 的选型对比

https://zhuanlan.zhihu.com/p/103236688

6,如何选择适合你的微服务 API 网关:对比 Kong、APISIX、Tyk、Apigee 和其他网关

https://segmentfault.com/a/1190000020303778

其他:

https://www.bbva.com/en/api-gateways-kong-vs-tyk/

https://stackshare.io/stackups/kong-vs-traefik

https://blog.getambassador.io/envoy-vs-nginx-vs-haproxy-why-the-open-source-ambassador-api-gateway-chose-envoy-23826aed79ef

https://engineering.opsgenie.com/comparing-api-gateway-performances-nginx-vs-zuul-vs-spring-cloud-gateway-vs-linkerd-b2cc59c65369

https://appinventiv.com/blog/open-source-api-management-tools/

https://www.moesif.com/blog/technical/api-gateways/How-to-Choose-The-Right-API-Gateway-For-Your-Platform-Comparison-Of-Kong-Tyk-Apigee-And-Alternatives/

https://stackoverflow.com/questions/52851770/microservices-what-is-the-exact-difference-between-service-discovery-and-servi

https://www.express-gateway.io/service-mesh-service-discovery-and-api-gateways/

https://www.nginx.com/blog/service-discovery-in-a-microservices-architecture/

https://microservices.io/patterns/apigateway.html

https://konghq.com/blog/the-difference-between-api-gateways-and-service-mesh/

https://microservices.io/patterns/server-side-discovery.html



网友评论已有0条评论, 我也要评论

发表评论

*

* (保密)

Ctrl+Enter 快捷回复