使用ansible批量安装Prometheus node_exporter

使用

pip install ansible
mkdir -p /etc/ansible/
touch /etc/ansible/hosts

修改hosts主机配置文件,把需要安装的服务器,按照下面格式写

[node]
172.16.170.127 ansible_ssh_user=root ansible_ssh_pass="123456"
172.16.170.128 ansible_ssh_user=root ansible_ssh_pass="123456"
172.16.170.129 ansible_ssh_user=root ansible_ssh_pass="123456"

进入node_exporter目录执行下面命令

ansible-playbook node_exporter.yml -i /etc/ansible/hosts

安装完成后,提供安装的IP就可以了。默认的监听端口是9100

修改端口

修改node_exporter.service,将9100改成需要的就可以了

ExecStart=/opt/node_exporter-0.18.1.linux-amd64/node_exporter --web.listen-address=0.0.0.0:9100

附件

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=/opt/node_exporter-0.18.1.linux-amd64/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

node_exporter.yml

---
- hosts: node
  user: root
  gather_facts: false
  tasks: 
  - name: 安装node_exporter
    unarchive: src=node_exporter-0.18.1.linux-amd64.tar.gz dest=/opt/ 
  - name: 添加node_exporter服务
    copy: src=node_exporter.service dest=/usr/lib/systemd/system/
  - name: 设置开机自动启动
    shell: systemctl enable node_exporter.service 
  - name: 启动服务
    shell: systemctl start node_exporter.service 

你可能感兴趣的:(DevOps)