Grafana(1)安装和配置

Ubuntu安装

首先需要安装依赖。

1
$ sudo apt-get install -y adduser libfontconfig1

如果使用的是Centos系统,则需要安装一个urw字体依赖。

1
$ sudo yum install urw-fonts

进入Grafana下载页面Download Grafana选择deb安装包,下载直接安装。

1
2
$ wget https://dl.grafana.com/oss/release/grafana_10.0.0_amd64.deb
$ sudo dpkg -i grafana_10.0.0_amd64.deb

启动服务

1
2
3
$ sudo /bin/systemctl daemon-reload
$ sudo /bin/systemctl enable grafana-server.service
$ sudo /bin/systemctl start grafana-server.service

检查服务状态。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$  sudo /bin/systemctl status grafana-server.service
● grafana-server.service - Grafana instance
Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-06-09 10:48:41 CST; 1 weeks 6 days ago
Docs: http://docs.grafana.org
Main PID: 3315 (grafana)
Tasks: 13 (limit: 4915)
CGroup: /system.slice/grafana-server.service
└─3315 /usr/share/grafana/bin/grafana server --config=/etc/grafana/grafana.ini --pidfile=/run/grafana/grafana-server.pid --packaging=deb cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana cfg:default.paths.

Jun 22 13:45:16 VM-0-5-ubuntu grafana[3315]: logger=context userId=0 orgId=0 uname= t=2023-06-22T13:45:16.309927024+08:00 level=info msg="Request Completed" method=GET path=/favicon.ico status=302 remote_addr=127.0.0.1 time_ms=0 duration=391.531µJun 22 13:48:48 VM-0-5-ubuntu grafana[3315]: logger=cleanup t=2023-06-22T13:48:48.324101724+08:00 level=info msg="Completed cleanup jobs" duration=35.652862ms
Jun 22 13:48:49 VM-0-5-ubuntu grafana[3315]: logger=plugins.update.checker t=2023-06-22T13:48:49.317745125+08:00 level=info msg="Update check succeeded" duration=290.429755ms
Jun 22 13:48:49 VM-0-5-ubuntu grafana[3315]: logger=grafana.update.checker t=2023-06-22T13:48:49.621393118+08:00 level=info msg="Update check succeeded" duration=741.522769ms
Jun 22 13:58:48 VM-0-5-ubuntu grafana[3315]: logger=cleanup t=2023-06-22T13:58:48.323309543+08:00 level=info msg="Completed cleanup jobs" duration=35.628673ms
Jun 22 13:58:49 VM-0-5-ubuntu grafana[3315]: logger=grafana.update.checker t=2023-06-22T13:58:49.125999268+08:00 level=info msg="Update check succeeded" duration=246.277611ms
Jun 22 13:58:49 VM-0-5-ubuntu grafana[3315]: logger=plugins.update.checker t=2023-06-22T13:58:49.361911566+08:00 level=info msg="Update check succeeded" duration=334.347133ms
Jun 22 14:08:48 VM-0-5-ubuntu grafana[3315]: logger=cleanup t=2023-06-22T14:08:48.308940924+08:00 level=info msg="Completed cleanup jobs" duration=20.468025ms
Jun 22 14:08:49 VM-0-5-ubuntu grafana[3315]: logger=plugins.update.checker t=2023-06-22T14:08:49.318130025+08:00 level=info msg="Update check succeeded" duration=291.288081ms
Jun 22 14:08:50 VM-0-5-ubuntu grafana[3315]: logger=grafana.update.checker t=2023-06-22T14:08:50.228624628+08:00 level=info msg="Update check succeeded" duration=1.348194856s

grafana默认监听3000端口,检查端口状态。

1
2
3
4
$ netstat -nlpt | grep 3000
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::3000 :::* LISTEN -

配置nginx

配置nginx通过80端口转发到3000端口。

1
2
3
4
5
6
7
8
server {
listen 80;
server_name grafana.domain.com;
location / {
proxy_set_header Host $http_host;
proxy_pass http://localhost:3000/;
}
}

这里一定要设置proxy_set_header Host $http_host;这个header,不然会出现访问错误。