麒麟os需据其ubuntu/debian或centos/rhel底层选择安装方式:ubuntu系用apt添加influxdata仓库并安装telegraf;centos系用yum创建influxdb.repo后安装,均需启动并启用服务。

如果您在麒麟OS系统中需要部署Telegraf以实现指标数据采集,则需结合其基于Debian/Ubuntu或CentOS/RHEL的底层发行版特性选择适配安装路径。麒麟OS V10桌面版与服务器版分别对应不同内核基线,安装方式需按实际系统标识判断。以下是针对麒麟OS的多种可行安装方法:
一、通过APT包管理器安装(适用于麒麟OS基于Ubuntu/Debian的版本)
该方法适用于麒麟OS桌面版(如V10 SP1,内核标识含ubuntu或deb-based),利用系统已配置的APT源或添加InfluxData官方仓库,确保依赖自动解析与后续升级支持。
1、执行系统更新并安装基础工具:
sudo apt update && sudo apt install -y software-properties-common curl apt-transport-https
2、添加InfluxData官方GPG密钥:
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
3、添加稳定版仓库源(适配麒麟OS的amd64/arm64架构):
echo "deb https://repos.influxdata.com/debian stable main" | sudo tee /etc/apt/sources.list.d/influxdata.list
4、再次更新软件包索引并安装telegraf:
sudo apt update && sudo apt install -y telegraf
5、启动服务并设为开机自启:
sudo systemctl daemon-reload && sudo systemctl enable telegraf && sudo systemctl start telegraf
二、通过YUM/DNF安装(适用于麒麟OS基于CentOS/RHEL的版本)
该方法适用于麒麟OS服务器版(如V10 SP3,内核标识含el7/el8或centos),通过创建InfluxData YUM仓库配置文件完成安装,兼容麒麟OS对RPM包签名机制的校验要求。
1、创建InfluxData仓库配置文件:
sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - Stable
baseurl = https://repos.influxdata.com/stable/\$basearch/main
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdata-archive.key
EOF
2、导入GPG公钥以通过签名验证:
sudo rpm --import https://repos.influxdata.com/influxdata-archive.key
3、安装telegraf主程序:
sudo yum install -y telegraf
4、启用并启动服务:
sudo systemctl daemon-reload && sudo systemctl enable telegraf && sudo systemctl start telegraf
三、使用预编译二进制包离线安装(适用于无外网或受限环境)
该方法不依赖系统包管理器,适用于麒麟OS政务专网、隔离网络或需指定Telegraf精确版本(如1.33.3)的场景,支持手动控制用户权限与服务生命周期。
1、创建专用低权限运行用户:
sudo useradd -r -s /bin/false telegraf
2、下载对应CPU架构的tar.gz包(以麒麟OS主流的arm64平台为例):
cd /tmp && curl -sLO https://dl.influxdata.com/telegraf/releases/telegraf-1.33.3_linux_arm64.tar.gz
3、解压至/opt/telegraf并设置属主:
sudo mkdir -p /opt/telegraf && sudo tar xzf telegraf-1.33.3_linux_arm64.tar.gz -C /opt/telegraf --strip-components=1
sudo chown -R telegraf:telegraf /opt/telegraf
4、建立全局可执行链接:
sudo ln -sf /opt/telegraf/usr/bin/telegraf /usr/local/bin/telegraf
5、复制默认配置并授权:
sudo cp /opt/telegraf/etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf
sudo chown telegraf:telegraf /etc/telegraf/telegraf.conf
6、创建systemd服务单元文件(/etc/systemd/system/telegraf.service):
[Unit]
Description=The plugin-driven server agent for reporting metrics into InfluxDB
Documentation=https://github.com/influxdata/telegraf
After=network.target
[Service]
User=telegraf
EnvironmentFile=-/etc/default/telegraf
ExecStart=/usr/local/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d \$TELEGRAF_OPTS
Restart=on-failure
RestartSec=30
RestartPreventExitStatus=255
KillMode=control-group
[Install]
WantedBy=multi-user.target
7、重载systemd配置并启用服务:
sudo systemctl daemon-reload && sudo systemctl enable telegraf && sudo systemctl start telegraf
四、验证麒麟OS系统架构并确认安装路径
麒麟OS存在多架构变体(x86_64、arm64、loongarch64),错误选择二进制包将导致无法执行。必须先确认当前系统准确架构,再匹配对应安装资源。
1、查看CPU架构类型:
uname -m
2、若输出为aarch64或arm64,则须选用arm64构建包;若输出为x86_64,则选用amd64包;若输出为loongarch64,则需从InfluxData社区或麒麟OS生态镜像站获取LoongArch专用构建版本。
3、检查telegraf进程是否正常运行:
sudo systemctl status telegraf
4、确认telegraf配置语法有效性:
sudo -u telegraf /usr/local/bin/telegraf --config /etc/telegraf/telegraf.conf --test










