aboutsummaryrefslogtreecommitdiffstats
path: root/docs/lma/logs/userguide.rst
blob: b410ee6c4ba151b27528c171e21b90559c161121 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
=================
Table of Contents
=================
.. contents::
.. section-numbering::

Setup
======

Prerequisites
-------------------------
- Require 3 VMs to setup K8s
- ``$ sudo yum install ansible``
- ``$ pip install openshift pyyaml kubernetes`` (required for ansible K8s module)
- Update IPs in all these files (if changed)
   ====================================================================== ======================
   Path                                                                   Description
   ====================================================================== ======================
   ``ansible-server/group_vars/all.yml``                                  IP of K8s apiserver and VM hostname
   ``ansible-server/hosts``                                               IP of VMs to install
   ``ansible-server/roles/logging/files/persistentVolume.yaml``           IP of NFS-Server
   ``ansible-server/roles/logging/files/elastalert/ealert-rule-cm.yaml``  IP of alert-receiver
   ====================================================================== ======================

Architecture
--------------
.. image:: images/setup.png

Installation - Clientside
-------------------------

Nodes
`````
- **Node1** = 10.10.120.21
- **Node4** = 10.10.120.24

How installation is done?
`````````````````````````
- TD-agent installation
   ``$ curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent3.sh | sh``
- Copy the TD-agent config file in **Node1**
   ``$ cp tdagent-client-config/node1.conf /etc/td-agent/td-agent.conf``
- Copy the TD-agent config file in **Node4**
   ``$ cp tdagent-client-config/node4.conf /etc/td-agent/td-agent.conf``
- Restart the service
   ``$ sudo service td-agent restart``

Installation - Serverside
-------------------------

Nodes
`````
Inside Jumphost - POD12
   - **VM1** = 10.10.120.211
   - **VM2** = 10.10.120.203
   - **VM3** = 10.10.120.204


How installation is done?
`````````````````````````
**Using Ansible:**
   - **K8s**
      - **Elasticsearch:** 1 Master & 1 Data node at each VM
      - **Kibana:** 1 Replicas
      - **Nginx:** 2 Replicas
      - **Fluentd:** 2 Replicas
      - **Elastalert:** 1 Replica (get duplicate alert, if increase replica)
   - **NFS Server:** at each VM to store elasticsearch data at following path
      - ``/srv/nfs/master``
      - ``/srv/nfs/data``

How to setup?
`````````````
- **To setup K8s cluster and EFK:** Run the ansible-playbook ``ansible/playbooks/setup.yaml``
- **To clean everything:** Run the ansible-playbook ``ansible/playbooks/clean.yaml``

Do we have HA?
````````````````
Yes

Configuration
=============

K8s
---
Path of all yamls (Serverside)
````````````````````````````````
``ansible-server/roles/logging/files/``

K8s namespace
`````````````
``logging``

K8s Service details
````````````````````
``$ kubectl get svc -n logging``

Elasticsearch Configuration
---------------------------

Elasticsearch Setup Structure
`````````````````````````````
.. image:: images/elasticsearch.png

Elasticsearch service details
`````````````````````````````
| **Service Name:** ``logging-es-http``
| **Service Port:** ``9200``
| **Service Type:** ``ClusterIP``

How to get elasticsearch default username & password?
`````````````````````````````````````````````````````
- User1 (custom user):
    | **Username:** ``elasticsearch``
    | **Password:** ``password123``
- User2 (by default created by Elastic Operator):
    | **Username:** ``elastic``
    | To get default password:
    | ``$ PASSWORD=$(kubectl get secret -n logging logging-es-elastic-user -o go-template='{{.data.elastic | base64decode}}')``
    | ``$ echo $PASSWORD``

How to increase replica of any index?
````````````````````````````````````````
| $ curl -k -u "elasticsearch:password123" -H 'Content-Type: application/json' -XPUT  "https://10.10.120.211:9200/indexname*/_settings" -d '
| {
|   "index" : {
|   "number_of_replicas" : "2" }
| }'

Index Life
```````````
**30 Days**

Kibana Configuration
--------------------

Kibana Service details
````````````````````````
| **Service Name:** ``logging-kb-http``
| **Service Port:** ``5601``
| **Service Type:** ``ClusterIP``

Nginx Configuration
--------------------
IP
````
https://10.10.120.211:32000

Nginx Setup Structure
`````````````````````
.. image:: images/nginx.png

Ngnix Service details
`````````````````````
| **Service Name:** ``nginx``
| **Service Port:** ``32000``
| **Service Type:** ``NodePort``

Why NGINX is used?
```````````````````
`Securing ELK using Nginx <https://logz.io/blog/securing-elk-nginx/>`_

Nginx Configuration
````````````````````
**Path:** ``ansible-server/roles/logging/files/nginx/nginx-conf-cm.yaml``

Fluentd Configuration - Clientside (Td-agent)
---------------------------------------------

Fluentd Setup Structure
````````````````````````
.. image:: images/fluentd-cs.png

Log collection paths
`````````````````````
- ``/tmp/result*/*.log``
- ``/tmp/result*/*.dat``
- ``/tmp/result*/*.csv``
- ``/tmp/result*/stc-liveresults.dat.*``
- ``/var/log/userspace*.log``
- ``/var/log/sriovdp/*.log.*``
- ``/var/log/pods/**/*.log``

Logs sends to
`````````````
Another fluentd instance of K8s cluster (K8s Master: 10.10.120.211) at Jumphost.

Td-agent logs
`````````````
Path of td-agent logs: ``/var/log/td-agent/td-agent.log``

Td-agent configuration
````````````````````````
| Path of conf file: ``/etc/td-agent/td-agent.conf``
| **If any changes is made in td-agent.conf then restart the td-agent service,** ``$ sudo service td-agent restart``

Config Description
````````````````````
- Get the logs from collection path
- | Convert to this format
  | {
  |   msg: "log line"
  |   log_path: “/file/path”
  |   file: “file.name”
  |   host: “pod12-node4”
  | }
- Sends it to fluentd

Fluentd Configuration - Serverside
----------------------------------

Fluentd Setup Structure
````````````````````````
.. image:: images/fluentd-ss.png

Fluentd Service details
````````````````````````
| **Service Name:** ``fluentd``
| **Service Port:** ``32224``
| **Service Type:** ``NodePort``

Logs sends to
`````````````
Elasticsearch service (https://logging-es-http:9200)

Config Description
````````````````````
- **Step 1**
   - Get the logs from Node1 & Node4
- **Step 2**
   ======================================== ======================
   log_path                                 add tag (for routing)
   ======================================== ======================
   ``/tmp/result.*/.*errors.dat``           errordat.log
   ``/tmp/result.*/.*counts.dat``           countdat.log
   ``/tmp/result.*/stc-liveresults.dat.tx`` stcdattx.log
   ``/tmp/result.*/stc-liveresults.dat.rx`` stcdatrx.log
   ``/tmp/result.*/.*Statistics.csv``       ixia.log
   ``/tmp/result.*/vsperf-overall*``        vsperf.log
   ``/tmp/result.*/vswitchd*``              vswitchd.log
   ``/var/log/userspace*``                  userspace.log
   ``/var/log/sriovdp*``                    sriovdp.log
   ``/var/log/pods*``                       pods.log
   ======================================== ======================

- **Step 3**
   Then parse each type using tags.
    - error.conf: to find any error
    - time-series.conf: to parse time series data
    - time-analysis.conf: to calculate time analyasis
- **Step 4**
   ================================ ======================
   host                             add tag (for routing)
   ================================ ======================
   ``pod12-node4``                  node4
   ``worker``                       node1
   ================================ ======================
- **Step 5**
   ================================ ======================
   Tag                              elasticsearch
   ================================ ======================
   ``node4``                        index “node4*”
   ``node1``                        index “node1*”
   ================================ ======================

Elastalert
----------

Send alert if
``````````````
- Blacklist
    - "Failed to run test"
    - "Failed to execute in '30' seconds"
    - "('Result', 'Failed')"
    - "could not open socket: connection refused"
    - "Input/output error"
    - "dpdk|ERR|EAL: Error - exiting with code: 1"
    - "Failed to execute in '30' seconds"
    - "dpdk|ERR|EAL: Driver cannot attach the device"
    - "dpdk|EMER|Cannot create lock on"
    - "dpdk|ERR|VHOST_CONFIG: * device not found"
- Time
    - vswitch_duration > 3 sec

How to configure alert?
````````````````````````
- Add your rule in ``ansible/roles/logging/files/elastalert/ealert-rule-cm.yaml`` (`Elastalert Rule Config <https://elastalert.readthedocs.io/en/latest/ruletypes.html>`_)
    | name: anything
    | type: <check-above-link> #The RuleType to use
    | index: node4*   #index name
    | realert:
    |   minutes: 0    #to get alert for all cases after each interval
    | alert: post #To send alert as HTTP POST
    | http_post_url: "http://url"

- Mount this file to elastalert pod in ``ansible/roles/logging/files/elastalert/elastalert.yaml``.

Alert Format
````````````
{"type": "pattern-match", "label": "failed", "index": "node4-20200815", "log": "error-log-line", "log-path": "/tmp/result/file.log", "reson": "error-message" }

Data Management
===============

Elasticsearch
-------------

Where data is stored now?
`````````````````````````
Data is stored in NFS server with 1 replica of each index (default). Path of data are following:
  - ``/srv/nfs/data (VM1)``
  - ``/srv/nfs/data (VM2)``
  - ``/srv/nfs/data (VM3)``
  - ``/srv/nfs/master (VM1)``
  - ``/srv/nfs/master (VM2)``
  - ``/srv/nfs/master (VM3)``
If user wants to change from NFS to local storage
``````````````````````````````````````````````````
Yes, user can do this, need to configure persistent volume. (``ansible-server/roles/logging/files/persistentVolume.yaml``)

Do we have backup of data?
````````````````````````````
1 replica of each index

When K8s restart, the data is still accessible?
`````````````````````````````````````````````````````
Yes (If data is not deleted from /srv/nfs/data)

Troubleshooting
===============
If no logs receiving in Elasticsearch
--------------------------------------
- Check IP & port of server-fluentd in client config.
- Check client-fluentd logs, ``$ sudo tail -f /var/log/td-agent/td-agent.log``
- Check server-fluentd logs, ``$ sudo kubectl logs -n logging <fluentd-pod-name>``

If no notification received
---------------------------
- Search your "log" in Elasticsearch.
- Check config of elastalert
- Check IP of alert-receiver

Reference
=========
- `Elastic cloud on K8s <https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-quickstart.html>`_
- `HA Elasticsearch on K8s <https://www.elastic.co/blog/high-availability-elasticsearch-on-kubernetes-with-eck-and-gke>`_
- `Fluentd Configuration <https://docs.fluentd.org/configuration/config-file>`_
- `Elastalert Rule Config <https://elastalert.readthedocs.io/en/latest/ruletypes.html>`_