apisix的安装脚本

!/bin/bash

Script to install Apache APISIX on Ubuntu

Based on https://apisix.apache.org/docs/apisix/installation-guide/

set -e
echo "Installing Apache APISIX..."

Check if running as root

if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi

Install necessary dependencies

echo "Installing dependencies..."
apt update
apt install -y wget curl gnupg

Install etcd

echo "Installing etcd..."
ETCD_VERSION='3.5.4'
wget https://github.com/etcd-io/etcd/releases/download/v\({ETCD_VERSION}/etcd-v\){ETCD_VERSION}-linux-amd64.tar.gz
tar -xvf etcd-v\({ETCD_VERSION}-linux-amd64.tar.gz cd etcd-v\){ETCD_VERSION}-linux-amd64
cp -a etcd etcdctl /usr/bin/
cd ..
rm -rf etcd-v${ETCD_VERSION}-linux-amd64*

Start etcd in the background

echo "Starting etcd..."
nohup etcd >/tmp/etcd.log 2>&1 &
sleep 2 # Give etcd time to start

Detect architecture

ARCH=$(dpkg --print-architecture)
echo "Detected architecture: $ARCH"

Add APISIX repository

echo "Adding APISIX repository..."
wget -O - http://repos.apiseven.com/pubkey.gpg | apt-key add -
if [ "$ARCH" = "arm64" ]; then
echo "deb http://repos.apiseven.com/packages/arm64/debian bullseye main" | tee /etc/apt/sources.list.d/apisix.list
else
echo "deb http://repos.apiseven.com/packages/debian bullseye main" | tee /etc/apt/sources.list.d/apisix.list
fi

Update package list

apt update

Install APISIX

echo "Installing APISIX..."
apt install -y apisix

Initialize APISIX

echo "Initializing APISIX..."
apisix init

Start APISIX

echo "Starting APISIX..."
apisix start

Add systemd configuration for automatic startup if needed

if [ ! -f /lib/systemd/system/apisix.service ]; then
echo "Creating systemd service file for APISIX..."
cat > /lib/systemd/system/apisix.service << 'EOF'
[Unit]
Description=APISIX API Gateway
After=network.target

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

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
echo "Enabling APISIX service to start on boot..."
systemctl enable apisix
fi

echo "APISIX installation completed successfully!"
echo "You can access the Admin API at: http://127.0.0.1:9180/apisix/admin/routes"
echo "Default API key is 'edd1c9f034335f136f87ad84b625c8f1'"
echo "To modify this key, edit the conf/config.yaml file"

posted @ 2025-05-06 09:04  昆仑葫芦  阅读(3)  评论(0)    收藏  举报