Grafana配置详解
本文摘要介绍了Grafana配置文件中的关键配置项,主要包括: 路径设置:包括数据、日志、插件和配置文件的存储路径; 服务器配置:协议、端口、域名、TLS等网络相关设置; 数据库连接:支持多种数据库类型及连接参数配置; 安全设置:管理员账户、加密、Cookie安全、内容安全策略等; 认证配置:登录设置、OAuth集成、匿名访问等。 这些配置项涵盖了Grafana的核心功能模块,包括数据存储、网络服
[paths]部分
-
data:指定Grafana存储临时文件、会话和SQLite数据库(如果使用)的路径,例如data = /var/lib/grafana。
-
temp_data_lifetime:设置data目录中临时文件的过期时间,超过该时间的文件将被删除,如temp_data_lifetime = 24h表示24小时。
-
logs:定义Grafana存储日志的目录,如logs = /var/log/grafana。
-
plugins:指定Grafana自动扫描和查找插件的目录,如plugins = /var/lib/grafana/plugins。
-
provisioning:设置包含配置文件的文件夹路径,Grafana在启动和运行时将应用这些配置,如provisioning = conf/provisioning。
[server]部分
-
protocol:定义Grafana使用的协议,如http、https、h2或socket,如protocol = http。
-
min_tls_version:指定允许的最低TLS版本,如min_tls_version = "TLS1.2"。
-
http_addr:绑定的IP地址,空值表示绑定到所有接口,如http_addr =。
-
http_port:使用的HTTP端口,如http_port = 3000。
-
domain:用于从浏览器访问Grafana的公共域名,如domain = localhost。
-
enforce_domain:如果主机头与域名不匹配,是否重定向到正确的域名,防止DNS重绑定攻击,如enforce_domain = false。
-
root_url:在浏览器中使用的完整公共URL,用于重定向和电子邮件,如root_url = %(protocol)s://%(domain)s:%(http_port)s/。
-
serve_from_sub_path:是否从root_url设置中指定的子路径提供Grafana服务,如serve_from_sub_path = false。
-
router_logging:是否记录Web请求,如router_logging = false。
-
static_root_path:相对工作路径,如static_root_path = public。
-
enable_gzip:是否启用gzip压缩,如enable_gzip = false。
-
cert_file和cert_key:用于HTTPS的证书和密钥文件路径,如cert_file =和cert_key =。
-
cert_pass:解密密钥文件的可选密码,如cert_pass =。
-
certs_watch_interval:证书文件的监视间隔,如certs_watch_interval =。
-
socket_gid:Unix套接字的组ID,如socket_gid =。
-
socket_mode:Unix套接字的模式,如socket_mode =。
-
socket:Unix套接字路径,如socket =。
-
cdn_url:CDN URL,如cdn_url =。
-
read_timeout:设置读取传入请求的超时时间,如read_timeout = 0表示无超时。
[database]部分
-
type:选择数据库类型,如sqlite3、mysql或postgres,如type = sqlite3。
-
host、name、user和password:分别是数据库服务器主机地址、数据库名称、用户名和密码,用于配置数据库连接,如host = 127.0.0.1:3306、name = grafana、user = root、password =。
-
url:使用URL配置数据库连接的替代方式,如url = mysql://user:secret@host:port/database。
-
max_idle_conn:最大空闲连接数,默认值为2,如max_idle_conn = 2。
-
max_open_conn:最大打开连接数,默认值为0(未设置),如max_open_conn =。
-
conn_max_lifetime:连接的最大生存时间,默认14400秒(4小时),如conn_max_lifetime = 14400。
-
log_queries:是否记录SQL调用和执行时间,如log_queries =。
-
ssl_mode:对于postgres,使用disable、require或verifyfull;对于mysql,使用true、false或skipverify,如ssl_mode = disable。
-
ssl_sni:对于postgres,设置为1启用或0禁用SNI,如ssl_sni =。
-
isolation_level:数据库驱动支持的事务隔离级别,如isolation_level =。
-
ca_cert_path、client_key_path和client_cert_path:与SSL/TLS相关的证书路径,如ca_cert_path =、client_key_path =、client_cert_path =。
-
server_cert_name:服务器证书名称,如server_cert_name =。
-
path(仅适用于sqlite3):相对于data_path设置的数据库文件路径,如path = grafana.db。
-
cache_mode(仅适用于sqlite3):数据库连接的缓存模式,如cache_mode = private。
-
wal(仅适用于sqlite3):启用/禁用预写日志,如wal = false。
-
migration_locking(仅适用于mysql和postgres):在迁移时是否锁定数据库,默认值为true,如migration_locking = true。
-
locking_attempt_timeout_sec(仅适用于mysql和postgres):迁移时锁定数据库失败前的等待时间,默认值为0,如locking_attempt_timeout_sec = 0。
-
query_retries(仅适用于sqlite):数据库锁定失败时查询的重试次数,默认值为0(禁用),如query_retries = 0。
-
transaction_retries(仅适用于sqlite):数据库锁定失败时事务的重试次数,默认值为5,如transaction_retries = 5。
-
instrument_queries:是否为数据库查询添加指标和跟踪,如instrument_queries = false。
[security]部分
-
disable_initial_admin_creation:是否在Grafana首次启动时禁用创建管理员用户,如disable_initial_admin_creation = false。
-
admin_user和admin_password:默认管理员用户和密码,如admin_user = admin、admin_password = admin。
-
admin_email:默认管理员电子邮件,如admin_email = admin@localhost。
-
secret_key:用于签名的密钥,如secret_key = SW2YcwTIb9zpOOhoPsMm。
-
encryption_provider:当前用于信封加密的密钥提供程序,默认值为secretKey.v1,如encryption_provider = secretKey.v1。
-
available_encryption_providers:配置的密钥提供程序列表,如available_encryption_providers =。
-
disable_gravatar:是否禁用Gravatar个人资料图片,如disable_gravatar = false。
-
data_source_proxy_whitelist:数据源代理白名单,如data_source_proxy_whitelist =。
-
disable_brute_force_login_protection:是否禁用暴力登录保护,如disable_brute_force_login_protection = false。
-
cookie_secure:如果在HTTPS后面托管Grafana,是否设置为true,默认值为false,如cookie_secure = false。
-
cookie_samesite:设置Cookie的SameSite属性,如cookie_samesite = lax。
-
allow_embedding:是否允许浏览器在<frame>、<iframe>、<embed>或<object>中渲染Grafana,默认值为false,如allow_embedding = false。
-
strict_transport_security:是否启用HTTP严格传输安全(HSTS)响应头,如strict_transport_security = false。
-
strict_transport_security_max_age_seconds:设置浏览器应缓存HSTS的时间,仅在strict_transport_security启用时应用,如strict_transport_security_max_age_seconds = 86400。
-
strict_transport_security_preload:是否启用HSTS预加载选项,仅在strict_transport_security启用时应用,如strict_transport_security_preload = false。
-
strict_transport_security_subdomains:是否启用HSTS的includeSubDomains选项,仅在strict_transport_security启用时应用,如strict_transport_security_subdomains = false。
-
x_content_type_options:是否启用X Content Type Options响应头,如x_content_type_options = true。
-
x_xss_protection:是否启用X XSS Protection头,如x_xss_protection = true。
-
content_security_policy:是否启用添加Content Security Policy头,如content_security_policy = false。
-
content_security_policy_template:设置Content Security Policy头的模板,如content_security_policy_template = """scriptsrc'self''unsafeeval''unsafeinline''strictdynamic' $NONCE;objectsrc 'none';fontsrc'self';stylesrc'self''unsafeinline' blob:;imgsrc * data:;baseuri'self';connectsrc'self' grafana.com ws://$ROOT_PATH wss://$ROOT_PATH;manifestsrc'self';mediasrc 'none';formaction'self';"""。
-
content_security_policy_report_only:是否启用添加Content Security Policy Report Only头,如content_security_policy_report_only = false。
-
content_security_policy_report_only_template:设置Content Security Policy Report Only头的模板,如content_security_policy_report_only_template = """scriptsrc'self''unsafeeval''unsafeinline''strictdynamic' $NONCE;objectsrc 'none';fontsrc'self';stylesrc'self''unsafeinline' blob:;imgsrc * data:;baseuri'self';connectsrc'self' grafana.com ws://$ROOT_PATH wss://$ROOT_PATH;manifestsrc'self';mediasrc 'none';formaction'self';"""。
-
angular_support_enabled:是否支持旧的Angular插件,如angular_support_enabled = false。
-
csrf_trusted_origins:CSRF检查信任的额外URL列表,如csrf_trusted_origins = example.com。
-
csrf_additional_headers:用户可以设置的允许的额外头部列表,如csrf_additional_headers =。
-
csrf_always_check:即使请求没有登录Cookie,是否执行CSRF检查,如csrf_always_check = false。
-
disable_frontend_sandbox_for_plugins:逗号分隔的插件ID列表,这些插件将不在前端沙箱中加载,如disable_frontend_sandbox_for_plugins =。
-
actions_allow_post_url:POST/PUT URL操作的允许路径列表,空值表示允许任何不在同一源的内容,如actions_allow_post_url =。
[auth]部分
-
login_cookie_name:登录Cookie的名称,如login_cookie_name = grafana_session。
-
disable_login:是否禁用Grafana内置的登录解决方案,如disable_login = false。
-
login_maximum_inactive_lifetime_duration:经过多长时间无活动后,用户需要重新登录,默认值为7天,如login_maximum_inactive_lifetime_duration =。
-
login_maximum_lifetime_duration:用户登录后多长时间需要重新登录,默认值为30天,如login_maximum_lifetime_duration =。
-
token_rotation_interval_minutes:认证用户活动时令牌应多久轮换一次,默认值为10分钟,如token_rotation_interval_minutes = 10。
-
disable_login_form:是否隐藏登录表单,在使用OAuth时有用,默认值为false,如disable_login_form = false。
-
disable_signout_menu:是否禁用侧边菜单中的注销链接,在使用auth.proxy或auth.jwt时有用,默认值为false,如disable_signout_menu = false。
-
signout_redirect_url:注销后重定向的URL,如signout_redirect_url =。
-
oauth_auto_login:是否自动尝试使用OAuth登录,跳过登录屏幕,如oauth_auto_login = false。
-
oauth_login_error_message:设置自定义的OAuth错误消息,如oauth_login_error_message = oauth.login.error。
-
oauth_state_cookie_max_age:OAuth状态Cookie的最大年龄(秒),默认值为600秒,如oauth_state_cookie_max_age = 600。
-
oauth_refresh_token_server_lock_min_wait_ms:服务器锁重试机制的最小等待时间(毫秒),用于防止多个Grafana实例同时刷新OAuth令牌,如oauth_refresh_token_server_lock_min_wait_ms = 1000。
-
api_key_max_seconds_to_live:API密钥的最大生存时间(秒),1表示无限制,如api_key_max_seconds_to_live = 1。
-
sigv4_auth_enabled:是否启用基于HTTP的数据源的SigV4身份验证选项,如sigv4_auth_enabled = false。
-
sigv4_verbose_logging:是否启用SigV4请求签名的详细日志记录,如sigv4_verbose_logging = false。
-
azure_auth_enabled:是否启用基于HTTP的数据源的Azure身份验证选项,如azure_auth_enabled = false。
-
oauth_allow_insecure_email_lookup:是否使用电子邮件查找以及IdP提供的唯一ID,如oauth_allow_insecure_email_lookup = false。
-
id_response_header_enabled:是否在响应头中包含身份ID,如id_response_header_enabled = false。
-
id_response_header_prefix:身份响应头的前缀,如id_response_header_prefix = X Grafana。
-
id_response_header_namespaces:要添加身份响应头的命名空间列表,如id_response_header_namespaces = user api key service account。
-
managed_service_accounts_enabled:是否启用托管服务账户用于插件身份验证,当前仅支持单组织部署,如managed_service_accounts_enabled = false。
-
### [auth.anonymous]部分
-
enabled:是否启用匿名访问,如enabled = false。
-
org_name:指定匿名用户使用的组织名称,如org_name = Main Org.。
-
org_role:指定匿名用户的角色,如org_role = Viewer。
-
hide_version:是否对匿名用户隐藏Grafana版本号,如hide_version = false。
-
device_limit:设备数量限制,如device_limit =。
[auth.github]、[auth.gitlab]
这些部分用于配置不同的认证提供程序,如GitHub、GitLab、Google等。以下是一些常见字段的含义:
-
name:认证提供程序的名称,如name = GitHub。
-
icon:在登录界面显示的图标,如icon = github。
-
enabled:是否启用该认证提供程序,如enabled = false。
-
allow_sign_up:是否允许通过该认证提供程序进行注册,如allow_sign_up = true。
-
auto_login:是否自动登录,如auto_login = false。
-
client_id和client_secret:与认证提供程序相关的客户端ID和客户端密钥,如client_id = some_id、client_secret = some_secret。
-
scopes:请求的权限范围,如scopes = user:email,read:org。
-
auth_url、token_url和api_url:认证、获取令牌和获取用户信息的URL,如auth_url = https://github.com/login/oauth/authorize、token_url = https://github.com/login/oauth/access_token、api_url = https://api.github.com/user。
-
signout_redirect_url:注销后的重定向URL,如signout_redirect_url =。
-
allowed_domains:允许的域名列表,如allowed_domains =。
-
team_ids和allowed_groups:允许的团队ID和组,用于限制访问,如team_ids =、allowed_groups =。
-
role_attribute_path和role_attribute_strict:用于确定用户角色的属性路径和是否严格匹配,如role_attribute_path =、role_attribute_strict = false。
-
org_mapping:组织映射,用于将外部组织与Grafana组织关联,如org_mapping =。
-
allow_assign_grafana_admin:是否允许分配Grafana管理员角色,如allow_assign_grafana_admin = false。
-
skip_org_role_sync:是否跳过组织角色同步,如skip_org_role_sync = false。
-
tls_skip_verify_insecure:是否
openEuler 是由开放原子开源基金会孵化的全场景开源操作系统项目,面向数字基础设施四大核心场景(服务器、云计算、边缘计算、嵌入式),全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构
更多推荐


所有评论(0)