
机器学习算法有哪些
我打算使用apisix作为原始项目,所以首先应该学会对apisix的编译安装并使之能够成功运行。
Apache APISIX 是一个云原生 API 网关Apache APISIX 仪表板旨在让用户通过前端界面尽可能轻松地操作Apache APISIX
参考API服务网关实现之APISIX安装和部署上面这个博客在安装可视化界面的时候存在问题,看看官方的。官方dashboard部署文档我来理一下大致的过程,安装过程首先需要apisix本身,和一个展示程序。所以可以考虑从两步走,先安装apisix,然后再安装其配套的界面。以下是我这边的实践过程。
环境:已安装openResty centos 7
wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
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 查看进程或者监听端口9080
ps aux|grep apisix
netstat -lntp|grep 9080
为了避免出现失败,但是生产环境不建议
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
在这之前,需要安装go语言的环境,nodejs环境和yarn的环境。
注意:
go env -w GOPROXY=https://goproxy.cn,direct
根据apisix-dashboard官方安装教程中提到的步骤如下:
git clone -b release/2.10.1 https://github.com/apache/apisix-dashboard.git && cd apisix-dashboard
这个步骤如果你的服务器连接到github超时,可以考虑在本机下载了,然后传到你的服务器上去。然后执行
make build
等待执行完毕,这个过程中会连接到github,如果连接超时,就多试几次。
成功之后,来到目录下的output目录,生成的结果就在里面
首先,conf里面是web的配置,结构如下:
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
需要关注的几个点,首先allow_list,关乎着哪些能够访问该展示层,0.0.0.0/0 可以表示所有可访问,账号密码在users部分配置。
使用命令
./manager-api
启动项目即可。访问:http://ip:9000/user/login?redirect=/ 即可,默认密码为 admin/admin 或者 user/user
官方使用简介
Grafana是数据可视化,仪表盘和图形编辑器,是 Graphite 和 InfluxDB 仪表盘和图形编辑器,同时也是开源的、功能齐全的度量仪表盘和图形编辑器,支持 Graphite,InfluxDB 和 OpenTSDB。
grafana 是一个开源的时序性统计和监控平台,支持例如 elasticsearch、graphite、influxdb 等众多的数据源,并以功能强大的界面编辑器著称。
或许可以考虑放到网络安全智能防控平台与elasticsearch一起玩。官网相当于已经实现了各种定制的仪表盘,然后只需要导入即可。官网的配置似乎都是需要配置一堆节点的,但是我这里只有一个简单的填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
# 保存后执行
yum -y install grafana
systemctl enable grafana-server
systemctl start grafana-server
来看看grafana-server的内容
[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
导入数据和控制台:分分钟搞定Grafana(图文详解)目前我这边没有数据可视化展示需求,也不是重点,就不考虑了。
路由(Route)是请求的入口点,它定义了客户端请求与服务之间的匹配规则。路由可以与服务(Service)、上游(Upstream)关联,一个服务可对应一组路由,一个路由可以对应一个上游对象(一组后端服务节点),因此,每个匹配到路由的请求将被网关代理到路由绑定的上游服务中。
上游列表包含了已创建的上游服务(即后端服务),可以对上游服务的多个目标节点进行负载均衡和健康检查。
服务由路由中公共的插件配置、上游目标信息组合而成。服务与路由、上游关联,一个服务可对应一组上游节点、可被多条路由绑定
消费者是路由的消费方,形式包括开发者、最终用户、API 调用等。创建消费者时,需绑定至少一个认证类插件 包含身份验证、安全防护、流量控制、无服务器架构、可观测性和其他几个类型。
插件类型有如下几种:官方插件文档
然后consumer将其密钥添加到请求标头以验证其请求
对插件的合理使用已经可以解决绝大部分的问题,比如proxy-mirror和Proxy-cache拿来镜像客户端的请求,然后我们就可以拿这些请求来额外做分析,比如做反爬虫和数据安全相关的内容。
证书被网关用于处理加密请求,它将与 SNI 关联,并与路由中主机名绑定。
修改定制化
前端项目的代码结构如下
其中web目录里面就是项目的前端页面
整个项目是由vue编写,可以使用yarn构建,所以项目可以以调试模式使用yarn build命令进行运行。官方调试文档值得注意的是,我这边在最后一步,使用yarn start似乎不能成功登陆,只能使用yarn start:e2e指令。
调试的目的就是不用走编译,边改边看效果,因为yarn会检测文件变化然后进行实时编译。调试的结构为
# 进入到web目录,项目运行在8000端口
yarn start:e2e
# 退出到dashboard项目目录
# 开启接口服务,运行在9000端口
make api-run
然后访问8000端口的应用,登录即可。让我们来看看实时编译:
然后我去修改defaultSettings.ts:
可以看见就触发了实时编译。这个时候就可以进行动态调试。
页面也发生了变化(123是我刚刚才加的)
这只是一个简单的例子,更多的修改将在接下来的文章里面跟大家分享。
github上面的APISIX有很多不同的版本,所以掌握一手github切换分支的操作就尤为重要。就我观察而言,这个版本的代码应该是最新的比稳定版本多了一些插件。我之前的源码是在gitee上面下载的,结果版本太老了,代码跟github不是一样的,所以还是回归到了github。慢点就慢点吧。从github下载的apisix的代码如下:
其中核心代码在apisix目录中,
里面都是lua脚本,其整体架构和之前分析的Orange差不多,都是由插件系统构成扩展功能,只不过基础的实现不一样。我们在开源项目上做扩展主要就是扩展插件。要扩展插件就得弄明白其插件调用流程以及实现方法。这部分内容将在接下来的文章里面描绘。
本文章转载微信公众号@海燕技术栈