安装ansible
pip install ansible
安装elastsearch集群
下载role
ansible-galaxy install elastic.elasticsearch,7.6.2
配置主机信息
cd /root/.ansible/roles
[root@iZ1bb01rvthes8gbrnyixjZ roles]
[elk-master-nodes]
master_ip ansible_user=root ansible_ssh_pass=xx ansible_port=22
[elk-data-nodes]
data_node_ip ansible_user=root ansible_ssh_pass=xx ansible_port=22
配置playbook
[root@iZ1bb01rvthes8gbrnyixjZ roles]
- hosts: elk-master-nodes
roles:
- role: elastic.elasticsearch
vars:
es_enable_xpack: false
es_data_dirs:
- "/data/elasticsearch/data"
es_log_dir: "/data/elasticsearch/logs"
es_java_install: true
es_heap_size: "8g"
es_config:
cluster.name: "elk-cluster"
cluster.initial_master_nodes: "master1:9300,master2:9300,master3:9300"
discovery.seed_hosts: "master1:9300,master2:9300,master3:9300"
http.port: 9200
node.data: false
node.master: true
bootstrap.memory_lock: false
network.host: '0.0.0.0'
- hosts: elk-data-nodes
roles:
- role: elastic.elasticsearch
vars:
es_enable_xpack: false
es_data_dirs:
- "/data/elasticsearch/data"
es_log_dir: "/data/elasticsearch/logs"
es_java_install: true
es_heap_size: "8g"
es_config:
cluster.name: "elk-cluster"
cluster.initial_master_nodes: "master1:9300,master2:9300,master3:9300"
discovery.seed_hosts: "master1:9300,master2:9300,master3:9300"
http.port: 9200
node.data: true
node.master: false
bootstrap.memory_lock: false
network.host: '0.0.0.0'
运行playbook
ansible-playbook -i inventory.yml elk.yml
验证集群
curl http://master1:9200/_cluster/health?pretty
如果报错,修改配置文件
[root@iZ1bb01rvthes8gbrnyixjZ roles]
cluster.name: es-cluster
node.name: master1
node.master: true
node.data: true
bootstrap.memory_lock: true
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping.unicast.hosts: ["master1", "master2", "master3"]
cluster.initial_master_nodes: master1
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs
action.auto_create_index: true
systemctl restart elasticsearch
安装kibana
wget https://artifacts.elastic.co/downloads/kibana/kibana-oss-7.6.2-x86_64.rpm
yum install kibana-oss-7.6.2-x86_64.rpm
systemctl start kibana
cat /etc/kibana/kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]
安装search-guard 安全认证插件
安装 search-guard es 插件
https://docs.search-guard.com/latest/search-guard-versions
wget https://maven.search-guard.com/search-guard-suite-release/com/floragunn/search-guard-suite-plugin/7.6.2-41.0.0/search-guard-suite-plugin-7.6.2-41.0.0.zip
https://docs.search-guard.com/latest/search-guard-installation
安装步骤
1. 关闭分片分配
curl -Ss -XPUT 'http://localhost:9200/_cluster/settings?pretty' -H 'Content-Type: application/json' -d'
{
"persistent": {
"cluster.routing.allocation.enable": "none"
}
}
'
2. 停掉es
systemctl stop elasticsearch
3. 安装插件
/usr/share/elasticsearch/bin/elasticsearch-plugin install file:///root/search-guard-suite-plugin-7.6.2-41.0.0.zip
4. 增加 tls 配置
cd /usr/share/elasticsearch/plugins/search-guard-7/tools/
sh install_demo_configuration.sh
4. 启动es集群
systemctl start elasticsearch
5. 开启分片分配
./sgadmin.sh --enable-shard-allocation -cert /etc/elasticsearch/kirk.pem -key /etc/elasticsearch/kirk-key.pem -cacert /etc/elasticsearch/root-ca.pem
6. 初始化search guard
sh sgadmin_demo.sh
7. 验证
curl http://localhost:9200/_searchguard/health -k
{"message":null,"mode":"strict","status":"UP"}[
安装 search-guard kibana 插件
wget https://maven.search-guard.com/search-guard-kibana-plugin-release/com/floragunn/search-guard-kibana-plugin/7.6.2-41.1.0/search-guard-kibana-plugin-7.6.2-41.1.0.zip
/usr/share/kibana/bin/kibana-plugin install file:///root/search-guard-kibana-plugin-7.6.2-41.1.0.zip --allow-root
修改默认密码
cd /usr/share/elasticsearch/plugins/search-guard-7/tools/
[root@iZ1bb01rvthes8gbrnyixjZ tools]
WARNING: JAVA_HOME not set, will use /usr/bin/java
$2y$12$5bv2H9KAeLn3gMbO.4Hr6.eT9AW.hHpJZ3GOxycKWe4D0ixs7zGia
把hash值填写到
vi /usr/share/elasticsearch/plugins/search-guard-7/sgconfig/sg_internal_users.yml
admin:
hash: "$2y$12$GCUMF8L8AE7mSsCoD/zoI.1E2FiHppedwFnKZPBwcQOYzx2yygPlq"
reserved: true
backend_roles:
- "admin"
description: "Demo admin user"
sh sgadmin_demo.sh
开启http访问
vi /etc/elasticsearch/elasticsearch.yml
searchguard.ssl.http.enabled: false
安装flutend日志采集
[root@yunqi-master1 fluentd-kubernetes-daemonset]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: fluentd
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: fluentd
namespace: kube-system
rules:
- apiGroups:
- ""
resources:
- pods
- namespaces
verbs:
- get
- list
- watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: fluentd
roleRef:
kind: ClusterRole
name: fluentd
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: fluentd
namespace: kube-system
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd
namespace: kube-system
labels:
k8s-app: fluentd-logging
version: v1
spec:
selector:
matchLabels:
k8s-app: fluentd-logging
version: v1
template:
metadata:
labels:
k8s-app: fluentd-logging
version: v1
spec:
serviceAccount: fluentd
serviceAccountName: fluentd
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: fluentd
image: fluent/fluentd-kubernetes-daemonset:v1-debian-elasticsearch
env:
- name: FLUENT_ELASTICSEARCH_HOST
value: "master1"
- name: FLUENT_ELASTICSEARCH_PORT
value: "9200"
- name: FLUENT_ELASTICSEARCH_SCHEME
value: "http"
- name: FLUENT_ELASTICSEARCH_SSL_VERIFY
value: "true"
- name: FLUENT_ELASTICSEARCH_SSL_VERSION
value: "TLSv1_2"
- name: FLUENT_ELASTICSEARCH_USER
value: "admin"
- name: FLUENT_ELASTICSEARCH_PASSWORD
value: "admin"
- name: FLUENT_ELASTICSEARCH_BUFFER_CHUNK_LIMIT_SIZE
value: "15m"
resources:
limits:
memory: 400Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /data/docker/containers
readOnly: true
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /data/docker/containers
kubectl apply -f fluentd-daemonset-elasticsearch-rbac.yaml
flutend 踩坑点
flutend报错之一
2016-12-01T22:41:01.814337960Z 2016-12-01 22:41:01 +0000 [warn]: /var/log/containers/kubernetes-dashboard-qcmyh_kube-system_kubernetes-dashboard-c98d8d1296b691493ac2a8ce7f30a42dbe8107d2e425cd12f681021144f1895f.log unreadable. It is excluded and would be examined next time.
2016-12-01T22:41:01.814351093Z 2016-12-01 22:41:01 +0000 [warn]: /var/log/containers/kube-dns-v20-zr41g_kube-system_POD-22aaa1f29033d57e6f1a40a2c87c6d3624815824adf9e5192d4ec611e1ab1909.log unreadable. It is excluded and would be examined next time.
2016-12-01T22:41:01.814364345Z 2016-12-01 22:41:01 +0000 [warn]: /var/log/containers/kubernetes-dashboard-qcmyh_kube-system_POD-465a601853d4a418984da54c1a5d7868368b6f221ba936988930cd22b87d4685.log unreadable. It is excluded and would be examined next time.
2016-12-01T22:41:01.814374217Z 2016-12-01 22:41:01 +0000 [warn]: /var/log/containers/kube-addon-manager-minikube_kube-system_kube-addon-manager-0813bd6a91f83b7d5171b8f291a1a353ce3c4672f5494319c61ba0d78c13f046.log unreadable. It is excluded and would be examined next time.
2016-12-01T22:41:01.814381784Z 2016-12-01 22:41:01 +0000 [warn]: /var/log/containers/kube-addon-manager-minikube_kube-system_POD-a894a06883d52c19b5e0f62bff14465f70525363d26bc66652cc31c36b266b67.log unreadable. It is excluded and would be examined next time.
排查
ll /var/log/containers
docker info
https://github.com/kubernetes/minikube/issues/876
flutend报错之二
chunk bytes limit exceeds for an emitted event stream:
排查
默认chuck bytes size不够大
修改yaml文件注入容器环境变量修改默认chunk byte size
- name: FLUENT_ELASTICSEARCH_BUFFER_CHUNK_LIMIT_SIZE
value: "15m"