docker安装Grafana

2022-10-27 13:39:46 浏览数 (3)

# 1.获取下载镜像

代码语言:javascript复制
[root@smartops43 grafana]# docker run -d -p 3000:3000 --name=grafana -v /home/summer/grafana:/var/lib/grafana grafana/grafana
Unable to find image 'grafana/grafana:latest' locally
latest: Pulling from grafana/grafana
188c0c94c7c5: Pull complete 
de79f55c0b0f: Pull complete 
a1b840f120d9: Pull complete 
b46b3ffb9b7d: Pull complete 
f04fb38cc8ac: Pull complete 
4f4fb700ef54: Pull complete 
4abcddc85579: Pull complete 
5059d9c487b2: Pull complete 
Digest: sha256:6d42886b3ebe286b92eca592e1251b5dc128e611678ccffbefb5701bbf7ef186
Status: Downloaded newer image for grafana/grafana:latest
0948b47dd4370ec6f546c34e82db1987cc0e6677e448e0a6fa2abd8a90960972

# 2.解决报错

代码语言:javascript复制
[root@smartops43 grafana]# docker log 0948b47dd437
docker: 'log' is not a docker command.
See 'docker --help'
[root@smartops43 grafana]# docker logs 0948b47dd437
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migration-from-a-previous-version-of-the-docker-container-to-5-1-or-later
[root@smartops43 grafana]# ll
total 0
[root@smartops43 grafana]# chmod 777 /home/summer/grafana/
[root@smartops43 grafana]# docker restart 0948b47dd437
0948b47dd437
[root@smartops43 grafana]# docker ps
CONTAINER ID        IMAGE                                  COMMAND                  CREATED              STATUS              PORTS                            NAMES
0948b47dd437        grafana/grafana                        "/run.sh"                About a minute ago   Up 4 seconds        0.0.0.0:3000->3000/tcp           grafana

# 3.验证

  • IP:3000
  • 默认用户名密码为:admin/admin
  • 第一次登陆的时候,会被要求需要修改密码

# 4.整合zabbix

  • 下载zabbix插件
代码语言:javascript复制
[root@smartops43 conf]# docker exec -it 0948b47dd437 /bin/bash
bash-5.0$ grafana-cli plugins install alexanderzobnin-zabbix-app
installing alexanderzobnin-zabbix-app @ 4.0.2
from: https://grafana.com/api/plugins/alexanderzobnin-zabbix-app/versions/4.0.2/download
into: /var/lib/grafana/plugins

✔ Installed alexanderzobnin-zabbix-app successfully 

Restart grafana after installing plugins . <service grafana-server restart>

bash-5.0$ 
  • 重启grafana容器
  • 此时可看到zabbix的插件已成功安装
  • 配置zabbix数据源

# 5.备份

  • Zabbix 使用如下命令将Zabbix的数据库进行备份,备份为sql文件,自行保存到其他服务器。然后添加到Crontab中。
代码语言:javascript复制
docker exec zabbix-mysql mysqldump -uroot -pmysql57 zabbix > zabbix.sql
scp zabbix.sql 192.168.0.1:/root

恢复

代码语言:javascript复制
docker cp zabbix.sql zabbix-mysql:/tmp/
docker exec zabbix-mysql mysql -uroot -pmysql57 zabbix -e "source /tmp/zabbix.sql"
  • Grafana 备份
代码语言:javascript复制
docker cp grafana:/var/lib/grafana/grafana.db ./
scp grafana.db 192.168.0.0.1:/root

恢复

代码语言:javascript复制
docker cp grafana.db grafana:/var/lib/grafana/grafana.db
docker restart grafana

# 简单展示

0 人点赞