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

啟動apisix:apisix start 查看進程或者監(jiān)聽端口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語言的環(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

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

make build

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

成功之后,來到目錄下的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)注的幾個點,首先allow_list,關(guān)乎著哪些能夠訪問該展示層,0.0.0.0/0 可以表示所有可訪問,賬號密碼在users部分配置。

使用命令

./manager-api

啟動項目即可。訪問:http://ip:9000/user/login?redirect=/ 即可,默認密碼為 admin/admin 或者 user/user

功能介紹

官方使用簡介

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

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

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

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

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

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

來看看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ù)和控制臺:分分鐘搞定Grafana(圖文詳解)目前我這邊沒有數(shù)據(jù)可視化展示需求,也不是重點,就不考慮了。

路由

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

上游

上游列表包含了已創(chuàng)建的上游服務(wù)(即后端服務(wù)),可以對上游服務(wù)的多個目標節(jié)點進行負載均衡和健康檢查。

服務(wù)

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

消費者

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

插件

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

然后consumer將其密鑰添加到請求標頭以驗證其請求

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

證書

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

修改定制化

前端界面的修改

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

其中web目錄里面就是項目的前端頁面

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

調(diào)試的目的就是不用走編譯,邊改邊看效果,因為yarn會檢測文件變化然后進行實時編譯。調(diào)試的結(jié)構(gòu)為

# 進入到web目錄,項目運行在8000端口
yarn start:e2e
# 退出到dashboard項目目錄
# 開啟接口服務(wù),運行在9000端口
make api-run

然后訪問8000端口的應(yīng)用,登錄即可。讓我們來看看實時編譯:

然后我去修改defaultSettings.ts:

可以看見就觸發(fā)了實時編譯。這個時候就可以進行動態(tài)調(diào)試。

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

這只是一個簡單的例子,更多的修改將在接下來的文章里面跟大家分享。

apisix能力層的修改

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

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

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

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

上一篇:

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

下一篇:

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

我們有何不同?

API服務(wù)商零注冊

多API并行試用

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

查看全部API→
??

熱門場景實測,選對API

#AI文本生成大模型API

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

25個渠道
一鍵對比試用API 限時免費

#AI深度推理大模型API

對比大模型API的邏輯推理準確性、分析深度、可視化建議合理性

10個渠道
一鍵對比試用API 限時免費