背景
玩一玩
由于都是non-root启动,所以,都是:
- 先下载压缩包
- 配置systemctl服务配置文件
- systemctl start/status/stop {服务名}
grafana
下载:https://grafana.com/grafana/download
需要使用non-root启动的话,下载Standalone Linux Binaries
解压
配置systemctl:
[root@localhost system]# cat grafana-server.service
[Unit]
Description=grafana - enables you to query, visualize, alert on, and explore your metrics, logs, and traces wherever they are stored.
Documentation=https://grafana.com/docs/grafana/latest/introduction/
After=network-online.target
[Service]
Type=simple
ExecStart=/home/sysadmin/monitor/grafana-v10.2.2/bin/grafana server \
--homepath /home/sysadmin/monitor/grafana-v10.2.2 \
--config /home/sysadmin/monitor/grafana-v10.2.2/conf/custom.ini
Restart=on-failure
User=sysadmin
Group=sysadmin
[Install]
WantedBy=multi-user.target
[root@localhost system]#
启动:
[root@localhost system]# systemctl start grafana-server.service
[root@localhost system]# systemctl status grafana-server.service
● grafana-server.service - grafana - enables you to query, visualize, alert on, and explore your metrics, logs, and traces wherever they are stored.
Loaded: loaded (/etc/systemd/system/grafana-server.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2023-12-11 17:49:29 CST; 7s ago
Docs: https://grafana.com/docs/grafana/latest/introduction/
Main PID: 2548 (grafana)
Tasks: 21 (limit: 100057)
Memory: 102.2M
CGroup: /system.slice/grafana-server.service
└─2548 /home/sysadmin/monitor/grafana-v10.2.2/bin/grafana server --homepath /home/sysadmin/monitor/grafana-v10.2.2 --config /home/sysadmin/monitor/grafana-v10.2.2/conf/custom.ini
12月 11 17:49:33 localhost.localdomain grafana[2548]: logger=sqlstore.transactions t=2023-12-11T17:49:33.234603441+08:00 level=info msg="Database locked, sleeping then retrying" error="database is lo>
12月 11 17:49:33 localhost.localdomain grafana[2548]: logger=ngalert.migration t=2023-12-11T17:49:33.339105773+08:00 level=info msg=Starting
12月 11 17:49:33 localhost.localdomain grafana[2548]: logger=ngalert.migration t=2023-12-11T17:49:33.339602491+08:00 level=info msg="No migrations to run"
12月 11 17:49:33 localhost.localdomain grafana[2548]: logger=http.server t=2023-12-11T17:49:33.388485736+08:00 level=info msg="HTTP Server Listen" address=[::]:3000 protocol=http subUrl=/grafana sock>
12月 11 17:49:33 localhost.localdomain grafana[2548]: logger=ngalert.state.manager t=2023-12-11T17:49:33.644194974+08:00 level=info msg="State cache has been initialized" states=0 duration=421.887563>
12月 11 17:49:33 localhost.localdomain grafana[2548]: logger=ngalert.scheduler t=2023-12-11T17:49:33.644248371+08:00 level=info msg="Starting scheduler" tickInterval=10s
12月 11 17:49:33 localhost.localdomain grafana[2548]: logger=ticker t=2023-12-11T17:49:33.644342054+08:00 level=info msg=starting first_tick=2023-12-11T17:49:40+08:00
12月 11 17:49:33 localhost.localdomain grafana[2548]: logger=ngalert.multiorg.alertmanager t=2023-12-11T17:49:33.644355847+08:00 level=info msg="Starting MultiOrg Alertmanager"
12月 11 17:49:33 localhost.localdomain grafana[2548]: logger=plugins.update.checker t=2023-12-11T17:49:33.666795693+08:00 level=info msg="Update check succeeded" duration=443.293369ms
12月 11 17:49:34 localhost.localdomain grafana[2548]: logger=grafana.update.checker t=2023-12-11T17:49:34.026805884+08:00 level=info msg="Update check succeeded" duration=803.690713ms
[root@localhost system]# ps -ef |grep grafana
sysadmin 2548 1 15 17:49 ? 00:00:02 /home/sysadmin/monitor/grafana-v10.2.2/bin/grafana server --homepath /home/sysadmin/monitor/grafana-v10.2.2 --config /home/sysadmin/monitor/grafana-v10.2.2/conf/custom.ini
root 2572 1942 0 17:49 pts/1 00:00:00 grep --color=auto grafana
[root@localhost system]#
检查停止:
[root@localhost system]# systemctl stop grafana-server.service
[root@localhost system]# systemctl status grafana-server.service
● grafana-server.service - grafana - enables you to query, visualize, alert on, and explore your metrics, logs, and traces wherever they are stored.
Loaded: loaded (/etc/systemd/system/grafana-server.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: https://grafana.com/docs/grafana/latest/introduction/
12月 11 17:49:33 localhost.localdomain grafana[2548]: logger=ngalert.multiorg.alertmanager t=2023-12-11T17:49:33.644355847+08:00 level=info msg="Starting MultiOrg Alertmanager"
12月 11 17:49:33 localhost.localdomain grafana[2548]: logger=plugins.update.checker t=2023-12-11T17:49:33.666795693+08:00 level=info msg="Update check succeeded" duration=443.293369ms
12月 11 17:49:34 localhost.localdomain grafana[2548]: logger=grafana.update.checker t=2023-12-11T17:49:34.026805884+08:00 level=info msg="Update check succeeded" duration=803.690713ms
12月 11 17:50:22 localhost.localdomain grafana[2548]: logger=infra.usagestats t=2023-12-11T17:50:22.23100276+08:00 level=info msg="Usage stats are ready to report"
12月 11 17:50:56 localhost.localdomain systemd[1]: Stopping grafana - enables you to query, visualize, alert on, and explore your metrics, logs, and traces wherever they are stored....
12月 11 17:50:56 localhost.localdomain grafana[2548]: logger=server t=2023-12-11T17:50:56.762804431+08:00 level=info msg="Shutdown started" reason="System signal: terminated"
12月 11 17:50:56 localhost.localdomain grafana[2548]: logger=tracing t=2023-12-11T17:50:56.763057587+08:00 level=info msg="Closing tracing"
12月 11 17:50:56 localhost.localdomain grafana[2548]: logger=ticker t=2023-12-11T17:50:56.763272714+08:00 level=info msg=stopped last_tick=2023-12-11T17:50:50+08:00
12月 11 17:50:56 localhost.localdomain systemd[1]: grafana-server.service: Succeeded.
12月 11 17:50:56 localhost.localdomain systemd[1]: Stopped grafana - enables you to query, visualize, alert on, and explore your metrics, logs, and traces wherever they are stored..
[root@localhost system]#
配置开机启动:
[root@localhost system]# systemctl enable grafana-server.service
Created symlink /etc/systemd/system/multi-user.target.wants/grafana-server.service → /etc/systemd/system/grafana-server.service.
[root@localhost system]# systemctl start grafana-server.service
prometheus
下载:https://prometheus.io/download/#prometheus
解压
prometheus启动参数:https://prometheus.io/docs/prometheus/latest/command-line/pro...
配置systemctl:
[root@localhost system]# cat prometheus.service
[Unit]
Description=prometheus - open-source systems monitoring and alerting toolkit
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
Type=simple
PIDFile=/home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus.pid
ExecStart=/home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus \
--config.file=/home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus.yml \
--storage.tsdb.retention.time=15d \
--storage.tsdb.path=/home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/data/ \
--web.max-connections=512 \
--web.read-timeout=5m \
--query.max-concurrency=20 \
--query.timeout=2m
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus.pid)"
User=sysadmin
Group=sysadmin
[Install]
WantedBy=multi-user.target
[root@localhost system]# pwd
/etc/systemd/system
[root@localhost system]#
启动:systemctl start prometheus
:
[root@localhost system]# vi prometheus.service
[root@localhost system]# systemctl start prometheus
Warning: The unit file, source configuration file or drop-ins of prometheus.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl start prometheus
[root@localhost system]# systemctl status prometheus.service
● prometheus.service - prometheus - open-source systems monitoring and alerting toolkit
Loaded: loaded (/etc/systemd/system/prometheus.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2023-12-11 15:55:42 CST; 6s ago
Docs: https://prometheus.io/docs/introduction/overview/
Main PID: 2111 (prometheus)
Tasks: 10 (limit: 100057)
Memory: 30.4M
CGroup: /system.slice/prometheus.service
└─2111 /home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus --config.file=/home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus.yml --storage.tsdb.retention.time=15d ->
12月 11 15:55:42 localhost.localdomain prometheus[2111]: ts=2023-12-11T07:55:42.428Z caller=head.go:761 level=info component=tsdb msg="WAL segment loaded" segment=10 maxSegment=12
12月 11 15:55:42 localhost.localdomain prometheus[2111]: ts=2023-12-11T07:55:42.449Z caller=head.go:761 level=info component=tsdb msg="WAL segment loaded" segment=11 maxSegment=12
12月 11 15:55:42 localhost.localdomain prometheus[2111]: ts=2023-12-11T07:55:42.449Z caller=head.go:761 level=info component=tsdb msg="WAL segment loaded" segment=12 maxSegment=12
12月 11 15:55:42 localhost.localdomain prometheus[2111]: ts=2023-12-11T07:55:42.450Z caller=head.go:798 level=info component=tsdb msg="WAL replay completed" checkpoint_replay_duration=1.520374ms wal_>
12月 11 15:55:42 localhost.localdomain prometheus[2111]: ts=2023-12-11T07:55:42.452Z caller=main.go:1045 level=info fs_type=XFS_SUPER_MAGIC
12月 11 15:55:42 localhost.localdomain prometheus[2111]: ts=2023-12-11T07:55:42.452Z caller=main.go:1048 level=info msg="TSDB started"
12月 11 15:55:42 localhost.localdomain prometheus[2111]: ts=2023-12-11T07:55:42.452Z caller=main.go:1229 level=info msg="Loading configuration file" filename=/home/sysadmin/monitor/prometheus-2.48.0.>
12月 11 15:55:42 localhost.localdomain prometheus[2111]: ts=2023-12-11T07:55:42.453Z caller=main.go:1266 level=info msg="Completed loading of configuration file" filename=/home/sysadmin/monitor/prome>
12月 11 15:55:42 localhost.localdomain prometheus[2111]: ts=2023-12-11T07:55:42.453Z caller=main.go:1009 level=info msg="Server is ready to receive web requests."
12月 11 15:55:42 localhost.localdomain prometheus[2111]: ts=2023-12-11T07:55:42.453Z caller=manager.go:1012 level=info component="rule manager" msg="Starting rule manager..."
lines 1-20/20 (END)
检查进程在:
[root@localhost system]# ps -ef |grep prometheus
sysadmin 2111 1 0 15:55 ? 00:00:00 /home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus --config.file=/home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus.yml --storage.tsdb.retention.time=15d --storage.tsdb.path=/home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/data/ --web.max-connections=512 --web.read-timeout=5m --query.max-concurrency=20 --query.timeout=2m
root 2160 1942 0 16:04 pts/1 00:00:00 grep --color=auto prometheus
检查停止正常:
[root@localhost system]# systemctl stop prometheus.service
[root@localhost system]# systemctl status prometheus.service
● prometheus.service - prometheus - open-source systems monitoring and alerting toolkit
Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2023-12-11 16:06:38 CST; 5s ago
Docs: https://prometheus.io/docs/introduction/overview/
Process: 2182 ExecStop=/bin/sh -c /bin/kill -s TERM $(/bin/cat /home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus.pid) (code=exited, status=1/FAILURE)
Process: 2111 ExecStart=/home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus --config.file=/home/sysadmin/monitor/prometheus-2.48.0.linux-amd64/prometheus.yml --storage.tsdb.retention.ti>
Main PID: 2111 (code=exited, status=0/SUCCESS)
12月 11 16:06:38 localhost.localdomain prometheus[2111]: ts=2023-12-11T08:06:38.036Z caller=manager.go:1036 level=info component="rule manager" msg="Rule manager stopped"
12月 11 16:06:38 localhost.localdomain prometheus[2111]: ts=2023-12-11T08:06:38.036Z caller=main.go:934 level=info msg="Stopping scrape manager..."
12月 11 16:06:38 localhost.localdomain prometheus[2111]: ts=2023-12-11T08:06:38.036Z caller=main.go:879 level=info msg="Scrape discovery manager stopped"
12月 11 16:06:38 localhost.localdomain prometheus[2111]: ts=2023-12-11T08:06:38.036Z caller=main.go:893 level=info msg="Notify discovery manager stopped"
12月 11 16:06:38 localhost.localdomain prometheus[2111]: ts=2023-12-11T08:06:38.036Z caller=main.go:926 level=info msg="Scrape manager stopped"
12月 11 16:06:38 localhost.localdomain prometheus[2111]: ts=2023-12-11T08:06:38.095Z caller=notifier.go:604 level=info component=notifier msg="Stopping notification manager..."
12月 11 16:06:38 localhost.localdomain prometheus[2111]: ts=2023-12-11T08:06:38.095Z caller=main.go:1155 level=info msg="Notifier manager stopped"
12月 11 16:06:38 localhost.localdomain prometheus[2111]: ts=2023-12-11T08:06:38.095Z caller=main.go:1167 level=info msg="See you next time!"
12月 11 16:06:38 localhost.localdomain systemd[1]: prometheus.service: Failed with result 'exit-code'.
12月 11 16:06:38 localhost.localdomain systemd[1]: Stopped prometheus - open-source systems monitoring and alerting toolkit.
[root@localhost system]# ps -ef |grep prometheus
root 2191 1942 0 16:06 pts/1 00:00:00 grep --color=auto prometheus
[root@localhost system]#
配置开机启动:
[root@localhost system]# systemctl enable prometheus.service
Created symlink /etc/systemd/system/multi-user.target.wants/prometheus.service → /etc/systemd/system/prometheus.service.
[root@localhost system]#
node_exporter
下载:https://prometheus.io/download/#node_exporter
解压
配置systemctl:
[root@localhost system]# cat node_exporter.service
[Unit]
Description=node_exporter - Prometheus exporter for hardware and OS metrics
Documentation=https://github.com/prometheus/node_exporter; https://prometheus.io/docs/guides/node-exporter/;
After=network-online.target
[Service]
Type=simple
ExecStart=/home/sysadmin/monitor/node_exporter-1.7.0.linux-amd64/node_exporter
Restart=on-failure
User=sysadmin
Group=sysadmin
[Install]
WantedBy=multi-user.target
[root@localhost system]#
启动:
[root@localhost system]# systemctl start node_exporter.service
[root@localhost system]# systemctl status node_exporter.service
● node_exporter.service - node_exporter - Prometheus exporter for hardware and OS metrics
Loaded: loaded (/etc/systemd/system/node_exporter.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2023-12-11 16:19:44 CST; 4s ago
Docs: https://github.com/prometheus/node_exporter;
https://prometheus.io/docs/guides/node-exporter/;
Main PID: 2231 (node_exporter)
Tasks: 6 (limit: 100057)
Memory: 18.6M
CGroup: /system.slice/node_exporter.service
└─2231 /home/sysadmin/monitor/node_exporter-1.7.0.linux-amd64/node_exporter
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=thermal_zone
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=time
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=timex
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=udp_queues
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=uname
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=vmstat
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=xfs
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=zfs
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9100
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=[::]:9100
[root@localhost system]# ps -ef |grep node_exporter
sysadmin 2231 1 0 16:19 ? 00:00:00 /home/sysadmin/monitor/node_exporter-1.7.0.linux-amd64/node_exporter
root 2240 1942 0 16:20 pts/1 00:00:00 grep --color=auto node_exporter
[root@localhost system]#
检查停止正常:
[root@localhost system]# systemctl stop node_exporter.service
[root@localhost system]# ps -ef |grep node
root 2249 1942 0 16:23 pts/1 00:00:00 grep --color=auto node
[root@localhost system]# systemctl status node_exporter.service
● node_exporter.service - node_exporter - Prometheus exporter for hardware and OS metrics
Loaded: loaded (/etc/systemd/system/node_exporter.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: https://github.com/prometheus/node_exporter;
https://prometheus.io/docs/guides/node-exporter/;
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=udp_queues
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=uname
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=vmstat
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=xfs
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=node_exporter.go:117 level=info collector=zfs
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9100
12月 11 16:19:45 localhost.localdomain node_exporter[2231]: ts=2023-12-11T08:19:45.017Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=[::]:9100
12月 11 16:23:22 localhost.localdomain systemd[1]: Stopping node_exporter - Prometheus exporter for hardware and OS metrics...
12月 11 16:23:22 localhost.localdomain systemd[1]: node_exporter.service: Succeeded.
12月 11 16:23:22 localhost.localdomain systemd[1]: Stopped node_exporter - Prometheus exporter for hardware and OS metrics.
[root@localhost system]#
配置开机启动:
[root@localhost system]# systemctl enable node_exporter.service
Created symlink /etc/systemd/system/multi-user.target.wants/node_exporter.service → /etc/systemd/system/node_exporter.service.
[root@localhost system]#
成果
忘记grafana密码了:
[sysadmin@localhost bin]$ ls -l
总用量 194400
-rwxr-xr-x 1 sysadmin sysadmin 195352632 11月 20 21:24 grafana
-rwxr-xr-x 1 sysadmin sysadmin 1851408 11月 20 21:24 grafana-cli
-rwxr-xr-x 1 sysadmin sysadmin 1851408 11月 20 21:24 grafana-server
[sysadmin@localhost bin]$ ./grafana-cli admin reset-admin-password monitor
Deprecation warning: The standalone 'grafana-cli' program is deprecated and will be removed in the future. Please update all uses of 'grafana-cli' to 'grafana cli'
INFO [12-11|17:56:36] Starting Grafana logger=settings version= commit= branch= compiled=1970-01-01T08:00:00+08:00
INFO [12-11|17:56:36] Config loaded from logger=settings file=/home/sysadmin/monitor/grafana-v10.2.2/conf/defaults.ini
INFO [12-11|17:56:36] Config loaded from logger=settings file=/home/sysadmin/monitor/grafana-v10.2.2/conf/custom.ini
INFO [12-11|17:56:36] Target logger=settings target=[all]
INFO [12-11|17:56:36] Path Home logger=settings path=/home/sysadmin/monitor/grafana-v10.2.2
INFO [12-11|17:56:36] Path Data logger=settings path=/home/sysadmin/monitor/grafana-v10.2.2/data
INFO [12-11|17:56:36] Path Logs logger=settings path=/home/sysadmin/monitor/grafana-v10.2.2/data/log
INFO [12-11|17:56:36] Path Plugins logger=settings path=/home/sysadmin/monitor/grafana-v10.2.2/data/plugins
INFO [12-11|17:56:36] Path Provisioning logger=settings path=/home/sysadmin/monitor/grafana-v10.2.2/conf/provisioning
INFO [12-11|17:56:36] App mode production logger=settings
INFO [12-11|17:56:36] Connecting to DB logger=sqlstore dbtype=sqlite3
INFO [12-11|17:56:36] Starting DB migrations logger=migrator
INFO [12-11|17:56:36] migrations completed logger=migrator performed=0 skipped=608 duration=545.03µs
INFO [12-11|17:56:36] Validated license token logger=licensing appURL=http://localhost:3000/grafana/ source=disk status=NotFound
INFO [12-11|17:56:36] Envelope encryption state logger=secrets enabled=true current provider=secretKey.v1
Admin password changed successfully ✔
[sysadmin@localhost bin]$
创建一个dashboard:
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。