更新时间:2022-12-29 16:01:15浏览次数:822+次
本文介绍使用Docker在Ubuntu 22.04上安装Graphite和Graphite Web的方法。因为当前在Ubuntu 22.04 Linux操作系统上运行Graphite最简单快捷的方法是使用Docker容器。
安装Graphite和Graphite Web的方法
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 gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg
将Docker CE存储库添加到Ubuntu机器:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
在Ubuntu 22.04/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 version
Client: Docker Engine - Community
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.6
GitCommit: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc:
Version: 1.1.2
GitCommit: v1.1.2-0-ga916309
docker-init:
Version: 0.19.0
GitCommit: de40ad0
确认服务正在运行,然后才能继续:
$ systemctl status docker
docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running)
3、在Docker Container中的Ubuntu 22.04上运行Graphite
一旦docker引擎安装并运行,是时候为Graphite和Statsd启动docker容器了。我们将使用Graphite的官方Docker repo协议,地址https://github.com/graphite-project/docker-graphite-statsd:
下载最新的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
在主机系统上创建持久数据存储的目录。这可以是专用于存储Graphite数据的磁盘或分区的装载点:
sudo mkdir -p /data/graphite/{data,logs,conf,statsd_config}
我们下载的图像包括以下组件:
Nginx–反向代理Graphite仪表板。
Graphite–前端仪表板。
Carbon–后端。
Statsd–基于UDP的后端代理。
映射的端口,如下图:
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='Asia/Shanghai' \
graphiteapp/graphite-statsd
列出正在运行的容器,以查看石墨容器是否正在运行:
$ docker ps
您可以流式传输日志以检查是否存在任何错误:
$ docker logs -f graphite
样本输出:
[tagdb] Tagged carbon.aggregator.4a26c4c0f746-a.destinations.127_0_0_1:2004:None.attemptedRelays, carbon.aggregator.4a26c4c0f746-a.bufferedDatapoints in 0.021245479583740234
[listener] MetricLineReceiver connection with 127.0.0.1:57472 established
[listener] MetricLineReceiver connection with 127.0.0.1:57472 closed cleanly
[tagdb] Tagging carbon.agents.4a26c4c0f746-a.errors
[tagdb] Tagged carbon.agents.4a26c4c0f746-a.errors in 0.15246272087097168
[listener] MetricLineReceiver connection with 127.0.0.1:57476 established
[listener] MetricLineReceiver connection with 127.0.0.1:57476 closed cleanly
[listener] MetricLineReceiver connection with 127.0.0.1:57478 established
[listener] MetricLineReceiver connection with 127.0.0.1:57478 closed cleanly
[tagdb] Tagging stats.statsd.graphiteStats.last_flush
[tagdb] Tagged stats.statsd.graphiteStats.last_flush in 0.013707160949707031
[listener] MetricLineReceiver connection with 127.0.0.1:57482 established
[listener] MetricLineReceiver connection with 127.0.0.1:57482 closed cleanly
[tagdb] Tagging stats.timers.view.graphite.tags.views.tagMultiSeries.POST.count_90
[tagdb] Tagged stats.timers.view.graphite.tags.views.tagMultiSeries.POST.count_90 in 0.011429786682128906
[listener] MetricLineReceiver connection with 127.0.0.1:57486 established
[listener] MetricLineReceiver connection with 127.0.0.1:57486 closed cleanly
[tagdb] Tagging carbon.aggregator.4a26c4c0f746-a.whitelistRejects
[tagdb] Tagged carbon.aggregator.4a26c4c0f746-a.whitelistRejects in 0.015319108963012695
[listener] MetricLineReceiver connection with 127.0.0.1:57490 established
[listener] MetricLineReceiver connection with 127.0.0.1:57490 closed cleanly
[tagdb] Tagging carbon.agents.4a26c4c0f746-a.memUsage
[tagdb] Tagged carbon.agents.4a26c4c0f746-a.memUsage in 0.009841442108154297
[listener] MetricLineReceiver connection with 127.0.0.1:57494 established
[listener] MetricLineReceiver connection with 127.0.0.1:57494 closed cleanly
[tagdb] Tagging carbon.agents.4a26c4c0f746-a.creates
[tagdb] Tagged carbon.agents.4a26c4c0f746-a.creates in 0.019759416580200195
默认情况下,statsd侦听UDP端口8125。如果您希望它监听TCP端口8125,则可以在运行容器时将环境变量STATSD_INTERFACE设置为TCP。
4、访问Graphite Web界面
可以使用服务器IP地址或端口号以及主机上映射到容器端口80的端口访问Graphite web控制台:
默认登录凭据为:
用户名:root
密码:root
在首次登录后更改此登录凭据,地址格式http://ip-address/admin/auth/user/1/,单击更改密码链接以启动root用户密码更改:
提供所需的新根密码并确认:
您现在可以注销并使用新密码返回。
5、使用Systemd管理Graphite Container
为了确保容器在系统启动时启动,让我们创建新的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
重新加载Systemd服务:
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
启动Systemd服务:
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)
使用docker CLI列出正在运行的容器:
$ docker ps
如果服务器重新启动,请执行系统重新启动以确保容器已启动:
sudo reboot
我们可以确认容器是用不同的ID启动的:
$ docker ps
至此,配置完成。
相关资讯