Fork me on GitHub

Ubuntu20.04 源码安装APISIX-2.15.x Dashboard

[TOC]

nodejs及go环境准备

安装nodejs

1
2
3
wget https://nodejs.org/download/release/v14.21.3/node-v14.21.3-linux-x64.tar.gz
tar xzvf node-v14.21.3-linux-x64.tar.gz -C /opt
mv /opt/node-v14.21.3-linux-x64/ /opt/node/

注意nodejs版本不能过高,试过node18构建会报错,建议版本node14~node16

配置环境变量

1
2
3
4
tee -a /etc/profile << EOF
export NODE_HOME=/opt/node
export PATH=$PATH:$NODE_HOME/bin
EOF

使环境变量生效

1
source /etc/profile

安装yarn

1
npm install -g yarn

安装go

https://mirrors.aliyun.com/golang/可以找需要的版本

1
2
wget https://mirrors.aliyun.com/golang/go1.20.3.linux-amd64.tar.gz
tar xzvf go1.20.3.linux-amd64.tar.gz -C /opt/

1
2
3
4
5
6
tee -a /etc/profile << EOF
export GO_HOME=/opt/go
export PATH=$PATH:$GO_HOME/bin
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
EOF

使环境变量生效

1
source /etc/profile

安装APISIX Dashboard

下载源码

1
wget https://github.com/apache/apisix-dashboard/archive/refs/tags/v2.15.1.tar.gz

解压源码

1
2
3
tar xzvf v2.15.1.tar.gz

cd apisix-dashboard-2.15.1

构建

1
make build

构建完成会打印以下内容,估计要7分钟左右

1
2
3
4
5
6
7
其他省略...

The bundle size is significantly larger than recommended.
Consider reducing it with code splitting: https://umijs.org/docs/load-on-demand
You can also analyze the project dependencies using ANALYZE=1

Done in 433.32s.

编译完将output拷贝到/opt/apisix-dashboard

1
mkdir -p mkdir -p /usr/local/apisix/dashboard && cp -r ./output/* /usr/local/apisix/dashboard

修改配置

如果是http访问etcd仅需配置ectd的访问地址即可

如果是https访问etcd则需要相关证书

将根证书,etcd-server-key证书,etcd-server证书拷贝到apisix目录下

1
2
3
4
mkdir -p /usr/local/apisix/ssl

# 根据具体情况即可
cp /opt/etcd3/ssl/{etcd-ca.pem,etcd-server-key.pem,etcd-server.pem} /usr/local/apisix/ssl/

修改vi /usr/local/apisix/dashboard/conf/conf.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 其余省略...
etcd:
endpoints: # supports defining multiple etcd host addresses for an etcd cluster
- 10.1.80.91:2379
- 10.1.80.92:2379
- 10.1.80.93: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: "/usr/local/apisix/ssl/etcd-server-key.pem" # Path of your self-signed client side key
cert_file: "/usr/local/apisix/ssl/etcd-server.pem" # Path of your self-signed client side cert
ca_file: "/usr/local/apisix/ssl/etcd-ca.pem" # 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
# 其余省略...

运行APISIX DASHBOARD

frontend方式运行apisix-dashboard(不推荐)

1
2
cd /usr/local/apisix/dashboard
./manager-api

安装为系统服务(推荐)

1
2
3
4
5
6
7
8
9
10
11
tee /usr/lib/systemd/system/apisix-dashboard.service << EOF
[Unit]
Description=apisix-dashboard
Conflicts=apisix-dashboard.service
After=network-online.target

[Service]
WorkingDirectory=/usr/local/apisix/dashboard
ExecStart=/usr/local/apisix/dashboard/manager-api -c /usr/local/apisix/dashboard/conf/conf.yaml

EOF

服务管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# reload下
systemctl daemon-reload

# enable apisix-dashboard
systemctl enable apisix-dashboard

# start apisix-dashboard
systemctl start apisix-dashboard

# stop apisix-dashboard
systemctl stop apisix-dashboard

# check apisix-dashboard status
systemctl status apisix-dashboard

访问http://10.1.80.91:9000/

若出现以下错误,需要将您的机器IP加入白名单,修改conf.yaml将IP地址或IP网段加入到allow_list内即可

1
2
3
4
5
6
{
Code: 20002,
Message: "IP address not allowed",
Data: null,
SourceSrv: ""
}

修改vi /usr/local/apisix/dashboard/conf/conf.yaml,加入允许访问的网段即可

1
2
3
4
5
6
7
# 其余省略...
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.
- 10.1.80.0/24 # 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
# 其余省略...