Loading... ### Smartctl Exporter 安装 从[官网]([https://prometheus.io/download/](https://github.com/prometheus/smartctl_exporter/releases))下载对应的 Smartctl Exporter 软件包,解压到 `/usr/local/smartctl_exporter` ```bash wget https://github.com/prometheus-community/smartctl_exporter/releases/download/v0.12.0/smartctl_exporter-0.12.0.linux-amd64.tar.gz tar zxvf smartctl_exporter-0.12.0.linux-amd64.tar.gz mv smartctl_exporter-0.12.0.linux-amd64 /usr/local/smartctl_exporter ``` 安装依赖,`smartmontools >= 7` ```bash apk install smartmontools ``` ### 配置 TLS 和 Basic Auth #### TLS 将安装 Prometheus 时创建的证书 `node_exporter.crt` 和密钥 `node_exporter.key` 复制到 Smartctl Exporter 路径 `/usr/local/smartctl_exporter/` 创建配置文件 `vim /usr/local/smartctl_exporter/config.yaml` ```yaml tls_server_config: cert_file: node_exporter.crt key_file: node_exporter.key ``` #### Basic Auth 使用 htpasswd 生成密码hash(如果命令不存在,则需要安装软件包 `apt install apache2-utils` ) ```bash htpasswd -nBC 12 '' | tr -d ':\n' ``` 完整的 `/usr/local/smartctl_exporter/config.yaml` 配置文件参考: ```yaml tls_server_config: cert_file: node_exporter.crt key_file: node_exporter.key # 增加 BasicAuth 验证 basic_auth_users: # 当前设置的用户名为 asdasfdassad,可以设置多个,冒号后面为上面生成的密码hash asdasfdassad: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ``` ### 通过服务启动 创建服务 `vim /etc/systemd/system/smartctl_exporter.service`,要根据实际情况修改启动参数 ```bash [Unit] Description=Prometheus smartctl exporter Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/smartctl_exporter/smartctl_exporter --web.config.file=/usr/local/smartctl_exporter/config.yaml [Install] WantedBy=multi-user.target ``` 创建用户并赋权 ```bash useradd prometheus -M -s /sbin/nologin chown prometheus:prometheus /usr/local/smartctl_exporter -R chmod 755 /usr/local/smartctl_exporter -R ``` 设置开机启动并启动服务 ```bash systemctl enable smartctl_exporter service smartctl_exporter start service smartctl_exporter status ``` ### 增加防火墙规则 Smartctl Exporter 默认使用 `9633` 端口,防火墙上需要放行这个端口(不建议公网直接访问),建议只允许 Prometheus 服务端IP访问 ``` iptables -A INPUT -s 1.1.1.1/32 -p tcp --dport 9633 -j ACCEPT -m comment --comment "prometheus-smartctl-exporter" iptables-save >/etc/iptables/rules.v4 ``` ## 在 Prometheus 服务端增加 Job `prometheus.yml` 中增加,然后 reload 配置 ``` - job_name: 'smartctl-exporter' scheme: https tls_config: ca_file: node_exporter.crt server_name: "qwerto.local" insecure_skip_verify: true basic_auth: username: **** password: ************** static_configs: - targets: ['x.x.x.x:9633'] ``` ## Grafana https://github.com/blesswinsamuel/grafana-dashboards/blob/main/dashboards/dist/smartctl.json 最后修改:2024 年 04 月 25 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏