cd /usr/local/bin
curl -O https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
tar -zxvf node_exporter-1.7.0.linux-amd64.tar.gz
mv node_exporter-1.7.0.linux-amd64 node_exporter
方法一
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://github.com/prometheus/node_exporter
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/node_exporter/node_exporter --web.listen-address=:9100
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start node_exporter
systemctl status node_exporter
systemctl enable node_exporter
vim /etc/rc.local
方法二
#node_exporte启动
nohup /usr/local/bin/node_exporter/node_exporter --web.listen-address=:9100 &
问题
执行systemctl enable node_exporter.service,实现开机自启动服务,出现:Failed to execute operation: File exists
[root@k8s-master system]# systemctl enable node_exporter.service
Failed to execute operation: File exists
解决方法:
1、执行 find / -name node_exporter.service,查找由于之前安装 node_exporter没有卸载干净,产生了重复的文件 node_exporter.service以及符号链接.
[root@k8s-master system]# find / -name node_exporter.service
/sys/fs/cgroup/devices/system.slice/node_exporter.service
/sys/fs/cgroup/cpu,cpuacct/system.slice/node_exporter.service
/sys/fs/cgroup/pids/system.slice/node_exporter.service
/sys/fs/cgroup/memory/system.slice/node_exporter.service
/sys/fs/cgroup/blkio/system.slice/node_exporter.service
/sys/fs/cgroup/systemd/system.slice/node_exporter.service
/etc/systemd/system/multi-user.target.wants/node_exporter.service
/etc/systemd/system/node_exporter.service
2、删除重复文件
rm -rf /etc/systemd/system/multi-user.target.wants/node_exporter.service
3、执行开机自启动node_exporter
systemctl enable node_exporter.service