云网牛站
所在位置:首页 > Linux教程 > 在Ubuntu 18.04/Debian 9上安装Grafana的方法

在Ubuntu 18.04/Debian 9上安装Grafana的方法

2019-01-08 21:33:20作者:戴均力稿源:云网牛站

本文介绍在Ubuntu 18.04/Debian 9系统上安装Grafana的方法,有两种常用的安装方法,使用官方APT存储库及从.deb包安装,首选方法是使用apt存储库,因为你可以使用Debian和Ubuntu的apt包管理器轻松升级到最新版本。

 

方法1、使用APT存储库在Ubuntu 18.04/Debian 9上安装Grafana

1、将以下行添加到/etc/apt/sources.list.d/grafana.list文件中:

$ cat /etc/apt/sources.list.d/grafana.list

deb https://packagecloud.io/grafana/stable/debian/ stretch main

2、然后添加Package Cloud密钥,这允许你安装签名包:

$ sudo curl https://packagecloud.io/gpg.key | sudo apt-key add -

% Total % Received % Xferd Average Speed Time Time Time Current

Dload Upload Total Spent Left Speed

100 3889 100 3889 0 0 5446 0 --:--:-- --:--:-- --:--:-- 5439

OK

3、更新apt索引并安装grafana:

# apt-get update

Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease

Hit:2 http://mirrors.digitalocean.com/ubuntu bionic InRelease 

Get:3 http://mirrors.digitalocean.com/ubuntu bionic-updates InRelease [83.2 kB] 

Get:4 http://mirrors.digitalocean.com/ubuntu bionic-backports InRelease [74.6 kB] 

Get:5 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe Sources [26.1 kB]

Get:6 http://mirrors.digitalocean.com/ubuntu bionic-updates/main Sources [42.0 kB] 

Hit:7 http://mirror.zol.co.zw/mariadb/repo/10.3/ubuntu bionic InRelease 

Get:8 http://mirrors.digitalocean.com/ubuntu bionic-updates/main amd64 Packages [113 kB]

Get:9 http://mirrors.digitalocean.com/ubuntu bionic-updates/main Translation-en [43.6 kB]

Get:10 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe amd64 Packages [68.0 kB]

Get:11 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe Translation-en [30.4 kB]

Get:12 https://packagecloud.io/grafana/stable/debian stretch InRelease [23.2 kB] 

Get:13 https://packagecloud.io/grafana/stable/debian stretch/main amd64 Packages [3418 B]

Fetched 507 kB in 3s (185 kB/s)

Reading package lists... Done

4、运行以下命令在Ubuntu 18.04上安装Grafana:

$ sudo apt-get install grafana

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following package was automatically installed and is no longer required:

grub-pc-bin

Use 'apt autoremove' to remove it.

The following NEW packages will be installed:

grafana

0 upgraded, 1 newly installed, 0 to remove and 26 not upgraded.

Need to get 52.8 MB of archives.

After this operation, 159 MB of additional disk space will be used.

Get:1 https://packagecloud.io/grafana/stable/debian stretch/main amd64 grafana amd64 5.4.2 [52.8 MB]

Fetched 52.8 MB in 2s (26.6 MB/s)  

Selecting previously unselected package grafana.

(Reading database ... 64405 files and directories currently installed.)

Preparing to unpack .../grafana_5.4.2_amd64.deb ...

Unpacking grafana (5.4.2) ...

Processing triggers for ureadahead (0.100.0-20) ...

Processing triggers for systemd (237-3ubuntu10) ...

Setting up grafana (5.4.2) ...

Adding system user `grafana' (UID 114) ...

Adding new user `grafana' (UID 114) with group `grafana' ...

Not creating home directory `/usr/share/grafana'.

### NOT starting on installation, please execute the following statements to configure grafana to start automatically using systemd

sudo /bin/systemctl daemon-reload

sudo /bin/systemctl enable grafana-server

### You can start grafana-server by executing

sudo /bin/systemctl start grafana-server

Processing triggers for ureadahead (0.100.0-20) ...

Processing triggers for systemd (237-3ubuntu10) ...

5、启动并启用grafana-server服务以在启动时启动:

$ sudo systemctl start grafana-server

6、启用它以在启动时启动:

# systemctl enable  grafana-server

Synchronizing state of grafana-server.service with SysV service script with /lib/systemd/systemd-sysv-install.

Executing: /lib/systemd/systemd-sysv-install enable grafana-server

Created symlink /etc/systemd/system/multi-user.target.wants/grafana-server.service → /usr/lib/systemd/system/grafana-server.service.

7、检查状态以确认它正在运行:

# systemctl status grafana-server

在Ubuntu 18.04/Debian 9上安装Grafana的方法

 

方法2、使用.deb包在Ubuntu 18.04/Debian 9上安装Grafana

1、本文要安装的版本是grafana_5.4.2,可以使用wget来安装,也可以上grafana网站下载:

#wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.4.2_amd64.deb

--2019-01-08 8:14:33-- https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.4.2_amd64.deb

Resolving s3-us-west-2.amazonaws.com (s3-us-west-2.amazonaws.com)... 52.218.193.16

Connecting to s3-us-west-2.amazonaws.com (s3-us-west-2.amazonaws.com)|52.218.193.16|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 52632986 (50M) [application/x-debian-package]

Saving to: ‘grafana_5.4.2_amd64.deb’

grafana_5.4.2_amd64. 100%[======================>]  52.8M  11.7MB/s    in 8.3s    

2019-01-08 8:14:32 (6.08 MB/s) - ‘grafana_5.4.2_amd64.deb’ saved [52632986/52632986]

2、然后使用dpkg安装:

$ sudo apt-get install -y adduser libfontconfig

$ sudo dpkg -i grafana_5.4.2_amd64.deb

(Reading database ... 65752 files and directories currently installed.)

Preparing to unpack grafana_5.4.2_amd64.deb ...

Unpacking grafana (5.4.2) over (5.4.2) ...

Setting up grafana (5.4.2) ...

Restarting grafana-server service... OK

Processing triggers for ureadahead (0.100.0-20) ...

Processing triggers for systemd (237-3ubuntu10) ...

 

在防火墙上打开端口

1、Grafana默认http端口为3000,你需要允许访问防火墙上的此端口,Ubuntu带有ufw防火墙,参考在Ubuntu 18.04系统中使用UFW设置防火墙,对于Debian,你可以使用以下命令安装它:

$ sudo apt-get install ufw

2、然后启用防火墙服务:

$ sudo ufw enable

3、打开防火墙上的端口:

$ sudo ufw allow 3000/tcp 

Rule added

Rule added (v6)

4、要仅允许从特定子网访问,请使用:

$ sudo ufw allow from 192.168.50.0/24 to any port 3000

 

访问Grafana仪表板

使用服务器IP地址或主机名和端口3000访问Grafana仪表板:

在Ubuntu 18.04/Debian 9上安装Grafana的方法

默认登录名是:

用户名:admin

密码:admin

 

附:Grafana相关知识

将二进制文件安装到/usr/sbin/grafana-server

将Init.d脚本安装到/etc/init.d/grafana-server

创建/etc/default/grafana-server的默认文件,systemd服务文件和init.d脚本都在位于/etc/default/grafana-server的文件上

将配置文件安装到/etc/grafana/grafana.ini

安装systemd服务(如果systemd可用)名称为grafana-server.service

默认配置将日志文件设置为/var/log/grafana/grafana.log

默认配置在/var/lib/grafana/grafana.db中指定sqlite3数据库

在/usr/share/grafana上安装HTML/JS/CSS和其他Grafana文件

 

相关主题

在CentOS 7上安装Grafana的方法

精选文章
热门文章