anisble批量安装node_exporter
原文链接:https://www.cnblogs.com/lvzhenjiang/p/14374243.html
# anisble批量安装node_exporter (opens new window)
目录
- 一、目录结构 (opens new window)
- 二、playbook文件 (opens new window)
- 三、服务文件 (opens new window)
- 四、任务文件 (opens new window)
# 一、目录结构
$ tree .
.
|-- hosts
|-- node_exporter
| |-- files
| | |-- node_exporter-1.0.1.linux-amd64.tar.gz
| | `-- node_exporter.service
| `-- tasks
| `-- main.yml
`-- node_exporter.yml
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 二、playbook文件
$ cat node_exporter.yml
#!/usr/bin/env ansible-playbook
- hosts: all
remote_user: root
gather_facts: false
roles:
- role: node_exporter
1
2
3
4
5
6
7
2
3
4
5
6
7
# 三、服务文件
$ cat node_exporter/files/node_exporter.service
[Unit]
Description=Prometheus node_exporter
Requires=network.target remote-fs.target
After=network.target remote-fs.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/node_exporter/node_exporter --web.listen-address=0.0.0.0:9100
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 四、任务文件
$ cat node_exporter/tasks/main.yml
- name: 安装node_exporter
unarchive:
src: node_exporter-1.0.1.linux-amd64.tar.gz
dest: /usr/local/
- name: 创建软链接
file:
src: /usr/local/node_exporter-1.0.1.linux-amd64
dest: /usr/local/node_exporter
state: link
- name: 添加node_exporter服务
copy:
src: node_exporter.service
dest: /usr/lib/systemd/system/
- name: daemon-reload
systemd:
daemon_reload: yes
- name: 设置开机自动启动
systemd:
name: node_exporter
state: started
enabled: True
- name: 确定端口在监听
wait_for:
host: 0.0.0.0
port: 9100
delay: 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
*************** 当你发现自己的才华撑不起野心时,就请安静下来学习吧!***************
上次更新: 2024/10/22, 18:10:01