将需要手动启动的服务,添加至systemctl管理中进行服务的统一管理,可以配置开机自动启动。

将prometheus加入到system

  1. [root@localhost system]# cat prometheus.service
  2. [Unit]
  3. Description=Promethues Watch App
  4. [Service]
  5. Restart=on-failure
  6. ExecStart=/home/watch/prometheus/prometheus --config.file=/home/watch/prometheus/prometheus.yml
  7. [Install]
  8. WantedBy=multi-user.target
  9. #添加至开机启动
  10. [root@localhost system]# systemctl enable prometheus.service
  11. Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.
  12. #会将/usr/lib/systemd/system下的对应service文件软连接到/etc/systemd/system/multi-user.target下
  13. #multi-user.target.wants是字符界面默认启动的服务集合

将alertmanager加入到system

  1. [root@localhost system]# systemctl status alertmanager.service
  2. alertmanager.service - Alertmanager server
  3. Loaded: loaded (/usr/lib/systemd/system/alertmanager.service; disabled; vendor preset: disabled)
  4. Active: inactive (dead)
  5. [root@localhost system]# systemctl enable alertmanager.service
  6. Created symlink from /etc/systemd/system/multi-user.target.wants/alertmanager.service to /usr/lib/systemd/system/alertmanager.service.
  7. [root@localhost system]# cat alertmanager.service
  8. [Unit]
  9. Description=Alertmanager server
  10. [Service]
  11. ExecStart=/home/watch/alertmanager/alertmanager --config.file=/home/watch/alertmanager/alertmanager.yml --storage.path=/home/watch/alertmanager/data
  12. Restart=on-failure
  13. [Install]
  14. WantedBy=multi-user.target
  15. [root@localhost system]# systemctl status alertmanager.service
  16. alertmanager.service - Alertmanager server
  17. Loaded: loaded (/usr/lib/systemd/system/alertmanager.service; enabled; vendor preset: disabled)
  18. Active: active (running) since 2021-03-30 10:54:51 CST; 7s ago
  19. Main PID: 8373 (alertmanager)
  20. Tasks: 12
  21. Memory: 8.8M
  22. CGroup: /system.slice/alertmanager.service
  23. └─8373 /home/watch/alertmanager/alertmanager --config.file=/home/watch/alertmanager...
  24. 3 30 10:54:51 localhost.localdomain systemd[1]: Started Alertmanager server.
  25. 3 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51...."
  26. 3月 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51...."
  27. 3 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....4
  28. 3 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....s
  29. 3 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....l
  30. 3 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....l
  31. 3 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....r
  32. 3 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....3
  33. 3 30 10:54:53 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:53....s
  34. Hint: Some lines were ellipsized, use -l to show in full.