rpm -ivh epel-release-latest-7.noarch.rpm

yum install yum-utils

yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo

yum install -y etcd openresty curl git gcc luarocks lua-devel
systemctl start etcd
yum install -y https://github.com/apache/incubator-apisix/releases/download/1.1/apisix-1.1-0.el7.noarch.rpm

啟動(dòng)apisix:apisix start 查看進(jìn)程或者監(jiān)聽(tīng)端口9080

ps aux|grep apisix
netstat -lntp|grep 9080

關(guān)閉各種防火墻

為了避免出現(xiàn)失敗,但是生產(chǎn)環(huán)境不建議

systemctl stop firewalld.service

systemctl disable firewalld.service

setenforce 0

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

安裝apisix cli

在這之前,需要安裝go語(yǔ)言的環(huán)境,nodejs環(huán)境和yarn的環(huán)境。

注意:

go env -w GOPROXY=https://goproxy.cn,direct

根據(jù)apisix-dashboard官方安裝教程中提到的步驟如下:

git clone -b release/2.10.1 https://github.com/apache/apisix-dashboard.git && cd apisix-dashboard

這個(gè)步驟如果你的服務(wù)器連接到github超時(shí),可以考慮在本機(jī)下載了,然后傳到你的服務(wù)器上去。然后執(zhí)行

make build

等待執(zhí)行完畢,這個(gè)過(guò)程中會(huì)連接到github,如果連接超時(shí),就多試幾次。

成功之后,來(lái)到目錄下的output目錄,生成的結(jié)果就在里面

首先,conf里面是web的配置,結(jié)構(gòu)如下:

conf:
listen:
# host: 127.0.0.1 # the address on which the Manager API should listen. # The default value is 0.0.0.0, if want to specify, please enable it. # This value accepts IPv4, IPv6, and hostname. port: 9000 # The port on which the Manager API should listen. # ssl: # host: 127.0.0.1 # the address on which the Manager API should listen for HTTPS. # The default value is 0.0.0.0, if want to specify, please enable it. # port: 9001 # The port on which the Manager API should listen for HTTPS. # cert: "/tmp/cert/example.crt" # Path of your SSL cert. # key: "/tmp/cert/example.key" # Path of your SSL key. allow_list: # If we don't set any IP list, then any IP access is allowed by default. - 127.0.0.1 # The rules are checked in sequence until the first match is found. - ::1 # In this example, access is allowed only for IPv4 network 127.0.0.1, and for IPv6 network ::1. # It also support CIDR like 192.168.1.0/24 and 2001:0db8::/32 etcd: endpoints: # supports defining multiple etcd host addresses for an etcd cluster - 127.0.0.1:2379 # yamllint disable rule:comments-indentation # etcd basic auth info # username: "root" # ignore etcd username if not enable etcd auth # password: "123456" # ignore etcd password if not enable etcd auth mtls: key_file: "" # Path of your self-signed client side key cert_file: "" # Path of your self-signed client side cert ca_file: "" # Path of your self-signed ca cert, the CA is used to sign callers' certificates # prefix: /apisix # apisix config's prefix in etcd, /apisix by default log: error_log: level: warn # supports levels, lower to higher: debug, info, warn, error, panic, fatal file_path: logs/error.log # supports relative path, absolute path, standard output # such as: logs/error.log, /tmp/logs/error.log, /dev/stdout, /dev/stderr # such as absolute path on Windows: winfile:///C:\error.log access_log: file_path: logs/access.log # supports relative path, absolute path, standard output # such as: logs/access.log, /tmp/logs/access.log, /dev/stdout, /dev/stderr # such as absolute path on Windows: winfile:///C:\access.log # log example: 2020-12-09T16:38:09.039+0800 INFO filter/logging.go:46 /apisix/admin/routes/r1 {"status": 401, "host": "127.0.0.1:9000", "query": "asdfsafd=adf&a=a", "requestId": "3d50ecb8-758c-46d1-af5b-cd9d1c820156", "latency": 0, "remoteIP": "127.0.0.1", "method": "PUT", "errs": []} max_cpu: 0 # supports tweaking with the number of OS threads are going to be used for parallelism. Default value: 0 [will use max number of available cpu cores considering hyperthreading (if any)]. If the value is negative, is will not touch the existing parallelism profile. authentication: secret: secret # secret for jwt token generation. # NOTE: Highly recommended to modify this value to protect manager api. # if it's default value, when manager api start, it will generate a random string to replace it. expire_time: 3600 # jwt token expire time, in second users: # yamllint enable rule:comments-indentation - username: admin # username and password for login manager api password: admin - username: user password: user

需要關(guān)注的幾個(gè)點(diǎn),首先allow_list,關(guān)乎著哪些能夠訪問(wèn)該展示層,0.0.0.0/0 可以表示所有可訪問(wèn),賬號(hào)密碼在users部分配置。

使用命令

./manager-api

啟動(dòng)項(xiàng)目即可。訪問(wèn):http://ip:9000/user/login?redirect=/ 即可,默認(rèn)密碼為 admin/admin 或者 user/user

功能介紹

官方使用簡(jiǎn)介

儀表盤-導(dǎo)入Grafana

Grafana是數(shù)據(jù)可視化,儀表盤和圖形編輯器,是 Graphite 和 InfluxDB 儀表盤和圖形編輯器,同時(shí)也是開(kāi)源的、功能齊全的度量?jī)x表盤和圖形編輯器,支持 Graphite,InfluxDB 和 OpenTSDB。

grafana 是一個(gè)開(kāi)源的時(shí)序性統(tǒng)計(jì)和監(jiān)控平臺(tái),支持例如 elasticsearch、graphite、influxdb 等眾多的數(shù)據(jù)源,并以功能強(qiáng)大的界面編輯器著稱。

或許可以考慮放到網(wǎng)絡(luò)安全智能防控平臺(tái)與elasticsearch一起玩。官網(wǎng)相當(dāng)于已經(jīng)實(shí)現(xiàn)了各種定制的儀表盤,然后只需要導(dǎo)入即可。官網(wǎng)的配置似乎都是需要配置一堆節(jié)點(diǎn)的,但是我這里只有一個(gè)簡(jiǎn)單的填http鏈接的操作。

目前還不知道怎么用,似乎是需要我自己做獨(dú)立安裝。

vim /etc/yum.repos.d/grafana.repo
# 在里面放入
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm-beta
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
# 保存后執(zhí)行
yum -y install grafana
systemctl enable grafana-server
systemctl start grafana-server

來(lái)看看grafana-server的內(nèi)容

[Unit]
Description=Grafana instance
Documentation=http://docs.grafana.org
Wants=network-online.target
After=network-online.target
After=postgresql.service mariadb.service mysqld.service

[Service]
EnvironmentFile=/etc/sysconfig/grafana-server
User=grafana
Group=grafana
Type=notify
Restart=on-failure
WorkingDirectory=/usr/share/grafana
RuntimeDirectory=grafana
RuntimeDirectoryMode=0750
ExecStart=/usr/sbin/grafana-server \
--config=${CONF_FILE} \
--pidfile=${PID_FILE_DIR}/grafana-server.pid \
--packaging=rpm \
cfg:default.paths.logs=${LOG_DIR} \
cfg:default.paths.data=${DATA_DIR} \
cfg:default.paths.plugins=${PLUGINS_DIR} \
cfg:default.paths.provisioning=${PROVISIONING_CFG_DIR}

LimitNOFILE=10000
TimeoutStopSec=20
CapabilityBoundingSet=
DeviceAllow=
LockPersonality=true
MemoryDenyWriteExecute=false
NoNewPrivileges=true
PrivateDevices=true
PrivateTmp=true
ProtectClock=true
ProtectControlGroups=true
ProtectHome=true
ProtectHostname=true
ProtectKernelLogs=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectProc=invisible
ProtectSystem=full
RemoveIPC=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
RestrictNamespaces=true
RestrictRealtime=true
RestrictSUIDSGID=true
SystemCallArchitectures=native
UMask=0027

[Install]
WantedBy=multi-user.target

導(dǎo)入數(shù)據(jù)和控制臺(tái):分分鐘搞定Grafana(圖文詳解)目前我這邊沒(méi)有數(shù)據(jù)可視化展示需求,也不是重點(diǎn),就不考慮了。

路由

路由(Route)是請(qǐng)求的入口點(diǎn),它定義了客戶端請(qǐng)求與服務(wù)之間的匹配規(guī)則。路由可以與服務(wù)(Service)、上游(Upstream)關(guān)聯(lián),一個(gè)服務(wù)可對(duì)應(yīng)一組路由,一個(gè)路由可以對(duì)應(yīng)一個(gè)上游對(duì)象(一組后端服務(wù)節(jié)點(diǎn)),因此,每個(gè)匹配到路由的請(qǐng)求將被網(wǎng)關(guān)代理到路由綁定的上游服務(wù)中。

上游

上游列表包含了已創(chuàng)建的上游服務(wù)(即后端服務(wù)),可以對(duì)上游服務(wù)的多個(gè)目標(biāo)節(jié)點(diǎn)進(jìn)行負(fù)載均衡和健康檢查。

服務(wù)

服務(wù)由路由中公共的插件配置、上游目標(biāo)信息組合而成。服務(wù)與路由、上游關(guān)聯(lián),一個(gè)服務(wù)可對(duì)應(yīng)一組上游節(jié)點(diǎn)、可被多條路由綁定

消費(fèi)者

消費(fèi)者是路由的消費(fèi)方,形式包括開(kāi)發(fā)者、最終用戶、API 調(diào)用等。創(chuàng)建消費(fèi)者時(shí),需綁定至少一個(gè)認(rèn)證類插件 包含身份驗(yàn)證、安全防護(hù)、流量控制、無(wú)服務(wù)器架構(gòu)、可觀測(cè)性和其他幾個(gè)類型。

插件

插件類型有如下幾種:官方插件文檔

然后consumer將其密鑰添加到請(qǐng)求標(biāo)頭以驗(yàn)證其請(qǐng)求

對(duì)插件的合理使用已經(jīng)可以解決絕大部分的問(wèn)題,比如proxy-mirror和Proxy-cache拿來(lái)鏡像客戶端的請(qǐng)求,然后我們就可以拿這些請(qǐng)求來(lái)額外做分析,比如做反爬蟲(chóng)和數(shù)據(jù)安全相關(guān)的內(nèi)容。

證書(shū)

證書(shū)被網(wǎng)關(guān)用于處理加密請(qǐng)求,它將與 SNI 關(guān)聯(lián),并與路由中主機(jī)名綁定。

修改定制化

前端界面的修改

前端項(xiàng)目的代碼結(jié)構(gòu)如下

其中web目錄里面就是項(xiàng)目的前端頁(yè)面

整個(gè)項(xiàng)目是由vue編寫,可以使用yarn構(gòu)建,所以項(xiàng)目可以以調(diào)試模式使用yarn build命令進(jìn)行運(yùn)行。官方調(diào)試文檔值得注意的是,我這邊在最后一步,使用yarn start似乎不能成功登陸,只能使用yarn start:e2e指令。

調(diào)試的目的就是不用走編譯,邊改邊看效果,因?yàn)閥arn會(huì)檢測(cè)文件變化然后進(jìn)行實(shí)時(shí)編譯。調(diào)試的結(jié)構(gòu)為

# 進(jìn)入到web目錄,項(xiàng)目運(yùn)行在8000端口
yarn start:e2e
# 退出到dashboard項(xiàng)目目錄
# 開(kāi)啟接口服務(wù),運(yùn)行在9000端口
make api-run

然后訪問(wèn)8000端口的應(yīng)用,登錄即可。讓我們來(lái)看看實(shí)時(shí)編譯:

然后我去修改defaultSettings.ts:

可以看見(jiàn)就觸發(fā)了實(shí)時(shí)編譯。這個(gè)時(shí)候就可以進(jìn)行動(dòng)態(tài)調(diào)試。

頁(yè)面也發(fā)生了變化(123是我剛剛才加的)

這只是一個(gè)簡(jiǎn)單的例子,更多的修改將在接下來(lái)的文章里面跟大家分享。

apisix能力層的修改

github上面的APISIX有很多不同的版本,所以掌握一手github切換分支的操作就尤為重要。就我觀察而言,這個(gè)版本的代碼應(yīng)該是最新的比穩(wěn)定版本多了一些插件。我之前的源碼是在gitee上面下載的,結(jié)果版本太老了,代碼跟github不是一樣的,所以還是回歸到了github。慢點(diǎn)就慢點(diǎn)吧。從github下載的apisix的代碼如下:

其中核心代碼在apisix目錄中,

里面都是lua腳本,其整體架構(gòu)和之前分析的Orange差不多,都是由插件系統(tǒng)構(gòu)成擴(kuò)展功能,只不過(guò)基礎(chǔ)的實(shí)現(xiàn)不一樣。我們?cè)陂_(kāi)源項(xiàng)目上做擴(kuò)展主要就是擴(kuò)展插件。要擴(kuò)展插件就得弄明白其插件調(diào)用流程以及實(shí)現(xiàn)方法。這部分內(nèi)容將在接下來(lái)的文章里面描繪。

本文章轉(zhuǎn)載微信公眾號(hào)@海燕技術(shù)棧

上一篇:

.NET Core高吞吐HttpAPI服務(wù)組件FastHttpApi

下一篇:

AWS開(kāi)源Multi-Agent-Orchestrator:多智能體編排框架,管理AI智能體,處理復(fù)雜對(duì)話
#你可能也喜歡這些API文章!

我們有何不同?

API服務(wù)商零注冊(cè)

多API并行試用

數(shù)據(jù)驅(qū)動(dòng)選型,提升決策效率

查看全部API→
??

熱門場(chǎng)景實(shí)測(cè),選對(duì)API

#AI文本生成大模型API

對(duì)比大模型API的內(nèi)容創(chuàng)意新穎性、情感共鳴力、商業(yè)轉(zhuǎn)化潛力

25個(gè)渠道
一鍵對(duì)比試用API 限時(shí)免費(fèi)

#AI深度推理大模型API

對(duì)比大模型API的邏輯推理準(zhǔn)確性、分析深度、可視化建議合理性

10個(gè)渠道
一鍵對(duì)比試用API 限時(shí)免費(fèi)