使用Docker在Ubuntu 20.04上安装Graphite和Graphite-Web

欢迎阅读在Ubuntu 20.04上捕获Graphite和Graphite-Web安装的指南。 Graphite是一个开放源代码监视平台,旨在提供高可用性并支持数据可视化。用户使用Graphite的方式是创建一个应用程序,该应用程序将数字的时间序列数据收集到图形中并将其发送到Graphite的处理后端。 ,将数据保存在Graphite的专用数据库中。

石墨:

  1. 保存数字时间序列数据
  2. 按需呈现此数据的图形

我们有很多 工具 可用于帮助收集数据并将其发送到Graphite。通常需要少量代码, 发送数据 转化为石墨非常容易。 石墨旨在实现前端和后端的水平可伸缩性。换句话说,您可以简单地通过将计算机添加到混合中来提高吞吐量。

石墨由三个软件组件组成:

  1. – 一种 监听时间序列数据的守护程序
  2. 耳语 –用于存储时间序列数据的简单数据库库(已设计 RRD
  3. 石墨网络应用 – 一种 Django的 Webapp使用来按需呈现图形 开罗

本文介绍如何在Ubuntu 20.04服务器上轻松运行Graphite Server实例。

使用Docker在Ubuntu 20.04上安装Graphite和Graphite-Web

在Ubuntu 20.04上运行Graphite的最简单,最快的方法是使用Docker容器。您所需要做的就是安装Docker,拉出容器映像,然后启动石墨容器。

步骤1:更新系统

首先更新和升级您的系统。

sudo apt update
sudo apt upgrade -y

升级完成后,重新启动系统。

sudo reboot

步骤2:安装Docker容器引擎

系统重启后,登录并安装一些依赖项。

sudo apt update
sudo apt -y install vim apt-transport-https ca-certificates curl gnupg-agent software-properties-common

从Docker APT存储库导入GPG密钥。

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

将Docker CE存储库添加到您的Ubuntu计算机。

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

在Ubuntu 20.04服务器上安装Docker CE。

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

将用户帐户添加到Docker组。

sudo usermod -aG docker $USER
newgrp docker

检查Docker版本并确认安装。

$ docker info
Client:
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 19.03.13
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.0-48-generic
 Operating System: Ubuntu 20.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 1.894GiB
 Name: ubuntu
 ID: ZJXE:T7RY:FSAV:CRBN:Q6Y7:YQQA:2ELU:VH25:P6PJ:6X6B:3WTC:EU2F
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

在继续之前,请确保服务正在运行。

$ systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-10-11 03:02:10 CEST; 1min 12s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 2663 (dockerd)
      Tasks: 8
     Memory: 35.7M
     CGroup: /system.slice/docker.service
             └─2663 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.495871164+02:00" level=warning msg="Your kernel does not support cgroup rt runtime"
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.496038020+02:00" level=warning msg="Your kernel does not support cgroup blkio weight"
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.496232070+02:00" level=warning msg="Your kernel does not support cgroup blkio weight_device"
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.497045530+02:00" level=info msg="Loading containers: start."
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.667666503+02:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0>
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.781078393+02:00" level=info msg="Loading containers: done."
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.835604534+02:00" level=info msg="Docker daemon" commit=4484c46d9d graphdriver(s)=overlay2 version>
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.836601759+02:00" level=info msg="Daemon has completed initialization"
Oct 11 03:02:10 ubuntu systemd[1]: Started Docker Application Container Engine.

步骤3:在Docker容器中的Ubuntu 20.04上运行Graphite

安装并运行Docker引擎后,启动Graphite和Statsd Docker容器。使用公式 石墨Docker存储库

下载最新的Docker映像。

$ docker pull  graphiteapp/graphite-statsd
Using default tag: latest
latest: Pulling from graphiteapp/graphite-statsd
df20fa9351a1: Pull complete
f9a569415da5: Pull complete
8f0c7d0dc99e: Pull complete
700de820209a: Pull complete
Digest: sha256:04a0037cc2ae7cc189b81fb38fbdc914fe269b861108821bea1ed776878334de
Status: Downloaded newer image for graphiteapp/graphite-statsd:latest
docker.io/graphiteapp/graphite-statsd:latest

列出可用的图像。

$ docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
graphiteapp/graphite-statsd   latest              875c7f22f4cd        2 months ago        628MB

在主机系统上创建目录以用于持久数据存储。这可以是专门用于存储Graphite数据的磁盘或分区安装点。

sudo mkdir -p /data/graphite/{data,logs,conf,statsd_config}

下载的图像包含以下组件:

映射端口

HostContainerService
8080Nginx的
2003年2003年碳纤维接收器–纯文本
2004年2004年碳接收器泡菜
2023年2023年碳聚集器–纯文本
2024年2024年碳聚集剂-腌渍
80808080石墨内部Gunicorn端口(无Nginx代理)。
81258125统计
81268126statsd管理员

Graphite&Statsd的配置可能很复杂。使用提供的Docker映像,您可以在几分钟内运行和收集统计信息。

请在执行命令之前将时区更改为正确的设置。

docker run -d 
 --name graphite 
 --restart=always 
 -p 80:80 
 -p 2003-2004:2003-2004 
 -p 2023-2024:2023-2024 
 -p 8125:8125/udp 
 -p 8126:8126 
 -v /data/graphite/data:/opt/graphite/storage 
 -v /data/graphite/conf:/opt/graphite/conf 
 -v /data/graphite/statsd_config:/opt/statsd/config 
 -v /data/graphite/logs:/var/log 
 -e GRAPHITE_TIME_ZONE='Africa/Nairobi' 
 graphiteapp/graphite-statsd

列出运行中的容器以查看石墨容器是否正在运行。

$ docker ps
CONTAINER ID        IMAGE                         COMMAND             CREATED             STATUS              PORTS                                                                                                                                                                       NAMES
4a26c4c0f746        graphiteapp/graphite-statsd   "/entrypoint"       31 seconds ago      Up 29 seconds       0.0.0.0:80->80/tcp, 0.0.0.0:2003-2004->2003-2004/tcp, 2013-2014/tcp, 8080/tcp, 0.0.0.0:2023-2024->2023-2024/tcp, 0.0.0.0:8126->8126/tcp, 8125/tcp, 0.0.0.0:8125->8125/udp   graphite

您可以流式传输日志以查看是否有任何错误。

$ docker logs -f graphite

样本输出:

,,..
1/10/2020 01:23:58 :: [tagdb] Tagged carbon.aggregator.4a26c4c0f746-a.destinations.127_0_0_1:2004:None.attemptedRelays, carbon.aggregator.4a26c4c0f746-a.bufferedDatapoints in 0.021245479583740234
11/10/2020 01:24:06 :: [listener] MetricLineReceiver connection with 127.0.0.1:57472 established
11/10/2020 01:24:06 :: [listener] MetricLineReceiver connection with 127.0.0.1:57472 closed cleanly
11/10/2020 01:24:08 :: [tagdb] Tagging carbon.agents.4a26c4c0f746-a.errors
11/10/2020 01:24:08 :: [tagdb] Tagged carbon.agents.4a26c4c0f746-a.errors in 0.15246272087097168
11/10/2020 01:24:16 :: [listener] MetricLineReceiver connection with 127.0.0.1:57476 established
11/10/2020 01:24:16 :: [listener] MetricLineReceiver connection with 127.0.0.1:57476 closed cleanly
11/10/2020 01:24:26 :: [listener] MetricLineReceiver connection with 127.0.0.1:57478 established
11/10/2020 01:24:26 :: [listener] MetricLineReceiver connection with 127.0.0.1:57478 closed cleanly
11/10/2020 01:24:26 :: [tagdb] Tagging stats.statsd.graphiteStats.last_flush
11/10/2020 01:24:26 :: [tagdb] Tagged stats.statsd.graphiteStats.last_flush in 0.013707160949707031
11/10/2020 01:24:36 :: [listener] MetricLineReceiver connection with 127.0.0.1:57482 established
11/10/2020 01:24:36 :: [listener] MetricLineReceiver connection with 127.0.0.1:57482 closed cleanly
11/10/2020 01:24:36 :: [tagdb] Tagging stats.timers.view.graphite.tags.views.tagMultiSeries.POST.count_90
11/10/2020 01:24:36 :: [tagdb] Tagged stats.timers.view.graphite.tags.views.tagMultiSeries.POST.count_90 in 0.011429786682128906
11/10/2020 01:24:46 :: [listener] MetricLineReceiver connection with 127.0.0.1:57486 established
11/10/2020 01:24:46 :: [listener] MetricLineReceiver connection with 127.0.0.1:57486 closed cleanly
11/10/2020 01:24:47 :: [tagdb] Tagging carbon.aggregator.4a26c4c0f746-a.whitelistRejects
11/10/2020 01:24:47 :: [tagdb] Tagged carbon.aggregator.4a26c4c0f746-a.whitelistRejects in 0.015319108963012695
11/10/2020 01:24:56 :: [listener] MetricLineReceiver connection with 127.0.0.1:57490 established
11/10/2020 01:24:56 :: [listener] MetricLineReceiver connection with 127.0.0.1:57490 closed cleanly
11/10/2020 01:24:57 :: [tagdb] Tagging carbon.agents.4a26c4c0f746-a.memUsage
11/10/2020 01:24:57 :: [tagdb] Tagged carbon.agents.4a26c4c0f746-a.memUsage in 0.009841442108154297
11/10/2020 01:25:06 :: [listener] MetricLineReceiver connection with 127.0.0.1:57494 established
11/10/2020 01:25:06 :: [listener] MetricLineReceiver connection with 127.0.0.1:57494 closed cleanly
11/10/2020 01:25:07 :: [tagdb] Tagging carbon.agents.4a26c4c0f746-a.creates
11/10/2020 01:25:07 :: [tagdb] Tagged carbon.agents.4a26c4c0f746-a.creates in 0.019759416580200195

默认情况下,statsd侦听UDP端口8125。如果要改为侦听TCP端口8125,则可以设置环境变量。 STATSD_INTERFACEtcp 运行容器时。

步骤4:访问Graphite Web界面

然后,您可以使用服务器的IP地址或端口号以及映射到主机容器中端口80的端口来访问Graphite Web控制台。

默认登录凭据为:

Username: root
Password: root

使用Docker在Ubuntu 20.04上安装Graphite和Graphite-Web

首次登录后,请更改此登录凭据 http:// ip-address / admin / auth / user / 1 /.. ”修改密码单击链接以开始更改root用户的密码。使用Docker在Ubuntu 20.04上安装Graphite和Graphite-Web

输入并确认所需的新root密码。使用Docker在Ubuntu 20.04上安装Graphite和Graphite-Web

现在,您可以使用新密码注销,然后再返回。

步骤5:使用Systemd管理石墨容器

让我们创建一个新的Systemd服务单元文件,以便容器在系统启动时启动。

sudo tee /etc/systemd/system/graphite-docker.service<<EOF
[Unit]
Description=Graphite Docker Container
Documentation=https://github.com/graphite-project/docker-graphite-statsd
After=docker.service
Requires=docker.service

[Service]
Type=simple
TimeoutStartSec=0
Restart=on-failure
RestartSec=30s
ExecStartPre=-/usr/bin/docker kill graphite
ExecStartPre=-/usr/bin/docker rm graphite
ExecStartPre=/usr/bin/docker pull graphiteapp/graphite-statsd
ExecStart=/usr/bin/docker run 
            --name graphite 
            --restart=always 
            -p 80:80 
            -p 2003-2004:2003-2004 
            -p 2023-2024:2023-2024 
            -p 8125:8125/udp 
            -p 8126:8126 
            -v /data/graphite/data:/opt/graphite/storage 
            -v /data/graphite/conf:/opt/graphite/conf 
            -v /data/graphite/statsd_config:/opt/statsd/config 
            -v /data/graphite/logs:/var/log 
            graphiteapp/graphite-statsd

SyslogIdentifier=graphite
ExecStop=/usr/bin/docker stop graphite

[Install]
WantedBy=multi-user.target
EOF

重新加载系统服务。

sudo systemctl daemon-reload

这将识别您创建的单位文件。

$ sudo systemctl list-unit-files graphite-docker.service
UNIT FILE               STATE    VENDOR PRESET
graphite-docker.service disabled enabled

1 unit files listed.

让我们能够在系统启动时启动服务。

$ sudo systemctl enable graphite-docker
Created symlink /etc/systemd/system/multi-user.target.wants/graphite-docker.service → /etc/systemd/system/graphite-docker.service.

终止正在运行的容器,以确保服务正常运行。

sudo docker rm -f graphite

如果没有其他容器,则ps列表应返回空。

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

启动系统服务。

sudo systemctl start graphite-docker.service

检查服务状态:

$ systemctl status graphite-docker.service
● graphite-docker.service - Graphite Docker Container
     Loaded: loaded (/etc/systemd/system/graphite-docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-10-11 03:53:48 CEST; 10s ago
       Docs: https://github.com/graphite-project/docker-graphite-statsd
    Process: 16394 ExecStartPre=/usr/bin/docker kill graphite (code=exited, status=1/FAILURE)
    Process: 16410 ExecStartPre=/usr/bin/docker rm graphite (code=exited, status=1/FAILURE)
    Process: 16416 ExecStartPre=/usr/bin/docker pull graphiteapp/graphite-statsd (code=exited, status=0/SUCCESS)
   Main PID: 16428 (docker)
      Tasks: 7 (limit: 2286)
     Memory: 25.1M
     CGroup: /system.slice/graphite-docker.service
             └─16428 /usr/bin/docker run --name graphite --restart=always -p 80:80 -p 2003-2004:2003-2004 -p 2023-2024:2023-2024 -p 8125:8125/udp -p 8126:8126 -v>

Oct 11 03:53:53 ubuntu graphite[16428]: run: carbon: (pid 73) 5s; run: log: (pid 72) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: run: carbon-aggregator: (pid 66) 5s; run: log: (pid 65) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: down: carbon-relay: 1s, normally up, want up; run: log: (pid 59) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: down: collectd: 1s, normally up, want up
Oct 11 03:53:53 ubuntu graphite[16428]: run: cron: (pid 58) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: down: go-carbon: 1s, normally up, want up
Oct 11 03:53:53 ubuntu graphite[16428]: run: graphite: (pid 70) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: run: nginx: (pid 63) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: down: redis: 1s, normally up, want up
Oct 11 03:53:53 ubuntu graphite[16428]: run: statsd: (pid 71) 5s; run: log: (pid 67) 5s

使用docker CLI列出正在运行的容器。

$ docker ps
CONTAINER ID        IMAGE                         COMMAND             CREATED              STATUS              PORTS                                                                                                                                                                       NAMES
e5647ba93e4d        graphiteapp/graphite-statsd   "/entrypoint"       About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, 0.0.0.0:2003-2004->2003-2004/tcp, 2013-2014/tcp, 8080/tcp, 0.0.0.0:2023-2024->2023-2024/tcp, 0.0.0.0:8126->8126/tcp, 8125/tcp, 0.0.0.0:8125->8125/udp   graphite

如果服务器已重新启动,请执行系统重新启动以验证容器已启动。

sudo reboot

您可以看到该容器以其他ID开头。

$ docker ps
CONTAINER ID        IMAGE                         COMMAND             CREATED              STATUS              PORTS                                                                                                                                                                       NAMES
11e596067be9        graphiteapp/graphite-statsd   "/entrypoint"       About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, 0.0.0.0:2003-2004->2003-2004/tcp, 2013-2014/tcp, 8080/tcp, 0.0.0.0:2023-2024->2023-2024/tcp, 0.0.0.0:8126->8126/tcp, 8125/tcp, 0.0.0.0:8125->8125/udp   graphite

通读 石墨文件 开始将指标从您的应用程序发送到Graphite。

Sidebar