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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
# MozDef: Complete Detailed Run Guide

## Table of Contents
1. [Prerequisites & System Requirements](#prerequisites--system-requirements)
2. [Complete Installation Process](#complete-installation-process)
3. [Component-by-Component Setup](#component-by-component-setup)
4. [Starting Services in Order](#starting-services-in-order)
5. [Verification & Testing](#verification--testing)
6. [Configuration Deep Dive](#configuration-deep-dive)
7. [Troubleshooting Each Component](#troubleshooting-each-component)
8. [Development Mode Setup](#development-mode-setup)

---

## Prerequisites & System Requirements

### System Requirements

**Minimum Requirements:**
- **CPU**: 4 cores (8 recommended)
- **RAM**: 8GB minimum (16GB recommended)
- **Disk**: 50GB free space (100GB+ for production)
- **OS**: Linux (CentOS 7, Ubuntu 18.04+, or Docker-compatible)

**Docker Requirements:**
- Docker Engine 20.10+
- Docker Compose 1.29+
- At least 4GB RAM allocated to Docker daemon
- Docker storage driver: `aufs` (recommended for Mac OS X)

### Software Prerequisites

**For Docker Installation (Recommended):**
```bash
# Check Docker version
docker --version
# Should be: Docker version 20.10.x or higher

# Check Docker Compose version
docker-compose --version
# Should be: docker-compose version 1.29.x or higher

# Check available memory
docker info | grep "Total Memory"
# Should show at least 4GB available
```

**For Manual Installation:**
- Python 3.6+
- Node.js 8.x (for Meteor)
- Elasticsearch 6.8
- RabbitMQ 3.7+
- MongoDB 3.6+
- Nginx
- Make utility

### Network Requirements

**Ports to Open:**
- `80` - Meteor web interface (HTTP)
- `8080` - Loginput endpoint
- `8081` - REST API (optional, internal)
- `9090` - Kibana
- `514` - Syslog (UDP/TCP)

**Internal Ports (Docker network only):**
- `9200` - Elasticsearch
- `5672` - RabbitMQ AMQP
- `15672` - RabbitMQ Management
- `3002` - MongoDB
- `5601` - Kibana (internal)
- `3000` - Meteor (internal)

---

## Complete Installation Process

### Method 1: Docker Installation (Recommended)

#### Step 1: Clone/Download MozDef

```bash
# If you already have MozDef
cd /root/MozDef

# Or clone from GitHub
git clone https://github.com/mozilla/MozDef.git
cd MozDef
```

#### Step 2: Verify Directory Structure

```bash
# Check key directories exist
ls -la
# Should see: alerts, bot, config, docker, loginput, meteor, mq, rest, etc.

# Check Makefile exists
ls -la Makefile
```

#### Step 3: Build Docker Images

**Option A: Build from Source (Takes 15-30 minutes)**
```bash
# Build all images from source
make build

# This builds:
# - mozdef_base (base Python environment)
# - mozdef_elasticsearch
# - mozdef_rabbitmq
# - mozdef_mongodb
# - mozdef_kibana
# - mozdef_nginx
# - mozdef_bootstrap
# - mozdef_loginput
# - mozdef_mq_worker
# - mozdef_rest
# - mozdef_meteor
# - mozdef_alerts
# - mozdef_alertactions
# - mozdef_cron
# - mozdef_syslog
```

**Option B: Pull Pre-built Images (Faster, 5-10 minutes)**
```bash
# Pull pre-built images from Docker Hub
make build BUILD_MODE=pull

# This downloads images from hub.docker.com/mozdef/*
```

**Option C: Build Without Cache (Clean Build)**
```bash
# Force rebuild everything from scratch
make build NO_CACHE=--no-cache
```

#### Step 4: Verify Images Built

```bash
# List all MozDef images
docker images | grep mozdef

# Should see:
# mozdef/mozdef_base
# mozdef/mozdef_elasticsearch
# mozdef/mozdef_rabbitmq
# mozdef/mozdef_mongodb
# mozdef/mozdef_kibana
# mozdef/mozdef_nginx
# mozdef/mozdef_bootstrap
# mozdef/mozdef_loginput
# mozdef/mozdef_mq_worker
# mozdef/mozdef_rest
# mozdef/mozdef_meteor
# mozdef/mozdef_alerts
# mozdef/mozdef_alertactions
# mozdef/mozdef_cron
# mozdef/mozdef_syslog
```

#### Step 5: Start All Services

```bash
# Start all services with docker-compose
make run

# This command:
# 1. Creates Docker network (mozdef_default)
# 2. Creates Docker volumes (elasticsearch, rabbitmq, mongodb, geolite_db)
# 3. Starts services in dependency order:
#    - Infrastructure: elasticsearch, rabbitmq, mongodb
#    - Bootstrap: Sets up Elasticsearch indices
#    - Backend: loginput, mq_worker, rest, alerts, alertactions
#    - Frontend: meteor, kibana
#    - Proxy: nginx
```

#### Step 6: Monitor Startup

```bash
# Watch all services starting
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps

# Watch logs in real-time
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs -f

# Check specific service logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs -f elasticsearch
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs -f bootstrap
```

**Expected Startup Time:**
- Infrastructure services: 1-2 minutes
- Bootstrap: 30-60 seconds
- Backend services: 1-2 minutes
- Frontend services: 2-3 minutes
- **Total: 5-8 minutes**

---

## Component-by-Component Setup

### 1. Elasticsearch Service

**Purpose:** Event storage, indexing, and search engine

**Configuration:**
- **Image:** `mozdef/mozdef_elasticsearch`
- **Port:** 9200 (internal), not exposed externally
- **Volume:** `elasticsearch:/var/lib/elasticsearch`
- **Health Check:** `curl -f http://127.0.0.1:9200`

**Start Individually:**
```bash
# Start only Elasticsearch
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d elasticsearch

# Check if running
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps elasticsearch

# Check health
docker exec -it mozdef_elasticsearch_1 curl -f http://127.0.0.1:9200

# View logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs elasticsearch
```

**Verify Elasticsearch:**
```bash
# Check cluster health
docker exec -it mozdef_elasticsearch_1 curl http://127.0.0.1:9200/_cluster/health?pretty

# Should return:
# {
#   "cluster_name" : "elasticsearch",
#   "status" : "green" or "yellow",
#   ...
# }

# List indices (should be empty initially)
docker exec -it mozdef_elasticsearch_1 curl http://127.0.0.1:9200/_cat/indices?v
```

**Troubleshooting:**
- **Not starting:** Check Docker memory allocation (needs 2GB+)
- **Yellow status:** Normal for single-node cluster
- **Out of memory:** Increase Docker memory limit

---

### 2. RabbitMQ Service

**Purpose:** Message queue for event processing

**Configuration:**
- **Image:** `mozdef/mozdef_rabbitmq`
- **Ports:** 5672 (AMQP, internal), 15672 (Management, internal)
- **Volume:** `rabbitmq:/var/lib/rabbitmq`
- **Default Credentials:** guest/guest
- **Health Check:** `curl -f http://127.0.0.1:15672`

**Start Individually:**
```bash
# Start RabbitMQ
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d rabbitmq

# Check status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps rabbitmq

# Access management UI (if port exposed)
# http://localhost:15672 (guest/guest)
```

**Verify RabbitMQ:**
```bash
# Check if management interface responds
docker exec -it mozdef_rabbitmq_1 curl -f http://127.0.0.1:15672

# List exchanges (should see eventtask, mozdef.event, alerts)
docker exec -it mozdef_rabbitmq_1 rabbitmqctl list_exchanges

# List queues
docker exec -it mozdef_rabbitmq_1 rabbitmqctl list_queues
```

**Troubleshooting:**
- **Connection refused:** Wait 30-60 seconds for full startup
- **Management UI not accessible:** Port not exposed (normal, internal only)

---

### 3. MongoDB Service

**Purpose:** Database for Meteor (incidents, users, settings)

**Configuration:**
- **Image:** `mozdef/mozdef_mongodb`
- **Port:** 3002 (internal)
- **Volume:** `mongodb:/var/lib/mongo`
- **Config:** `/etc/mongod.conf`
- **Health Check:** `curl -f http://127.0.0.1:3002`

**Start Individually:**
```bash
# Start MongoDB
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d mongodb

# Check status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps mongodb

# Connect to MongoDB shell
docker exec -it mozdef_mongodb_1 mongo --port 3002
```

**Verify MongoDB:**
```bash
# List databases
docker exec -it mozdef_mongodb_1 mongo --port 3002 --eval "db.adminCommand('listDatabases')"

# Should see: meteor, admin, local, config
```

**Troubleshooting:**
- **Not starting:** Check disk space (MongoDB needs space for journal)
- **Connection refused:** Wait for initialization (30 seconds)

---

### 4. Bootstrap Service

**Purpose:** Initial setup of Elasticsearch indices and Kibana dashboards

**Configuration:**
- **Image:** `mozdef/mozdef_bootstrap`
- **Runs Once:** Exits after setup completes
- **Dependencies:** base, elasticsearch
- **Script:** `initial_setup.py`

**What It Does:**
1. Waits for Elasticsearch to be ready
2. Creates Elasticsearch index templates
3. Creates initial indices (events-*, alerts-*)
4. Sets up Kibana index patterns
5. Imports Kibana dashboards (if available)

**Start Individually:**
```bash
# Start bootstrap (runs once and exits)
docker-compose -f docker/compose/docker-compose.yml -p mozdef up bootstrap

# Check logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs bootstrap

# Should see:
# "Waiting for Elasticsearch..."
# "Elasticsearch is ready"
# "Creating index templates..."
# "Setting up Kibana..."
# "Bootstrap complete"
```

**Verify Bootstrap:**
```bash
# Check if indices were created
docker exec -it mozdef_elasticsearch_1 curl http://127.0.0.1:9200/_cat/indices?v

# Should see:
# events-YYYY.MM.DD
# alerts-YYYY.MM.DD
# (with today's date)
```

**Troubleshooting:**
- **Fails immediately:** Elasticsearch not ready (wait 1-2 minutes)
- **Index creation fails:** Check Elasticsearch logs

---

### 5. Loginput Service

**Purpose:** HTTP endpoint for receiving JSON events

**Configuration:**
- **Image:** `mozdef/mozdef_loginput`
- **Port:** 8080 (via Nginx)
- **Config File:** `loginput/index.conf`
- **Endpoints:**
  - `/events` - Single event POST
  - `/_bulk` - Bulk events POST
  - `/nxlog` - NXLog endpoint
  - `/status` - Health check

**Configuration File:** `loginput/index.conf`
```ini
[options]
mquser=guest
mqpassword=guest
mqserver=rabbitmq
mqport=5672
mqvhost=/
mqprotocol=amqp
taskexchange=eventtask
listen_host=0.0.0.0
listen_port=8080
```

**Start Individually:**
```bash
# Start loginput
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d loginput

# Check status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps loginput

# Check health
curl http://localhost:8080/status
# Should return: {"status":"ok","service":"loginput"}
```

**Verify Loginput:**
```bash
# Test endpoint
curl -X POST http://localhost:8080/events \
  -H "Content-Type: application/json" \
  -d '{
    "timestamp": "2024-01-15T10:00:00+00:00",
    "utctimestamp": "2024-01-15T10:00:00+00:00",
    "hostname": "test.example.com",
    "processname": "test.py",
    "processid": 1234,
    "severity": "INFO",
    "summary": "Test event",
    "category": "test",
    "source": "test",
    "tags": ["test"],
    "details": {}
  }'

# Should return: HTTP 200 OK
```

**View Logs:**
```bash
# Loginput logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs loginput

# Should see:
# "Starting loginput service..."
# "Connected to RabbitMQ"
# "Listening on 0.0.0.0:8080"
```

**Troubleshooting:**
- **Connection refused:** Nginx not running or port conflict
- **RabbitMQ connection fails:** RabbitMQ not ready (wait 30 seconds)
- **500 errors:** Invalid JSON format (check event structure)

---

### 6. MQ Worker Service

**Purpose:** Process events from RabbitMQ queue and index to Elasticsearch

**Configuration:**
- **Image:** `mozdef/mozdef_mq_worker`
- **Config File:** `mq/esworker_eventtask.conf`
- **Dependencies:** elasticsearch, rabbitmq, loginput

**Configuration File:** `mq/esworker_eventtask.conf`
```ini
[options]
prefetch=150
esbulksize=150
esservers=http://elasticsearch:9200
mqack=False
mquser=guest
mqpassword=guest
mqserver=rabbitmq
mqport=5672
mqvhost=/
mqprotocol=amqp
taskexchange=eventtask
eventexchange=mozdef.event
```

**Start Individually:**
```bash
# Start MQ worker
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d mq_worker

# Check status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps mq_worker

# Check if worker is processing
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs mq_worker
```

**Verify MQ Worker:**
```bash
# Send test event (see Loginput section)
# Then check if event appears in Elasticsearch
docker exec -it mozdef_elasticsearch_1 curl \
  "http://127.0.0.1:9200/events-*/_search?q=category:test&pretty"

# Should return your test event
```

**View Logs:**
```bash
# MQ Worker logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs mq_worker

# Should see:
# "Connected to RabbitMQ"
# "Connected to Elasticsearch"
# "Consuming from queue: eventtask"
# "Processing event..."
# "Indexed event to Elasticsearch"
```

**Troubleshooting:**
- **Not consuming messages:** Check RabbitMQ connection
- **Elasticsearch errors:** Check Elasticsearch health
- **Events not appearing:** Check worker logs for errors

---

### 7. REST API Service

**Purpose:** RESTful API for web interface

**Configuration:**
- **Image:** `mozdef/mozdef_rest`
- **Port:** 8081 (internal, via Nginx)
- **Config File:** `rest/index.conf`
- **Dependencies:** elasticsearch, mongodb

**Configuration File:** `rest/index.conf`
```ini
[options]
esservers=http://elasticsearch:9200
mongohost=mongodb
mongoport=3002
listen_host=0.0.0.0
listen_port=8081
```

**Start Individually:**
```bash
# Start REST API
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d rest

# Check status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps rest

# Check health
curl http://localhost:8081/status
# Should return: {"status":"ok","service":"restapi"}
```

**Verify REST API:**
```bash
# Test endpoints
curl http://localhost:8081/veris
curl http://localhost:8081/kibanadashboards
curl http://localhost:8081/getwatchlist
```

**View Logs:**
```bash
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs rest
```

**Troubleshooting:**
- **Connection refused:** Nginx not routing correctly
- **Elasticsearch errors:** Check Elasticsearch connection
- **MongoDB errors:** Check MongoDB connection

---

### 8. Meteor Service (Web Interface)

**Purpose:** Real-time web interface for incident handling

**Configuration:**
- **Image:** `mozdef/mozdef_meteor`
- **Port:** 3000 (internal), 80 (via Nginx)
- **Dependencies:** mongodb, rest
- **Settings:** `meteor/imports/settings.js`

**Environment Variables:**
```bash
MONGO_URL=mongodb://mongodb:3002/meteor
ROOT_URL=http://localhost
PORT=3000
```

**Start Individually:**
```bash
# Start Meteor
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d meteor

# Check status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps meteor

# Check health
curl http://localhost:3000
# Should return HTML (Meteor app)
```

**Verify Meteor:**
```bash
# Access web interface
# http://localhost (via Nginx) or http://localhost:3000 (direct)

# Check if Meteor is running
docker exec -it mozdef_meteor_1 curl http://127.0.0.1:3000
```

**View Logs:**
```bash
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs meteor

# Should see:
# "MozDef starting"
# "Meteor server started"
# "Connected to MongoDB"
```

**Troubleshooting:**
- **Not accessible:** Check Nginx routing
- **MongoDB connection fails:** Wait for MongoDB to be ready
- **REST API errors:** Check REST API is running

---

### 9. Kibana Service

**Purpose:** Log visualization and analysis

**Configuration:**
- **Image:** `mozdef/mozdef_kibana`
- **Port:** 5601 (internal), 9090 (via Nginx)
- **Dependencies:** elasticsearch
- **Config:** Connects to `http://elasticsearch:9200`

**Start Individually:**
```bash
# Start Kibana
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d kibana

# Check status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps kibana

# Check health
curl http://localhost:9090/app/kibana
# Should return HTML
```

**Verify Kibana:**
```bash
# Access Kibana
# http://localhost:9090/app/kibana

# Check if Kibana API responds
curl http://localhost:9090/api/status
```

**View Logs:**
```bash
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs kibana
```

**Troubleshooting:**
- **Not accessible:** Check Nginx routing
- **Elasticsearch connection fails:** Wait for Elasticsearch
- **Index patterns missing:** Run bootstrap again

---

### 10. Alerts Service

**Purpose:** Alert correlation engine (Celery-based)

**Configuration:**
- **Image:** `mozdef/mozdef_alerts`
- **Technology:** Celery (Python task scheduler)
- **Dependencies:** elasticsearch, rabbitmq, rest, bootstrap
- **Config:** `alerts/lib/config.py`

**Start Individually:**
```bash
# Start Alerts
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d alerts

# Check status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps alerts

# Check Celery health
docker exec -it mozdef_alerts_1 celery -A lib.tasks inspect ping
# Should return: pong
```

**Verify Alerts:**
```bash
# Check registered alerts
docker exec -it mozdef_alerts_1 celery -A lib.tasks inspect registered

# Check active tasks
docker exec -it mozdef_alerts_1 celery -A lib.tasks inspect active

# Check scheduled tasks
docker exec -it mozdef_alerts_1 celery -A lib.tasks inspect scheduled
```

**View Logs:**
```bash
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs alerts

# Should see:
# "Loading alerts..."
# "Registered alert: bruteforce_ssh"
# "Registered alert: proxy_drop_executable"
# "Celery worker started"
# "Beat scheduler started"
```

**Troubleshooting:**
- **No alerts registered:** Check alert configuration files
- **Celery not starting:** Check RabbitMQ connection
- **Alerts not firing:** Check Elasticsearch queries

---

### 11. Alert Actions Service

**Purpose:** Post-alert processing and actions

**Configuration:**
- **Image:** `mozdef/mozdef_alertactions`
- **Config File:** `alerts/alert_actions_worker.conf`
- **Dependencies:** elasticsearch, rabbitmq, alerts

**Configuration File:** `alerts/alert_actions_worker.conf`
```ini
[options]
esservers=http://elasticsearch:9200
mquser=guest
mqpassword=guest
mqserver=rabbitmq
mqport=5672
mqvhost=/
mqprotocol=amqp
alertexchange=alerts
alertqueue=alerts
```

**Start Individually:**
```bash
# Start Alert Actions
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d alertactions

# Check status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps alertactions

# Check if worker is running
docker exec -it mozdef_alertactions_1 ps aux | grep python
```

**Verify Alert Actions:**
```bash
# Check if consuming from alerts queue
docker exec -it mozdef_rabbitmq_1 rabbitmqctl list_queues name consumers

# Should see "alerts" queue with 1 consumer
```

**View Logs:**
```bash
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs alertactions
```

**Troubleshooting:**
- **Not consuming alerts:** Check RabbitMQ connection
- **No alerts processed:** Ensure alerts service is generating alerts

---

### 12. Nginx Service

**Purpose:** Reverse proxy routing traffic to services

**Configuration:**
- **Image:** `mozdef/mozdef_nginx`
- **Config File:** `config/nginx.conf`
- **Ports:** 80, 8080, 8081, 9090
- **Dependencies:** meteor, kibana, loginput, rest

**Start Individually:**
```bash
# Start Nginx (starts last, depends on all services)
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d nginx

# Check status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps nginx

# Test routing
curl http://localhost/status
curl http://localhost:8080/status
curl http://localhost:9090/app/kibana
```

**Verify Nginx:**
```bash
# Check Nginx config
docker exec -it mozdef_nginx_1 nginx -t

# Check access logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs nginx
```

**Troubleshooting:**
- **502 Bad Gateway:** Upstream service not ready
- **Connection refused:** Service not started
- **404 Not Found:** Check routing configuration

---

### 13. Cron Service

**Purpose:** Scheduled tasks (index rotation, stats, etc.)

**Configuration:**
- **Image:** `mozdef/mozdef_cron`
- **Dependencies:** elasticsearch, rabbitmq, mongodb
- **Tasks:** Defined in `/opt/mozdef/envs/mozdef/cron/`

**Start Individually:**
```bash
# Start Cron
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d cron

# Check status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps cron

# Check cron jobs
docker exec -it mozdef_cron_1 crontab -l
```

**View Logs:**
```bash
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs cron
```

---

## Starting Services in Order

### Correct Startup Sequence

Services must start in dependency order:

```bash
# 1. Infrastructure Services (no dependencies)
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d elasticsearch
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d rabbitmq
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d mongodb

# 2. Wait for infrastructure (30-60 seconds)
sleep 60

# 3. Bootstrap (sets up Elasticsearch)
docker-compose -f docker/compose/docker-compose.yml -p mozdef up bootstrap

# 4. Backend Services
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d loginput
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d mq_worker
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d rest

# 5. Frontend Services
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d kibana
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d meteor

# 6. Alert Services
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d alerts
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d alertactions

# 7. Proxy (starts last)
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d nginx

# 8. Optional Services
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d cron
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d syslog
```

### Using Make Command (Recommended)

```bash
# This handles all dependencies automatically
make run
```

---

## Verification & Testing

### 1. Check All Services Running

```bash
# List all services
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps

# All services should show "Up" status
# Health checks should pass (no "unhealthy" status)
```

### 2. Test Event Ingestion

```bash
# Send test event
curl -X POST http://localhost:8080/events \
  -H "Content-Type: application/json" \
  -d '{
    "timestamp": "'$(date -u +"%Y-%m-%dT%H:%M:%S+00:00")'",
    "utctimestamp": "'$(date -u +"%Y-%m-%dT%H:%M:%S+00:00")'",
    "hostname": "test.example.com",
    "processname": "test.py",
    "processid": 1234,
    "severity": "INFO",
    "summary": "Test event from detailed guide",
    "category": "test",
    "source": "test",
    "tags": ["test", "verification"],
    "details": {
      "message": "This is a test event"
    }
  }'

# Should return: HTTP 200 OK
```

### 3. Verify Event in Elasticsearch

```bash
# Wait 5-10 seconds for processing
sleep 10

# Search for test event
docker exec -it mozdef_elasticsearch_1 curl \
  "http://127.0.0.1:9200/events-*/_search?q=category:test&pretty&size=1"

# Should return your test event
```

### 4. Verify Event in Kibana

```bash
# 1. Open Kibana: http://localhost:9090/app/kibana
# 2. Go to "Discover"
# 3. Select index pattern: "events-*"
# 4. Search for: category:test
# 5. Should see your test event
```

### 5. Test REST API

```bash
# Health check
curl http://localhost:8081/status

# Get watchlist
curl http://localhost:8081/getwatchlist

# Get VERIS stats
curl http://localhost:8081/veris
```

### 6. Test Meteor Web Interface

```bash
# 1. Open browser: http://localhost
# 2. Should see MozDef login page
# 3. Create account or login
# 4. Should see dashboard
```

### 7. Test Alert Generation

```bash
# Send multiple failed login events to trigger SSH brute force alert
for i in {1..15}; do
  curl -X POST http://localhost:8080/events \
    -H "Content-Type: application/json" \
    -d "{
      \"timestamp\": \"$(date -u +"%Y-%m-%dT%H:%M:%S+00:00")\",
      \"utctimestamp\": \"$(date -u +"%Y-%m-%dT%H:%M:%S+00:00")\",
      \"hostname\": \"test.example.com\",
      \"processname\": \"sshd\",
      \"processid\": 1234,
      \"severity\": \"WARNING\",
      \"summary\": \"Failed SSH login attempt\",
      \"category\": \"authentication\",
      \"source\": \"syslog\",
      \"tags\": [\"ssh\", \"authentication\", \"failure\"],
      \"details\": {
        \"username\": \"testuser\",
        \"sourceipaddress\": \"192.168.1.100\",
        \"success\": false
      }
    }"
  sleep 1
done

# Wait 5 minutes for alert to fire
# Check alerts in Elasticsearch
docker exec -it mozdef_elasticsearch_1 curl \
  "http://127.0.0.1:9200/alerts-*/_search?pretty&size=5"
```

---

## Configuration Deep Dive

### Environment Variables

Set via Docker Compose or environment file:

```bash
# Create custom environment file
cat > my-mozdef.env <<EOF
OPTIONS_METEOR_ROOTURL=http://localhost
OPTIONS_METEOR_PORT=80
OPTIONS_METEOR_ROOTAPI=http://rest:8081
OPTIONS_METEOR_KIBANAURL=http://localhost:9090/app/kibana
OPTIONS_METEOR_ENABLECLIENTACCOUNTCREATION=true
OPTIONS_METEOR_AUTHENTICATIONTYPE=meteor-password
OPTIONS_MQPROTOCOL=amqp
EOF

# Run with custom env file
make run-env-mozdef -e ENV=my-mozdef.env
```

### Key Configuration Files

| Service | Config File | Location |
|---------|------------|----------|
| Loginput | `index.conf` | `loginput/index.conf` |
| MQ Worker | `esworker_eventtask.conf` | `mq/esworker_eventtask.conf` |
| REST API | `index.conf` | `rest/index.conf` |
| Alerts | `lib/config.py` | `alerts/lib/config.py` |
| Alert Actions | `alert_actions_worker.conf` | `alerts/alert_actions_worker.conf` |
| Nginx | `nginx.conf` | `config/nginx.conf` |
| Meteor | `settings.js` | `meteor/imports/settings.js` |

---

## Troubleshooting Each Component

### Elasticsearch Issues

**Problem: Not starting**
```bash
# Check logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs elasticsearch

# Common issues:
# - Out of memory: Increase Docker memory
# - Disk space: Check available disk
# - Permissions: Check volume permissions
```

**Problem: Yellow/Red cluster status**
```bash
# Single node cluster shows yellow (normal)
# Red means unassigned shards - check logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs elasticsearch
```

### RabbitMQ Issues

**Problem: Connection refused**
```bash
# Wait for RabbitMQ to fully start (30-60 seconds)
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs rabbitmq

# Check if management interface is up
docker exec -it mozdef_rabbitmq_1 curl http://127.0.0.1:15672
```

### Loginput Issues

**Problem: 500 errors on event POST**
```bash
# Check event JSON format
# Must include all mandatory fields

# Check logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs loginput

# Common issues:
# - Invalid JSON
# - Missing mandatory fields
# - RabbitMQ connection failed
```

### MQ Worker Issues

**Problem: Events not appearing in Elasticsearch**
```bash
# Check worker logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs mq_worker

# Check RabbitMQ queue
docker exec -it mozdef_rabbitmq_1 rabbitmqctl list_queues

# Check Elasticsearch connection
docker exec -it mq_worker curl http://elasticsearch:9200
```

### Meteor Issues

**Problem: Web interface not loading**
```bash
# Check Meteor logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs meteor

# Check MongoDB connection
docker exec -it mozdef_meteor_1 mongo --host mongodb --port 3002

# Check REST API connection
docker exec -it mozdef_meteor_1 curl http://rest:8081/status
```

### Alerts Issues

**Problem: Alerts not firing**
```bash
# Check Celery status
docker exec -it mozdef_alerts_1 celery -A lib.tasks inspect active

# Check registered alerts
docker exec -it mozdef_alerts_1 celery -A lib.tasks inspect registered

# Check alert logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs alerts

# Verify Elasticsearch queries work
docker exec -it mozdef_alerts_1 python -c "
from mozdef_util.elasticsearch_client import ElasticsearchClient
from mozdef_util.query_models import SearchQuery, TermMatch
es = ElasticsearchClient(['http://elasticsearch:9200'])
query = SearchQuery(minutes=5)
query.add_must([TermMatch('category', 'authentication')])
results = es.query(query)
print(f'Found {len(results)} events')
"
```

---

## Development Mode Setup

### Run Individual Services for Development

```bash
# Start only infrastructure
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d elasticsearch rabbitmq mongodb

# Run service in foreground (see logs)
docker-compose -f docker/compose/docker-compose.yml -p mozdef up loginput

# Rebuild specific service
docker-compose -f docker/compose/docker-compose.yml -p mozdef build loginput
docker-compose -f docker/compose/docker-compose.yml -p mozdef up -d loginput
```

### Development Meteor (Live Reload)

```bash
# Run Meteor in development mode
make run-dev-meteor

# This mounts meteor directory for live code changes
```

### Run Tests

```bash
# Build test environment
make build-tests

# Run all tests
make tests

# Run specific test
make run-tests TEST_CASE=tests/alerts/test_bruteforce_ssh.py
```

---

## Complete Startup Checklist

- [ ] Docker and Docker Compose installed
- [ ] At least 4GB RAM allocated to Docker
- [ ] MozDef directory cloned/downloaded
- [ ] Docker images built (`make build`)
- [ ] All services started (`make run`)
- [ ] Elasticsearch healthy (green/yellow status)
- [ ] RabbitMQ management accessible
- [ ] MongoDB running
- [ ] Bootstrap completed successfully
- [ ] Loginput responding (`curl http://localhost:8080/status`)
- [ ] REST API responding (`curl http://localhost:8081/status`)
- [ ] Meteor web interface accessible (`http://localhost`)
- [ ] Kibana accessible (`http://localhost:9090/app/kibana`)
- [ ] Test event sent and appears in Elasticsearch
- [ ] Test event visible in Kibana
- [ ] Alerts service running (Celery ping successful)

---

## Quick Reference Commands

```bash
# Start everything
make run

# Stop everything
make stop

# View all logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs -f

# View specific service logs
docker-compose -f docker/compose/docker-compose.yml -p mozdef logs -f [service-name]

# Restart specific service
docker-compose -f docker/compose/docker-compose.yml -p mozdef restart [service-name]

# Rebuild specific service
docker-compose -f docker/compose/docker-compose.yml -p mozdef build [service-name]

# Clean everything
make clean

# Check service status
docker-compose -f docker/compose/docker-compose.yml -p mozdef ps

# Execute command in container
docker exec -it mozdef_[service]_1 [command]

# Access service shell
docker exec -it mozdef_[service]_1 /bin/bash
```

---

This guide provides complete step-by-step instructions for running every component of MozDef. Follow it sequentially for a successful deployment!