Alpine安装nezha-agent探针

chen'mo
2022-11-23 / 0 评论 / 12,229 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年11月23日,已超过759天没有更新,若内容或图片失效,请留言反馈。

哪吒监控的被控端服务被称为 Agent,只记录在apline 3.16上安装过程。

参考官方文档:
https://nezhahq.github.io/guide/agent.html#%E5%9C%A8-%E5%85%B6%E4%BB%96-linux-%E5%A6%82-alpine-%E4%BD%BF%E7%94%A8-openrc-%E7%9A%84%E5%8F%91%E8%A1%8C%E7%89%88-%E5%AE%89%E8%A3%85-agent

一、登陆SSH里执行

cat >/etc/init.d/nezha-agent<< EOF
#!/sbin/openrc-run
SERVER="" #Dashboard 地址 ip:port
SECRET="" #SECRET
TLS="" # 是否启用 tls 是 "--tls" 否留空
NZ_BASE_PATH="/opt/nezha"
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
pidfile="/run/${RC_SVCNAME}.pid"
command="/opt/nezha/agent/nezha-agent"
command_args="-s ${SERVER}  -p ${SECRET} ${TLS}"
command_background=true
depend() {
    need net
}
checkconfig() {
    GITHUB_URL="github.com"
    if [ ! -f "${NZ_AGENT_PATH}/nezha-agent" ]; then
        if [[ $(uname -m | grep 'x86_64') != "" ]]; then
            os_arch="amd64"
        elif [[ $(uname -m | grep 'i386\|i686') != "" ]]; then
            os_arch="386"
        elif [[ $(uname -m | grep 'aarch64\|armv8b\|armv8l') != "" ]]; then
            os_arch="arm64"
        elif [[ $(uname -m | grep 'arm') != "" ]]; then
            os_arch="arm"
        elif [[ $(uname -m | grep 's390x') != "" ]]; then
            os_arch="s390x"
        elif [[ $(uname -m | grep 'riscv64') != "" ]]; then
            os_arch="riscv64"
        fi
        local version=$(curl -m 10 -sL "https://api.github.com/repos/naiba/nezha/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
        if [ ! -n "$version" ]; then
            version=$(curl -m 10 -sL "https://fastly.jsdelivr.net/gh/naiba/nezha/" | grep "option\.value" | awk -F "'" '{print $2}' | sed 's/naiba\/nezha@/v/g')
        fi
        if [ ! -n "$version" ]; then
            version=$(curl -m 10 -sL "https://gcore.jsdelivr.net/gh/naiba/nezha/" | grep "option\.value" | awk -F "'" '{print $2}' | sed 's/naiba\/nezha@/v/g')
        fi
        if [ ! -n "$version" ]; then
            echo -e "获取版本号失败,请检查本机能否链接 https://api.github.com/repos/naiba/nezha/releases/latest"
            return 0
        else
            echo -e "当前最新版本为: ${version}"
        fi
        wget -t 2 -T 10 -O nezha-agent_linux_${os_arch}.zip https://${GITHUB_URL}/naiba/nezha/releases/download/${version}/nezha-agent_linux_${os_arch}.zip >/dev/null 2>&1
        if [[ $? != 0 ]]; then
            echo -e "Release 下载失败,请检查本机能否连接 ${GITHUB_URL}${plain}"
            return 0
        fi
        mkdir -p $NZ_AGENT_PATH
        chmod 755 -R $NZ_AGENT_PATH
        unzip -qo nezha-agent_linux_${os_arch}.zip && mv nezha-agent $NZ_AGENT_PATH && rm -rf nezha-agent_linux_${os_arch}.zip README.md
    fi
    if [ ! -x "${NZ_AGENT_PATH}/nezha-agent" ]; then
        chmod +x ${NZ_AGENT_PATH}/nezha-agent
    fi
}
start_pre() {
    if [ "${RC_CMD}" != "restart" ]; then
        checkconfig || return $?
    fi
}
EOF

二、增加运行权限

chmod +x /etc/init.d/nezha-agent

三、运行 Nezha-Agent

rc-service nezha-agent start

四、添加开机自启动

rc-update add nezha-agent

PS:
刚开始我在64M以及32M的小鸡上折腾是各种错误。

如果报文件找不到的错误,可能是/etc/init.d/nezha-agent文件里面有乱码,需要清理一下。
Test

内存太小了,不能apk add sudo bash curl。(头一回见sudo bash可以安装的)
只好手挫文件。用wget下载好后,移动到对应文件夹,增加权限解决。
https://github.com/naiba/nezha/releases/download/v0.14.4/nezha-agent_linux_amd64.zip

wget -O /etc/init.d/nezha-agent https://513513.xyz/v/nezha-agent (注意修改里面的参数)
wget -O /opt/nezha/agent/nezha-agent https://513513.xyz/v/opt/nezha-agent

32M小鸡上搭好的演示:
32M
64M小鸡上我装的caddy php8还是很流畅, 安装nezha就会经常卡。
64M

撸玩这些小鸡也就索然无味了。
国内脚本
curl -L https://jihulab.com/nezha/nezha/-/raw/master/script/install.sh -o nezha.sh && chmod +x nezha.sh && sudo CN=true ./nezha.sh

https://github.com/naiba/nezha/releases/download/v0.14.4/nezha-agent_linux_amd64.zip

0
Apline 常用命令
« 上一篇 11-20
hostcram黑五闪购套餐 $6 or $8/yr 1GB i9 NVMe KVM VPS
下一篇 » 11-28

评论 (0)