prometheus之influxdb1.8部署
k8s部署prometheus持久化存储influxdb
·
创建configmap.yaml文件
apiVersion: v1
data:
influxdb.conf: |
#禁用用户报告
reporting-disabled = true
bind-address = "127.0.0.1:8088"
[meta]
dir = "/var/lib/influxdb/meta"
retention-autocreate = true
logging-enabled = true
[data]
dir = "/var/lib/influxdb/data"
#要启用基于时间序列索引(TSI)磁盘的索引,请将其值设置为tsi1
index-version = "tsi1"
wal-dir = "/var/lib/influxdb/wal"
wal-fsync-delay = "0s"
validate-keys = false
strict-error-handling = false
query-log-enabled = true # 是否开启tsm引擎查询日志,默认值: true
# 用于限定shard最大值,大于该值时会拒绝写入,默认值:1000MB,单位:byte
cache-max-memory-size = "1g"
# 用于设置快照大小,大于该值时数据会刷新到tsm文件,默认值:25MB,单位:byte
cache-snapshot-memory-size = "25m"
# tsm引擎 snapshot写盘延迟,默认值:10Minute
cache-snapshot-write-cold-duration = "10m0s"
# tsm文件在压缩前可以存储的最大时间,默认值:4Hour
compact-full-write-cold-duration = "4h0m0s"
compact-throughput = 50331648
compact-throughput-burst = 50331648
# 限制数据库的级数,该值为0时取消限制,默认值:1000000
max-series-per-database = 0
# 一个tag最大的value数,0取消限制,默认值:100000
max-values-per-tag = 0
max-concurrent-compactions = 0
max-index-log-file-size = "1g" #索引预写日志(WAL)文件将压缩为索引文件时的阈值
series-id-set-cache-size = 100
series-file-max-concurrent-snapshot-compactions = 0
trace-logging-enabled = false
tsm-use-madv-willneed = false
[coordinator]
write-timeout = "10s" #写操作超时时间
max-concurrent-queries = 0 #最大并发查询数
query-timeout = "60s" #查询操作超时时间
log-queries-after = "0s" #慢查询超时时间
max-select-point = 0 #select语句可以处理的最大点数,默认值1000000
max-select-series = 0 #select语句可以处理的最大级数,默认值1000000
max-select-buckets = 0 #select语句可以处理的最大"GROUP BY time()"的时间周期
[retention]
enabled = true
check-interval = "30m0s"
[shard-precreation]
enabled = true
check-interval = "10m0s"
advance-period = "30m0s"
[monitor]
store-enabled = false #是否开启监控模块,默认为true
store-database = "_internal"
store-interval = "10s"
[subscriber]
enabled = true
http-timeout = "30s"
insecure-skip-verify = false
ca-certs = ""
write-concurrency = 40
write-buffer-size = 1000
[http]
enabled = true
bind-address = ":8086"
auth-enabled = false
log-enabled = true
suppress-write-log = false
write-tracing = false
flux-enabled = false
flux-log-enabled = false
pprof-enabled = true
pprof-auth-enabled = false
debug-pprof-enabled = false
ping-auth-enabled = false
prom-read-auth-enabled = false
https-enabled = false
https-certificate = "/etc/ssl/influxdb.pem"
https-private-key = ""
max-row-limit = 10000 #系统在非分块查询中可以返回的最大行数。 默认设置(0)允许无限制的行数
max-connection-limit = 0
shared-secret = ""
realm = "InfluxDB"
unix-socket-enabled = false
unix-socket-permissions = "0777"
bind-socket = "/var/run/influxdb.sock"
max-body-size = 25000000
access-log-path = ""
max-concurrent-write-limit = 0
max-enqueued-write-limit = 0
enqueued-write-timeout = 30000000000
[logging]
format = "auto"
level = "info"
suppress-logo = false
[[graphite]]
enabled = false
bind-address = ":2003"
database = "graphite"
retention-policy = ""
protocol = "tcp"
batch-size = 5000
batch-pending = 10
batch-timeout = "1s"
consistency-level = "one"
separator = "."
udp-read-buffer = 0
[[collectd]]
enabled = false
bind-address = ":25826"
database = "collectd"
retention-policy = ""
batch-size = 5000
batch-pending = 10
batch-timeout = "10s"
read-buffer = 0
typesdb = "/usr/share/collectd/types.db"
security-level = "none"
auth-file = "/etc/collectd/auth_file"
parse-multivalue-plugin = "split"
[[opentsdb]]
enabled = false
bind-address = ":4242"
database = "opentsdb"
retention-policy = ""
consistency-level = "one"
tls-enabled = false
certificate = "/etc/ssl/influxdb.pem"
batch-size = 1000
batch-pending = 5
batch-timeout = "1s"
log-point-errors = true
[[udp]]
enabled = false
bind-address = ":8089"
database = "udp"
retention-policy = ""
batch-size = 5000
batch-pending = 10
read-buffer = 0
batch-timeout = "1s"
precision = ""
[continuous_queries]
log-enabled = true
enabled = true
query-stats-enabled = false
run-interval = "1s"
[tls]
min-version = ""
max-version = ""
kind: ConfigMap
metadata:
name: influxdb-conf
namespace: shuan-influxdb
创建statefulset.yaml文件
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: influxdb #设置StatefulSet标签
name: influxdb #设置StatefulSet名称
namespace: monitoring #设置名称空间
spec:
serviceName: influxdb #关联无状态服务的服务名
replicas: 1 #定义容器副本数
selector: #标签选择器,与template的标签保持一致,代表管理控制该标签的pod容器
matchLabels:
app: influxdb
template: #定义pod参数
metadata:
labels:
app: influxdb #定义pod标签
spec:
volumes: #定义目录挂载
- name: host-time #挂载宿主机的时间文件
hostPath:
path: /etc/localtime
- name: influxdb-conf #挂载configMap配置文件
configMap:
name: influxdb-conf
defaultMode: 0777 #设置挂载后的文件权限
imagePullSecrets: #设置镜像拉取的秘钥,若未设置则拉取镜像失败
- name: shu-cn
containers: #定义容器参数
- image: xxx.cn/influxdb:1.8 #设置容器的运行镜像,修改为自己的私人镜像仓库或官方1.8镜像
name: influxdb
imagePullPolicy: IfNotPresent #设置容器镜像的拉取策略,IfNotPresent:不存在则拉取,Always:每次拉取
resources: #定义容器的资源
requests: #设置容器的最小启动资源CPU与memory
cpu: 500m
memory: 1G
limits: #设置容器的最大使用资源,超过该资源限制则会强制重启
cpu: 1000m
memory: 4G
ports: #定义容器开放的端口
- containerPort: 8086
name: tcp
volumeMounts: #定义挂载到容器内部的位置
- name: host-time #将host-time的volume挂载为容器内部的/etc/localtime,name字段的值要与volumes定义的一致
mountPath: /etc/localtime
- name: influxdb-conf #将influxdb-conf的volume挂载为容器内部的/etc/influxdb/influxdb.conf,name字段的值要与volumes定义的一致
mountPath: /etc/influxdb/influxdb.conf
subPath: influxdb.conf #设置挂载为单个文件,不设置将清空/etc/influxdb/目录挂载,该目录下的其他文件将被覆盖
- name: data #这里是持久化存储,所以名称与下面定义的持久化存储的名称一致
mountPath: /var/lib/influxdb
volumeClaimTemplates: #定义pvc,持久化存储
- metadata:
name: data #设置持久化名称,挂载时需要使用
spec:
storageClassName: "nfs" #设置持久化存储的类型,这里用的是nfs,所以设置为nfs存储类的名称
accessModes:
- ReadWriteOnce #设置该pvc的接入模式为单节点读写,具体与存储类的设置有关
resources:
requests:
storage: 50Gi #设置该pvc的大小为50G
---
apiVersion: v1
kind: Service
metadata:
labels:
app: svc-influxdb #设置service的标签
name: svc-influxdb #设置service的名称
namespace: monitoring #设置service所在的名称空间
spec:
selector:
app: influxdb #设置该service指向具有该标签的pod,与statefulset中pod的标签一致
type: NodePort #设置该服务为NodePort,将service端口映射为宿主机端口供外部访问
ports:
- port: 8086 #service暴露的端口
protocol: TCP #协议类型为tcp
targetPort: 8086 #service指向的pod暴露的端口
nodePort: 38086 #service端口映射的集群端口,可通过节点ip:38086的方式访问,若未设置该值则为随机端口
name: tcp
部署
kubectl apply -f configmap.yaml
kubectl apply -f statefulset.yaml
创建inlfuxdb账号及数据库
CREATE DATABASE "prometheus";
CREATE USER admin WITH PASSWORD '1234356' WITH ALL PRIVILEGES;
alter retention policy "autogen" on "prometheus" duration 15d default;
修改configmap.yaml文件,开启认证
...
[http]
enabled = true
bind-address = ":8086"
auth-enabled = true #false修改为true,开启认证
...
重启influxdb
更多推荐
已为社区贡献8条内容
所有评论(0)