标准模版
vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus/data
Restart=on-failure
RestartSec=5s
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
参数说明:
[Unit]
Description:服务的描述
After=network.target:确保网络启动后再启动此服务
[Service] 部分定义了服务的行为,包括启动前的准备命令(ExecStartPre)、启动命令(ExecStart)、重新加载命令(ExecReload)等
ExecStart:指定脚本路径
Restart=on-failure:如果脚本因错误退出,会自动重启
User=root:使用 root 用户运行该服务(如果需要)
Environment:设置环境变量,如 LOG_FILE。确保脚本中读取 $LOG_FILE 的位置正确
RestartSec=5s 定义了在尝试重新启动之前等待的时间(秒)
LimitNOFILE=65536 设置了进程的最大文件描述符数,这对于需要处理大量时间序列数据的Prometheus来说是很重要的
[Install]
WantedBy=multi-user.target:服务将在系统的多用户目标下启动,通常为默认运行级别。
prometheus
[root@iZuf60yo2r6jhkx73c9owjZ ~]# vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
ExecStart=/www/wwwroot/wangjian.run/RuanJian/prometheus-2.53.2.linux-amd64/prometheus --config.file=/www/wwwroot/wangjian.run/RuanJian/prometheus-2.53.2.linux-amd64/prometheus.yml --storage.tsdb.path=/www/wwwroot/wangjian.run/RuanJian/prometheus-2.53.2.linux-amd64/data
Restart=on-failure
RestartSec=5s
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable prometheus.service
systemctl start prometheus.service
systemctl restart prometheus.service
systemctl status prometheus.service
node_exporter
[root@iZuf60yo2r6jhkx73c9owjZ ~]# vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
ExecStart=/www/wwwroot/wangjian.run/RuanJian/node_exporter-1.8.2.linux-amd64/node_exporter
Restart=on-failure
RestartSec=5s
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable node_exporter.service
systemctl status node_exporter.service
systemctl start node_exporter.service
systemctl restart node_exporter.service
systemctl status node_exporter.service
nginx
[root@k8s-master conf]# vim /etc/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP Server
Wants=network-online.target
After=network-online.target
[Service]
Type=forking
PIDFile=/opt/nginx-1.26.2/logs/nginx.pid
#ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecStart=/opt/nginx-1.26.2/sbin/nginx
Restart=on-failure
RestartSec=5s
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable nginx.service
systemctl start nginx.service
systemctl status nginx.service
systemctl restart nginx.service
样例3
vim /usr/lib/systemd/system/mysqld_exporter.service
#加入如下内容
[Unit]
Description=mysqld_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/software/installs/prometheus/mysqld_exporter/bin/mysqld_exporter --config.my-cnf=/software/installs/prometheus/mysqld_exporter/cfg/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
#完成且检查无误后:wq保存并退出
样例4 redis
vim /usr/lib/systemd/system/redis_exporter.service
#加入如下内容
[Unit]
Description=redis_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/software/installs/prometheus/redis_exporter/bin/redis_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
#完成且检查无误后:wq保存并退出
systemctl daemon-reload
systemctl enable redis_exporter.service
systemctl start redis_exporter.service
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容