实现 LightOps 运维面板基础功能
This commit is contained in:
68
web/public/install-agent.sh
Normal file
68
web/public/install-agent.sh
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
SERVER=""
|
||||
TOKEN=""
|
||||
BIN_URL=""
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--server) SERVER="$2"; shift 2 ;;
|
||||
--token) TOKEN="$2"; shift 2 ;;
|
||||
--bin-url) BIN_URL="$2"; shift 2 ;;
|
||||
*) echo "未知参数:$1" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$SERVER" ] || [ -z "$TOKEN" ]; then
|
||||
echo "用法:install-agent.sh --server https://panel.example.com --token TOKEN [--bin-url URL]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "请使用 root 用户运行" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
install -d /etc/lightops /usr/local/bin
|
||||
|
||||
if [ -z "$BIN_URL" ]; then
|
||||
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
||||
ARCH="$(uname -m)"
|
||||
BIN_URL="$SERVER/downloads/lightops-agent-$OS-$ARCH"
|
||||
fi
|
||||
|
||||
if [ -n "$BIN_URL" ]; then
|
||||
curl -fsSL "$BIN_URL" -o /usr/local/bin/lightops-agent
|
||||
chmod +x /usr/local/bin/lightops-agent
|
||||
elif [ ! -x /usr/local/bin/lightops-agent ]; then
|
||||
echo "未在 /usr/local/bin/lightops-agent 找到 lightops-agent 二进制文件"
|
||||
echo "请先复制二进制文件,或传入 --bin-url https://.../lightops-agent"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat >/etc/lightops/agent.toml <<EOF
|
||||
server_url = "$SERVER"
|
||||
token = "$TOKEN"
|
||||
heartbeat_interval = 30
|
||||
EOF
|
||||
|
||||
cat >/etc/systemd/system/lightops-agent.service <<'EOF'
|
||||
[Unit]
|
||||
Description=LightOps Agent
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/lightops-agent --config /etc/lightops/agent.toml
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now lightops-agent
|
||||
Reference in New Issue
Block a user