docker安装和配置Grafana

安装

docker 启动

先普通启动,然后把配置文件导出来,修改配置文件,挂载到etc下

## 普通启动,挂载数据盘
docker run  -d --name grafana -p 3000:3000   -v /data/grafana:/var/lib/grafana  grafana/grafana

## 复制出配置文件
docker cp grafan:/etc/grafana/grafana.ini /data/grafana-data/etc/
## 修改配置文件,比如加上域名,比如修改端口为80,比如。。。


## kill重启
docker kill grafana
docker rm grafana
docker run --user root  -d --name grafana -p 3000:3000  -v /data/grafana-data/etc:/etc/grafana/ -v /data/grafana-data/grafana:/var/lib/grafana  grafana/grafana


docker run --user root  -d --name grafana -p 3000:3000  -v /data/opt/monitor/grafana-data/etc:/etc/grafana/ -v /data/opt/monitor/grafana-data/grafana:/var/lib/grafana  grafana/grafana

配置

配置域名和端口

作为一个公共服务,我们必然要给一个好记的域名。修改配置文件

# The http port  to use
http_port = 80

# The public facing domain name used to access grafana from a browser
domain = grafana.demo.com

修改端口了,则docker启动的端口映射也要改

docker run --user root  -d --name grafana -p 3000:80  -v /data/grafana-data/etc:/etc/grafana/ -v /data/grafana-data/grafana:/var/lib/grafana  grafana/grafana

配置ldap

作为一个公共服务,登录体系当然也要选择一个公共的方案。这里配置ldap。官方文档: http://docs.grafana.org/auth/ldap/

修改配置文件:

[auth.ldap]
enabled = true
config_file = /etc/grafana/ldap.toml
;allow_sign_up = true

docker启动的时候,我们已经把etc给挂载出来了,所以在宿主机对应的目录添加文件ldap.toml就可以了。

[[servers]]
# Ldap server host (specify multiple hosts space separated)
host = "10.0.101.66"
# Default port is 389 or 636 if use_ssl = true
port = 389
# Set to true if ldap server supports TLS
use_ssl = false
# Set to true if connect ldap server with STARTTLS pattern (create connection in insecure, then upgrade to secure connection with TLS)
start_tls = false
# set to true if you want to skip ssl cert validation
ssl_skip_verify = false
# set to the path to your root CA certificate or leave unset to use system defaults
# root_ca_cert = "/path/to/certificate.crt"
# Authentication against LDAP servers requiring client certificates
# client_cert = "/path/to/client.crt"
# client_key = "/path/to/client.key"

# Search user bind dn
bind_dn = "cn=admin,dc=yourdc,dc=com"
# Search user bind password
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
bind_password = 'admin'

# User search filter, for example "(cn=%s)" or "(sAMAccountName=%s)" or "(uid=%s)"
# Allow login from email or username, example "(|(sAMAccountName=%s)(userPrincipalName=%s))"
search_filter = "(sn=%s)"

# An array of base dns to search through
search_base_dns = ["dc=yourdc,dc=com"]

group_search_filter = "(&(objectClass=posixGroup)(memberUid=%s))"
group_search_filter_user_attribute = "dc=yourdc,dc=com"
group_search_base_dns = ["ou=groups,dc=grafana,dc=org"]

# Specify names of the ldap attributes your ldap uses
[servers.attributes]
name = "givenName"
surname = "sn"
username = "sn"
member_of = "memberOf"
email =  "mail"

配置邮箱

grafana提供了alert功能,但需要自己配置邮箱,比如腾讯邮箱,修改配置文件:

[smtp]
enabled = true
host = smtp.exmail.qq.com:465
user = 123456@qq.com
# If the password contains # or ; you have to wrap it with trippel quotes. Ex """#password;"""
password = 123456
;cert_file =
;key_file =
skip_verify = true
from_address = 123456@qq.com
from_name = Grafana
# EHLO identity in SMTP dialog (defaults to instance_name)
;ehlo_identity = dashboard.example.com

[emails]
;welcome_email_on_sign_up = false


添加数据源

创建dashboard

配置alert

posted @ 2019-06-20 20:10  Ryan.Miao  阅读(17490)  评论(0编辑  收藏  举报