胸怀万里世界, 放眼无限未来。这篇文章主要讲述ansible批量安装node-exporter相关的知识,希望能为你提供帮助。
安装ansible
nginx yum install ansible -y |
SQL 1、创建相应的目录 mkdir -p /opt/node-export cd /opt/node-export/ 2、下载node-exporter和创建对应的启动文件 wgethttps://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz tar xf node_exporter-1.3.1.linux-amd64.tar.gz node_exporter-1.3.1.linux-amd64/ 3、启动文件 cat 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/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 【ansible批量安装node-exporter】 4、创建对应的ip地址 [root@k8s-master node-export]# cat iplist.txt [20220504] 172.16.5.122 172.16.5.146 5、远程拷贝文件 [root@k8s-master node-export]# ansible 20220504 -m copy -a"src=https://www.songbingjia.com/android/node_exporter dest=/opt/node-exporter/ backup=yes" -i iplist.txt [WARNING]: Invalid characters were found in group names but not replaced,use -vvvv to see details 172.16.5.122 | CHANGED => "ansible_facts": "discovered_interpreter_python": "/usr/bin/python" , "changed": true, "checksum":"6b88b4e8e0b109cb70d0410fea7df35692fe1216", "dest":"/opt/node-exporter/node_exporter", "gid": 0, "group":"root", "md5sum":"e105cbe3e43cc6e133a83358db009d36", "mode":"0644", "owner":"root", "size": 18228926, "src":"/root/.ansible/tmp/ansible-tmp-1651660508.81-32118-215511342287544/source", "state":"file", "uid": 0 172.16.5.146 | CHANGED => "ansible_facts": "discovered_interpreter_python": "/usr/bin/python" , "changed": true, "checksum":"6b88b4e8e0b109cb70d0410fea7df35692fe1216", "dest":"/opt/node-exporter/node_exporter", "gid": 0, "group":"root", "md5sum":"e105cbe3e43cc6e133a83358db009d36", "mode":"0644", "owner":"root", "size": 18228926, "src":"/root/.ansible/tmp/ansible-tmp-1651660508.8-32120-197167126853989/source", "state":"file", "uid": 0 6、发送服务自启动配置文件 [root@k8s-master node-export]# ansible 20220504 -m copy -a"src=https://www.songbingjia.com/android/files/node-exporter.service dest=/usr/lib/systemd/system/ backup=yes" -i iplist.txt [WARNING]: Invalid characters were found in group names but not replaced,use -vvvv to see details 172.16.5.122 | CHANGED => "ansible_facts": "discovered_interpreter_python": "/usr/bin/python" , "changed": true, "checksum":"8523709e50be5c4e1218feafa8b22baf30e5e682", "dest":"/usr/lib/systemd/system/node-exporter.service", "gid": 0, "group":"root", "md5sum":"2168230bbf44d0bf8bff4539bce3a357", "mode":"0644", "owner":"root", "size": 367, "src":"/root/.ansible/tmp/ansible-tmp-1651660799.58-4285-252476952854520/source", "state":"file", "uid": 0 7、创建自启动文件 [root@k8s-master node-export]# ansible 20220504 -m shell -a"systemctl enable node-exporter.service" -i iplist.txt [WARNING]: Invalid characters were found in group names but not replaced,use -vvvv to see details 172.16.5.146 | CHANGED | rc=0 > > Created symlink from/etc/systemd/system/multi-user.target.wants/node-exporter.service to/usr/lib/systemd/system/node-exporter.service. 172.16.5.122 | CHANGED | rc=0 > > Created symlink from/etc/systemd/system/multi-user.target.wants/node-exporter.service to/usr/lib/systemd/system/node-exporter.service. 8、赋权限 [root@k8s-master node-export]# ansible 20220504 -m shell -a "chmod755 /opt/node-exporter/node_exporter" -i iplist.txt 9、自启动文件 [root@k8s-master node-export]# ansible 20220504 -m shell -a"systemctl start node-exporter.service" -i iplist.txt [WARNING]: Invalid characters were found in group names but not replaced,use -vvvv to see details 172.16.5.146 | CHANGED | rc=0 > > 172.16.5.122 | CHANGED | rc=0 > > |
方法二、ansible 部署Prometheus node_exporter通过playbook
1、编写site.yaml文件
YAML 1、创建工作目录 [root@k8s-master ~]# mkdir -p /opt/node-export [root@k8s-master ~]# cd /opt/node-export/ 2、配置site.yaml [root@k8s-master node-export]# cat site.yaml - hosts: node-exporter tasks: - name: copy node_exporter copy: src:/opt/node-export/node_exporter dest: /opt/node-exporter/ owner: root group: root mode: 755 - name: copynode-exporter.service copy: src:files/node-exporter.service dest:/usr/lib/systemd/system/ notify: - call restart service - name: 开机自启动 shell: systemctl enablenode-exporter.service - name: 启动服务 shell: systemctl startnode-exporter.service |
2.1、创建目录files
CoffeeScript [root@k8s-master node-export]# mkdir files [root@k8s-master node-export]# cd files/ [root@k8s-master files]#wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz |
备注:files文件里面包含node_exporter二进制文件;开机自启文件node-exporter.service;node_exporter开机自启服务自定义端口配置node-exporter |
Makefile [root@k8s-master node-export]# cat 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=/opt/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 |
CoffeeScript [root@k8s-master node-export]# vim /etc/ansible/hosts [node-exporter] 172.16.5.122 172.16.5.146 |
Go [root@k8s-master node-export]# ansible-playbook site.yaml |
推荐阅读
- AR和VR的七大开源平台
- #yyds干货盘点# MySQL - 存储引擎
- socket编程
- 如何做一个微信答题小程序
- [OpenCV实战]31 使用OpenCV将一个三角形仿射变换到另一个三角形
- Flutter 专题108 图解 PageView 滑动页面预览小尝试 #yyds干货盘点#
- #yyds干货盘点# 解决剑指offer(二叉搜索树与双向链表)
- 初识C++ 函数重载以及背后的原理
- 前端(react)上传到阿里云OSS存储 实例