系統設置
~# 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