> For the complete documentation index, see [llms.txt](https://monaive.gitbook.io/prometheus/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://monaive.gitbook.io/prometheus/part-ii-prometheus-shu-ju-cai-ji-yu-gao-jing/exporter/node/node_exporter.md).

# Linux

## node\_exporter

Node\_exporter部署请参考 第二章 部署/二进制部署 中的Node\_exporter。 还可以使用Ansible进行部署。

## Ansible Playbook部署node\_exporter

node\_exporter为golang开发编译的程序，直接运行即可。

### 1.新建ansible playbook roles

```
# 进入ansible roles目录
cd /etc/ansible/roles

# 初始化
ansible-galaxy init deploy_node_exporter

# 下载node_exporter
cd deploy_node_exporter/files
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz

# 目录结构
tree deploy_node_exporter/
deploy_node_exporter/
├── defaults
│   └── main.yml
├── files
│   └── node_exporter-0.18.1.linux-amd64.tar.gz
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── README.md
├── tasks
│   └── main.yml
├── templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars
    └── main.yml
```

### 2.编写playbook tasks

vi /etc/ansible/roles/deploy\_node\_exporter/tasks/main.yml

```
---
- name: create directory /ops
  file: 
    path: /ops
    state: directory
    mode: '0755'

- name: unarchive node_exporter
  unarchive:
    src: node_exporter-0.18.1.linux-amd64.tar.gz
    dest: /ops/

- name: configure node_exporter.service
  lineinfile:
    path: /usr/lib/systemd/system/node_exporter.service
    line: "{{ item }}"
    create: yes
    state: present
  with_items:
    - "[Unit]"
    - "Description=Node Exporter For Prometheus"
    - "[Service]"
    - "Type=simple"
    - "ExecStart=/ops/node_exporter-0.18.1.linux-amd64/node_exporter"
    - "[Install]"
    - "WantedBy=mutil-user.target"

- name: start and enable service
  shell: |
    systemctl daemon-reload 
    systemctl enable node_exporter
    systemctl start node_exporter
- name: add firewall port 9100
  shell: firewall-cmd --add-port=9100/tcp --permanent && firewall-cmd --reload
```

### 3.编写playbook

vi /etc/ansible/workflow/deploy\_node\_exporter.yml 其中hosts为需要安装的机器。

```
---
- hosts: node01
  remote_user: root
  roles:
    - deploy_node_exporter
```

### 4.部署node\_exporter

```
ansible-playbook deploy_node_exporter.yml
```

### 5.验证

```
curl http://node01:9100/metrics
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://monaive.gitbook.io/prometheus/part-ii-prometheus-shu-ju-cai-ji-yu-gao-jing/exporter/node/node_exporter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
