1.服务器环境ubuntu
2.全自动安装脚本
创建脚本:
nano install_glances.sh
粘贴最后脚本内容
给权限:
chmod +x install_glances.sh
运行脚本:
./install_glances.sh
脚本内容:
#!/bin/bashecho "开始全自动安装 Glances Web UI..."# 更新系统
echo "更新系统..."
sudo apt update -y && sudo apt upgrade -y# 安装 Python3 及 PIP
echo "安装 Python3 及必要组件..."
sudo apt install -y python3-pip python3-venv# 安装 Glances 及 Web 组件
echo "安装 Glances 及 Web 依赖..."
pip3 install --upgrade glances fastapi uvicorn jinja2# 创建 systemd 服务
echo "配置 Glances 开机自启..."
sudo tee /etc/systemd/system/glances.service > /dev/null <<EOF
[Unit]
Description=Glances in Web Mode
After=network.target[Service]
ExecStart=/usr/bin/python3 -m glances -w -B 0.0.0.0
Restart=always
User=ubuntu
Environment="PATH=/home/ubuntu/.local/bin:/usr/bin:/bin"[Install]
WantedBy=multi-user.target
EOF# 重新加载 systemd 并启用 Glances
sudo systemctl daemon-reload
sudo systemctl enable glances
sudo systemctl start glances# 放行防火墙端口
echo "放行 61208 端口..."
sudo ufw allow 61208/tcp
sudo ufw reload# 检查 Glances 运行状态
echo "Glances 安装完成!"
sudo systemctl status glances --no-pagerecho "现在可以访问 http://$(hostname -I | awk '{print $1}'):61208"