ubuntu 20.04安装 Apache APISIX

系统设置

~# cat /etc/security/limits.conf

root soft core unlimited
root hard core unlimited
root soft nproc 1000000
root hard nproc 1000000
root soft nofile 100000
root hard nofile 100000
root soft memlock 32000
root hard memlock 32000
root soft msgqueue 8192000
root hard msgqueue 8192000

  • soft core unlimited
  • hard core unlimited
  • soft nproc 1000000
  • hard nproc 1000000
  • soft nofile 100000
  • hard nofile 100000
  • soft memlock 32000
  • hard memlock 32000
  • soft msgqueue 8192000
  • hard msgqueue 8192000

安装etcd

 wget https://github.com/etcd-io/etcd/releases/download/v3.5.3/etcd-v3.5.3-linux-amd64.tar.gz
 tar -xvf etcd-v3.5.3-linux-amd64.tar.gz 
 cd etcd-v3.5.3-linux-amd64
 cp -a etcd etcdctl /usr/bin/
 nohup etcd >/tmp/etcd.log 2>&1 &

安装apache apisix

https://apisix.apache.org/zh/docs/apisix/getting-started

安装依赖

curl https://raw.githubusercontent.com/apache/apisix/master/utils/install-dependencies.sh -sL | bash -

下载apache apisix

wget https://downloads.apache.org/apisix/${APISIX_VERSION}/apache-apisix-2.13.1-src.tgz

解压apache apisix

mkdir apisix-2.13.1
tar zxvf apache-apisix-2.13.1-src.tgz -C apisix-2.13.1

安装apache apisix

cd apisix-2.13.1
LUAROCKS_SERVER=https://luarocks.cn make deps
make install
cp  -rf apisix /usr/local/apisix/
cp  -rf deps /usr/local/apisix/

管理 Apache APISIX 服务

初始化依赖

 apisix init

启动 Apache APISIX

apisix start

停止运行 Apache APISIX

apisix quit

修改 Admin API key

请修改 conf/config.yaml 中的 apisix.admin_key 并重启服务,如下所示:
~# cat /usr/local/apisix/conf/config.yaml 
apisix:
  admin_key:
    - name: admin
      key: edd1c9f034335f134f87ad84b625c8f1  # using fixed API token has security risk, please update it when you deploy to production environment
      role: admin

为 Apache APISIX 添加 systemd 配置文件

~# cat /lib/systemd/system/apisix.service
[Unit]
Description=apisix
#Conflicts=apisix.service
After=network-online.target
Wants=network-online.target

[Service]
Type=forking
Restart=on-failure
WorkingDirectory=/usr/local/apisix
ExecStart=/usr/bin/apisix start
ExecStop=/usr/bin/apisix stop
ExecReload=/usr/bin/apisix reload
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

API访问测试

~# curl http://127.0.0.1:9080/apisix/admin/routes?api_key=edd1c9f034335f134f87ad84b625c8f1 -i
HTTP/1.1 200 OK
Date: Tue, 19 Apr 2022 08:22:01 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX/2.13.1
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 3600

{"count":0,"action":"get","node":{"nodes":[],"key":"/apisix/routes","dir":true}}

端口占用

默认的端口 
80  openresty
9080 apisix
9443 apisix
2379 etcd

安装apache apisix Dashboard

https://apisix.apache.org/zh/docs/dashboard/install

安装node

wget https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-x64.tar.xz
tar xf node-v16.14.2-linux-x64.tar.xz -C /usr/local/
ln -svf /usr/local/node-v16.14.2-linux-x64 /usr/local/node
/usr/local/node/bin/corepack enable

安装go

wget https://go.dev/dl/go1.18.1.linux-amd64.tar.gz
tar xf go1.18.1.linux-amd64.tar.gz -C /usr/local/

下载apisix dashboard

wget https://dlcdn.apache.org/apisix/dashboard/2.11.0/apache-apisix-dashboard-2.11.0-src.tgz

解压apisix dashboard

mkdir apisix-dashboard-2.11.0
tar xf apache-apisix-dashboard-2.11.0-src.tgz -C apisix-dashboard-2.11.0/

安装apisix dashboard

cd apisix-dashboard-2.11.0/
make build

创建web server

mkdir -p /usr/local/apisix-dashboard
cp -rf ./output/* /usr/local/apisix-dashboard

添加apisix-dashboard.service

cp ./api/service/apisix-dashboard.service /usr/lib/systemd/system/apisix-dashboard.service
cat /lib/systemd/system/apisix-dashboard.service 
[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

管理web server

# start apisix-dashboard
systemctl start apisix-dashboard

stop apisix-dashboard

systemctl stop apisix-dashboard

check apisix-dashboard status

systemctl status apisix-dashboard

添加访问IP白名单

~# cat /usr/local/apisix-dashboard/conf/conf.yaml

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.
- 0.0.0.0/0 # It also support CIDR like 192.168.1.0/24 and 2001:0db8::/32

~# systemctl restart apisix-dashboard

访问dashboard

默认用户名:admin

默认密码:admin

http://127.0.0.1:9000

Apisix dashboard 结合grafana

修改 Grafana 配置

~# grep allow_embedding /etc/grafana/grafana.ini 
allow_embedding = true

apisix dashboard 设置

posted @ 2022-04-19 17:58  小吉猫  阅读(1314)  评论(0编辑  收藏  举报