-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-compose.yml
223 lines (194 loc) · 5.48 KB
/
docker-compose.yml
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
version: '3'
services:
#
# 1 cluster with 3 brokers each brockers have 2 partions
#
#
kafka1:
image: confluentinc/cp-kafka:latest
hostname: kafka1
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka1:9092
#KAFKA_CREATE_TOPICS: "twitter" # Specify the topic: partitions: replication factor
depends_on:
- zookeeper
networks:
- spark_kafka
healthcheck:
test: "nc -z localhost 9092" # Check if the Kafka port is open
interval: 10s # Check every 10 seconds
timeout: 10s # Timeout after 10 seconds
retries: 5 # Retry 5 times before considering the service unhealthy
kafka2:
image: confluentinc/cp-kafka:latest
hostname: kafka-broker-2
ports:
- "9093:9092" # Change the host port to avoid conflict
environment:
KAFKA_BROKER_ID: 2 # Change the broker ID
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka2:9093 # Adjust the advertised listener
#KAFKA_CREATE_TOPICS: "twitter"
depends_on:
- zookeeper
networks:
- spark_kafka
healthcheck:
test: "nc -z localhost 9093" # Check if the Kafka port is open
interval: 10s # Check every 10 seconds
timeout: 10s # Timeout after 10 seconds
retries: 5 # Retry 5 times before considering the service unhealthy
kafka3:
image: confluentinc/cp-kafka:latest
hostname: kafka-broker-3
ports:
- "9094:9092" # Change the host port to avoid conflict
environment:
KAFKA_BROKER_ID: 3 # Change the broker ID
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka3:9094 # Adjust the advertised listener
# KAFKA_CREATE_TOPICS: "twitter"
depends_on:
- zookeeper
networks:
- spark_kafka
healthcheck:
test: "nc -z localhost 9094" # Check if the Kafka port is open
interval: 10s # Check every 10 seconds
timeout: 10s # Timeout after 10 seconds
retries: 5 # Retry 5 times before considering the service unhealthy
#
# 3 service to create topics
#
#
init-kafka1:
image: confluentinc/cp-kafka:latest
depends_on:
kafka1:
condition: service_healthy
networks:
- spark_kafka
command: >
bash -c "echo 'Creation TOPICS : ' &&/usr/bin/kafka-topics --create --topic twitter --partitions 2 --replication-factor 3 --if-not-exists --bootstrap-server kafka1:9092"
init-kafka2:
image: confluentinc/cp-kafka:latest
depends_on:
kafka2:
condition: service_healthy
networks:
- spark_kafka
command: >
bash -c "echo 'Creation TOPICS : ' && /usr/bin/kafka-topics --create --topic twitter --partitions 2 --replication-factor 3 --if-not-exists --bootstrap-server kafka2:9093"
init-kafka3:
image: confluentinc/cp-kafka:latest
depends_on:
kafka3:
condition: service_healthy
networks:
- spark_kafka
command: >
bash -c "echo 'Creation TOPICS : ' && /usr/bin/kafka-topics --create --topic twitter --partitions 2 --replication-factor 3 --if-not-exists --bootstrap-server kafka3:9094"
zookeeper:
image: zookeeper:3.7.2
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- "2181:2181"
networks:
- spark_kafka
# Producers that send twitter_training.csv to kafka cluster
#
producer:
build:
context: .
dockerfile: Kafka_Streaming/producer/Dockerfile1
networks:
- spark_kafka
depends_on:
- init-kafka1
- init-kafka2
- init-kafka3
volumes:
- zookeeper_data:/data
#
# Spark consumer
#
#
spark:
build:
context: .
dockerfile: trainement/Dockerfile
ports:
- "8080:8080"
- "7077:7077"
networks:
- spark_kafka
depends_on:
- init-kafka1
- init-kafka2
- init-kafka3
spark-worker:
image: docker.io/bitnami/spark:3.5
environment:
- SPARK_MODE=worker
- SPARK_MASTER_URL=spark://spark:7077
- SPARK_WORKER_MEMORY=1G
- SPARK_WORKER_CORES=1
- SPARK_RPC_AUTHENTICATION_ENABLED=no
- SPARK_RPC_ENCRYPTION_ENABLED=no
- SPARK_LOCAL_STORAGE_ENCRYPTION_ENABLED=no
- SPARK_SSL_ENABLED=no
- SPARK_USER=spark
depends_on:
- spark
volumes:
- ./consumer/consumer.py:/root/consumer.py
networks:
- spark_kafka
#
# Mongodb Service
#
mongodb:
image: mongo:latest
hostname: mongodb
container_name: mongodb
ports:
- "27017:27017"
volumes:
- ./mongo/data:/data/db
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: 1234
MONGO_INITDB_DATABASE: Twitter
networks:
- spark_kafka
# mongo-express:
# image: mongo-express
# container_name: mongo-express
# ports:
# - "8081:8081"
# environment:
# - ME_CONFIG_MONGODB_ADMINUSERNAME=admin
# - ME_CONFIG_MONGODB_ADMINPASSWORD=1234
# - ME_CONFIG_MONGODB_URL=mongodb://root:example@mongo:27017/
# networks:
# - spark_kafka
# depends_on:
# - mongodb
#
# Network
#
networks:
spark_kafka:
driver: bridge
volumes:
zookeeper_data:
mongodb_data1: