将需要手动启动的服务,添加至systemctl管理中进行服务的统一管理,可以配置开机自动启动。
将prometheus加入到system
[root@localhost system]# cat prometheus.service
[Unit]
Description=Promethues Watch App
[Service]
Restart=on-failure
ExecStart=/home/watch/prometheus/prometheus --config.file=/home/watch/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target
#添加至开机启动
[root@localhost system]# systemctl enable prometheus.service
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.
#会将/usr/lib/systemd/system下的对应service文件软连接到/etc/systemd/system/multi-user.target下
#multi-user.target.wants是字符界面默认启动的服务集合
将alertmanager加入到system
[root@localhost system]# systemctl status alertmanager.service
● alertmanager.service - Alertmanager server
Loaded: loaded (/usr/lib/systemd/system/alertmanager.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@localhost system]# systemctl enable alertmanager.service
Created symlink from /etc/systemd/system/multi-user.target.wants/alertmanager.service to /usr/lib/systemd/system/alertmanager.service.
[root@localhost system]# cat alertmanager.service
[Unit]
Description=Alertmanager server
[Service]
ExecStart=/home/watch/alertmanager/alertmanager --config.file=/home/watch/alertmanager/alertmanager.yml --storage.path=/home/watch/alertmanager/data
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@localhost system]# systemctl status alertmanager.service
● alertmanager.service - Alertmanager server
Loaded: loaded (/usr/lib/systemd/system/alertmanager.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2021-03-30 10:54:51 CST; 7s ago
Main PID: 8373 (alertmanager)
Tasks: 12
Memory: 8.8M
CGroup: /system.slice/alertmanager.service
└─8373 /home/watch/alertmanager/alertmanager --config.file=/home/watch/alertmanager...
3月 30 10:54:51 localhost.localdomain systemd[1]: Started Alertmanager server.
3月 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51...."
3月 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51...."
3月 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....4
3月 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....s
3月 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....l
3月 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....l
3月 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....r
3月 30 10:54:51 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:51....3
3月 30 10:54:53 localhost.localdomain alertmanager[8373]: level=info ts=2021-03-30T02:54:53....s
Hint: Some lines were ellipsized, use -l to show in full.