Grafana高可用-LDAP

在这里插入图片描述

一. grafana高可用

1. 迁移之前的 grafana

sqlitedump.sh

#!/bin/bash
DB=$1
TABLES=$(sqlite3 $DB .tables | sed -r 's/(\S+)\s+(\S)/\1\n\2/g' | grep -v migration_log)
for t in $TABLES; doecho "TRUNCATE TABLE $t;"
done
for t in $TABLES; doecho -e ".mode insert $t\nselect * from $t;"
done | sqlite3 $DB

将grafana.db 转为mysql的sql文件

  • 找到 grafana 的 grafana.db,得到sql文件,source到mysql上即可
sh sqlitedump grafana.db >grafana.sql

2. 部署

  • 将数据存储到 mysql

1) mysql

  • grafna会自己初始化库,前提是需要创建出来
apiVersion: apps/v1
kind: PersistentVolumeClaim
metadata:name: mysqlnamespace: monitor
spec:storageClassName: monitor-nfs-storageaccessModes:- ReadWriteManyresources:requests:storage: 10Gi
#apiVersion: v1
#kind: ConfigMap
#metadata:
#  name: my.cnf
#  namespace: monitor
#data:
#  my.cnf: |
#    [mysqld]
#    port=3306
#---
apiVersion: apps/v1
kind: Deployment
metadata:labels:app: mysqlname: mysqlnamespace: monitor
spec:selector:matchLabels:app: mysqltemplate:metadata:labels:app: mysqlspec:containers:- image: mysql:5.7name: mysqlenv:- name: MYSQL_ROOT_PASSWORDvalue: Man10f&3^H_98est$#valueFrom:#  secretKeyRef:#    name: mysql-root-password#    key: passwordports:- containerPort: 3306volumeMounts:- name: mysqlvolumemountPath: /var/lib/mysql#  - name: mysql-conf#    mountPath: /etc/mysql/my.cnf#    subPath: my.cnfvolumes:- name: mysqlvolumepersistentVolumeClaim:claimName: mysql#- name: mysql-conf#  configMap:#    name: my.cnf
---
apiVersion: v1
kind: Service
metadata:labels:app: mysqlname: mysqlnamespace: monitor
spec:selector:app: mysqltype: ClusterIPports:- port: 3306protocol: TCPtargetPort: 3306
mysql -h mysql -p
create database grafana;
use grafana;
CREATE USER 'grafana'@'%' IDENTIFIED BY 'Man10f&3^H_98est$';
GRANT all on *.* TO 'grafana'@'%';
# 导入数据
source /grafana.sql

2). grafna

  • 配置文件需要改为如下的,其他的配置自行添加上去,这里只是mysql的配置
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: grafananamespace: monitor#annotations:#volume.beta.kubernetes.io/storage-class: "nfs"
spec:storageClassName: monitor-nfs-storageaccessModes:- ReadWriteManyresources:requests:storage: 10Gi
kind: ConfigMap
apiVersion: v1
metadata:name: grafana-confignamespace: monitor
data:grafana.ini: | [database]type = mysqlhost = mysql.prometheus.svc.cluster.local:3306name = grafanauser = grafanapassword = Man10f&3^H_98est$[auth.ldap]enabled = trueconfig_file = /etc/grafana/ldap.toml[log]level = debug---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: grafananamespace: monitor
spec:rules:- host: grafana-panel.yee.comhttp:paths:- path: /pathType: Prefixbackend:service: name: grafanaport:number: 3000tls:- hosts:- grafana-panel.yee.comsecretName: 2022-yee.com
---
apiVersion: apps/v1
kind: Deployment
metadata:name: grafananamespace: monitor
spec:replicas: 2selector:matchLabels:app: grafanatemplate:metadata:labels:app: grafanaspec:securityContext:runAsUser: 0containers:- name: grafanaimage: harbor.yee.com:8443/library/grafana:8.5.0imagePullPolicy: IfNotPresentports:- containerPort: 3000name: grafanaenv:- name: GF_SECURITY_ADMIN_USERvalue: admin- name: GF_SECURITY_ADMIN_PASSWORDvalue: Manifest%0304readinessProbe:failureThreshold: 10httpGet:path: /api/healthport: 3000scheme: HTTPinitialDelaySeconds: 60periodSeconds: 10successThreshold: 1timeoutSeconds: 30livenessProbe:failureThreshold: 3httpGet:path: /api/healthport: 3000scheme: HTTPperiodSeconds: 10successThreshold: 1timeoutSeconds: 1resources:limits:cpu: 2memory: 2Girequests:cpu: 150mmemory: 512MivolumeMounts:- mountPath: /var/lib/grafananame: storage- mountPath: /etc/grafana/grafana.inisubPath: grafana.ininame: configvolumes:- name: storagepersistentVolumeClaim:claimName: grafana- name: configconfigMap:name: grafana-config---
apiVersion: v1
kind: Service
metadata:name: grafananamespace: monitor
spec:type: ClusterIPports:- port: 3000selector:app: grafana

3. LDAP

  • grafana 使用加域,使用域账号登录,需要配置LDAP,LDAP是一种通讯协议,如同HTTP是一种协议一样的,
  • 域控的dn, 在 LDAP 目录中:
    • DC (Domain Component)
    • CN (Common Name)
    • OU (Organizational Unit)
  • An LDAP 目录类似于文件系统目录. 下列目录: DC=redmond,DC=wa,DC=microsoft,DC=com,如果我们类比文件系统的话,可被看作如下文件路径: Com\Microsoft\Wa\Redmond
  • 例如:cn=test 可能代表一个用户名, ou=developer 代表一个active directory中的 组织单位。这句话的含义可能就是说明test这个对象处在domainname. com域的developer组织单元中
kind: ConfigMap
apiVersion: v1
metadata:name: grafana-confignamespace: prometheus
data:grafana.ini: | [database]type = mysqlhost = mysql.prometheus.svc.cluster.local:3306name = grafanauser = grafanapassword = Man10f&3^H_98est$[auth.ldap]enabled = trueconfig_file = /etc/grafana/ldap.toml[log]level = info
---
kind: ConfigMap
apiVersion: v1
metadata:name: grafana-ldapnamespace: prometheus
data:ldap.toml: |# To troubleshoot and get more log info enable ldap debug logging in grafana.ini# [log]# filters = ldap:debug[[servers]]# Ldap server host (specify multiple hosts space separated)host = "192.168.1.250"# Default port is 389 or 636 if use_ssl = trueport = 389# Set to true if LDAP server should use an encrypted TLS connection (either with STARTTLS or LDAPS)use_ssl = false# If set to true, use LDAP with STARTTLS instead of LDAPSstart_tls = false# set to true if you want to skip ssl cert validationssl_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=xingguang,OU=运维组,OU=研发中心,OU=ooo,DC=SDRAD,DC=COM"bind_dn = "ooo"		# 根据自己的写# Search user bind password# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""bind_password = 'dfs@52%2(89!ykWc'# User search filter, for example "(cn=%s)" or "(sAMAccountName=%s)" or "(uid=%s)"#search_filter = "(&(objectCategory=person)(objectClass=user)(!(userAccountControl=514))(name=*))"search_filter = "(sAMAccountName=%s)"#search_filter = "(&(objectCategory=person)(objectClass=user)(!(userAccountControl=514))(sAMAccountName={login}))"# An array of base dns to search throughsearch_base_dns = ["OU=ooo,DC=sdrad,DC=com"]## For Posix or LDAP setups that does not support member_of attribute you can define the below settings## Please check grafana LDAP docs for examples# group_search_filter = "(&(objectClass=posixGroup)(memberUid=%s))"# group_search_base_dns = ["ou=groups,dc=grafana,dc=org"]# group_search_filter_user_attribute = "uid"# Specify names of the ldap attributes your ldap uses[servers.attributes]name = "displayName"#surname = "sn"#username = "username"username = "sAMAccountName"#member_of = "memberOf"email =  "mail"# Map ldap groups to grafana org roles[[servers.group_mappings]]group_dn = "CN=xxx,OU=运维组,OU=研发中心,OU=ooo,DC=SDRAD,DC=COM"org_role = "Admin"# To make user an instance admin  (Grafana Admin) uncomment line belowgrafana_admin = true# The Grafana organization database id, optional, if left out the default org (id 1) will be used#org_id = 1[[servers.group_mappings]]group_dn = "CN=xxx,OU=运维组,OU=研发中心,OU=ooo,DC=SDRAD,DC=COM"org_role = "Editor"#org_id = 2#[[servers.group_mappings]]## If you want to match all (or no ldap groups) then you can use wildcardgroup_dn = "*"org_role = "Viewer"#org_id = 3
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: grafananamespace: prometheus
spec:rules:- host: grafana-test.yee.net.cnhttp:paths:- path: /pathType: Prefixbackend:service: name: grafanaport:number: 3000tls:- hosts:- grafana-test.yee.net.cnsecretName: yee.net.cn
---
apiVersion: apps/v1
kind: Deployment
metadata:name: grafananamespace: prometheus
spec:replicas: 2selector:matchLabels:app: grafanatemplate:metadata:labels:app: grafanaspec:nodeSelector:ldap: "true"securityContext:runAsUser: 0containers:- name: grafanaimage: harbor.yee.net.cn/library/grafana:8.5.0imagePullPolicy: IfNotPresentports:- containerPort: 3000name: grafanaenv:- name: GF_SECURITY_ADMIN_USERvalue: admin- name: GF_SECURITY_ADMIN_PASSWORDvalue: Manifest%0304OURreadinessProbe:failureThreshold: 10httpGet:path: /api/healthport: 3000scheme: HTTPinitialDelaySeconds: 60periodSeconds: 10successThreshold: 1timeoutSeconds: 30livenessProbe:failureThreshold: 3httpGet:path: /api/healthport: 3000scheme: HTTPperiodSeconds: 10successThreshold: 1timeoutSeconds: 1resources:limits:cpu: 2memory: 2Girequests:cpu: 150mmemory: 512MivolumeMounts:- mountPath: /var/lib/grafananame: storage- mountPath: /etc/grafana/grafana.inisubPath: grafana.ininame: config- mountPath: /etc/grafana/ldap.tomlsubPath: ldap.tomlname: ldapvolumes:- name: storagepersistentVolumeClaim:claimName: grafana- name: configconfigMap:name: grafana-config- name: ldapconfigMap:name: grafana-ldap---
apiVersion: v1
kind: Service
metadata:name: grafananamespace: prometheus
spec:type: ClusterIPports:- port: 3000selector:app: grafana

同样 Deployment 需要加一些配置

        volumeMounts:- mountPath: /var/lib/grafananame: storage- mountPath: /etc/grafana/grafana.inisubPath: grafana.ininame: config- mountPath: /etc/grafana/ldap.tomlsubPath: ldap.tomlname: ldapvolumes:- name: storagepersistentVolumeClaim:claimName: grafana- name: configconfigMap:name: grafana-config- name: ldapconfigMap:name: grafana-ldap

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/294184.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Python量化投资——金融数据最佳实践: 使用qteasy+tushare搭建本地金融数据仓库并定期批量更新【附源码】

用qteasytushare实现金融数据本地化存储及访问 目的什么是qteasy什么是tushare为什么要本地化使用qteasy创建本地数据仓库qteasy支持的几种本地化仓库类型配置本地数据仓库配置tushare 的API token 配置本地数据源 —— 用MySQL数据库作为本地数据源下载金融历史数据 数据的定期…

Pipelined-ADC设计二——结构指标及非理想因素(Part1)

本章将详细介绍电路各个模块的设计思路和设计中需要注意的关键点,给出流水线ADC中的非理想因素,并计算出流水线ADC各个模块具体指标。根据电路中信号的传输方向,依次介绍采样保持电路、Sub_ADC,MDAC 等模块的设计。(本…

80x86汇编—寻址方式

文章目录 术语解释8086寻址方式直数寻址寄存器间接寻址寄存器相对寻址基址变址寻址比例变址寻址方式基址比例变址寻址方式 术语解释 EA:有效地址,通过段地址:偏移地址组合得到的Effect Address 位移量:一般是常量和标号&#xff…

【Amazon 实验③】验证源请求策略将特定的请求信息转发至源站

文章目录 1. 使用源请求策略1.1 什么是源请求策略1.2 源请求策略和缓存策略的关系 2. 实验:验证源请求策略将特定的请求信息转发至源站 接上一篇文章【Amazon 实验②】使用缓存策略及源请求策略,用于控制边缘缓存的行为及回源行为,本篇文章主…

<软考高项备考>《论文专题 - 23 整合管理(1) 》

1 论文基础情况 1.1 各过程写作要点 过程定义、作用写作要点、思路制定项目章程制定项目章程是编写一份正式批准项目并授权项目经理在项目活动中使用组织资源的文件的过程。作用:①明确项目与组织战略目标之间的直接联系;②确立项目的正式地位;③展示组织对项目的…

MsSQL中的索引到底长啥样,查找过程怎么进行

参考文章一 参考文章二 建表 mysql> create table user(-> id int(10) auto_increment,-> name varchar(30),-> age tinyint(4),-> primary key (id),-> index idx_age (age)-> )engineinnodb charsetutf8mb4;insert into user(name,age) values(张三,…

天猫数据分析(软件工具)-2023年11月天猫保健品行业分析报告:市场需求扩容,年轻人是主流群体

近年来,随着健康经济、颜值经济的兴起,越来越多的年轻人加入养生大军,成为保健食品市场上的一股新力量,带动市场扩容。根据鲸参谋电商数据分析平台的相关数据显示,今年11月份,天猫平台上保健食品的销量为24…

P1883 函数

题目链接 P1883 函数 思路 举例 题目中的 F ( x ) F(x) F(x) 看起来很复杂,但由于每个 f ( x ) f(x) f(x) 的二次项系数 a a a 都不是负数,故 F ( x ) F(x) F(x) 是一个单谷函数。直接说出结论可能有些令人难以接受,不妨举出两个例子…

文档 - - - Docsify文档创建

目录 1. Docsify 介绍2. 创建 Docsify 项目2.1 安装 Node.js2.1 安装 docsfiy-cli2.3 初始化项目2.4 运行项目2.5 使用 Python 运行项目(扩展,不推荐有bug) 3. 配置 Docsify 项目3.1 修改等待加载文字3.2 添加网站 ico 图标3.3 创建新页面写文…

编译原理----算符优先级的分析(自底向上)

自底向上分析的分类如下所示: 算符优先分析 算符优先分析只规定算符之间的优先关系,也就是只考虑终结符之间的优先关系。 (一)若有文法G,如果G没有形如A->..BC..的产生式,其中B和C为非终结符&#xff…

Milvus数据一致性介绍及选择方法

1、Milvus 时钟机制 Milvus 通过时间戳水印来保障读链路的一致性,如下图所示,在往消息队列插入数据时, Milvus 不光会为这些插入记录打上时间戳,还会不间断地插入同步时间戳,以图中同步时间戳 syncTs1 为例&#xff0…

CGAL的2D和曲面插值函数

了解函数使用,对数学原理不一定要懂, 这个软件包实现了各种邻居坐标计算函数以及用于散乱数据插值的不同方法。 在2D欧几里得空间中,自然和常规邻居坐标的计算在“自然邻居坐标”一节中描述。 在表面上的坐标和邻居计算在“表面自然邻居坐标和…