Skip to content

Commit 00690c2

Browse files
committed
Move Patroni, Mongo, Redis and Elastic cluster from databases repository
1 parent 644fdcb commit 00690c2

25 files changed

+689
-15
lines changed

.pre-commit-config.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ repos:
1616
hooks:
1717
- id: remove-crlf
1818
- id: remove-tabs
19+
20+
- repo: https://github.com/igorshubovych/markdownlint-cli
21+
rev: v0.41.0
22+
hooks:
23+
- id: markdownlint
24+
name: Markdown Lint
25+
args: [ --disable=MD007,--disable=MD013,--disable=MD014,--disable=MD024,--disable=MD031 ]

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[![Build](https://github.com/Romanow/docker-compose-examples/actions/workflows/build.yaml/badge.svg?branch=master)](https://github.com/Romanow/docker-compose-examples/actions/workflows/build.yaml)
1+
[![CI](https://github.com/Romanow/docker-compose-examples/actions/workflows/build.yaml/badge.svg?branch=master)](https://github.com/Romanow/docker-compose-examples/actions/workflows/build.yaml)
22
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
3-
[![License](https://img.shields.io/github/license/Romanow/docker-compose-examples)](https://github.com/Romanow/docker-compose-exampleslist/blob/main/LICENSE)
3+
[![License](https://img.shields.io/github/license/Romanow/docker-compose-examples)](https://github.com/Romanow/docker-compose-examples/blob/master/LICENSE)
44

55
# Docker Compose examples
66

@@ -13,7 +13,10 @@
1313
## Storages
1414

1515
* [Postgres](postgres/README.md)
16+
* [Patroni](mysql/README.md)
17+
* [Mongo](mysql/README.md)
1618
* [MySQL](mysql/README.md)
19+
* [Redis](mysql/README.md)
1720
* [Elastic](elastic/README.md)
1821
* [Minio](minio/README.md)
1922

artemis/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# ArtemisMQ
2+
3+
* [Simple](docker-compose.yml)

artemis/docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
timeout: 10s
1414
retries: 5
1515
volumes:
16-
- artemis-data:/var/lib/artemis-instance
16+
- artemis:/var/lib/artemis-instance
1717

1818
volumes:
19-
artemis-data:
19+
artemis:

elastic/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# ElasticSearch
22

33
* [Single Node](docker-compose.yml)
4+
* [Cluster](docker-compose.cluster.yml)
5+
6+
```shell
7+
$ docker-compose up -d --wait
8+
$ curl 'http://localhost:9200/_cluster/health?pretty' --user elastic:qwerty
9+
```

elastic/certs/ca-elastic.p12

2.61 KB
Binary file not shown.

elastic/docker-compose.cluster.yml

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
services:
2+
elastic-1:
3+
image: "bitnami/elasticsearch:8.17.1"
4+
container_name: elastic-1
5+
environment:
6+
BITNAMI_DEBUG: true
7+
ELASTICSEARCH_NODE_NAME: elastic-1
8+
ELASTICSEARCH_CLUSTER_NAME: elastic
9+
ELASTICSEARCH_PASSWORD: qwerty
10+
ELASTICSEARCH_ENABLE_SECURITY: true
11+
ELASTICSEARCH_ENABLE_REST_TLS: false
12+
ELASTICSEARCH_TLS_VERIFICATION_MODE: none
13+
ELASTICSEARCH_TRANSPORT_TLS_KEYSTORE_LOCATION: /opt/bitnami/elasticsearch/config/certs/ca-elastic.p12
14+
ELASTICSEARCH_TRANSPORT_TLS_TRUSTSTORE_LOCATION: /opt/bitnami/elasticsearch/config/certs/ca-elastic.p12
15+
ELASTICSEARCH_CLUSTER_HOSTS: elastic-1,elastic-2,elastic-3
16+
ELASTICSEARCH_HEAP_SIZE: 1g
17+
ports:
18+
- "9200:9200"
19+
- "9300:9300"
20+
healthcheck:
21+
test: [ "CMD-SHELL", "curl --silent --fail --user elastic:qwerty localhost:9200/_cluster/health?local=true || exit 1" ]
22+
interval: 20s
23+
timeout: 20s
24+
retries: 10
25+
volumes:
26+
- elastic-1:/bitnami
27+
- ./certs/:/opt/bitnami/elasticsearch/config/certs/
28+
29+
elastic-2:
30+
image: "bitnami/elasticsearch:8.17.1"
31+
container_name: elastic-2
32+
environment:
33+
ELASTICSEARCH_NODE_NAME: elastic-2
34+
ELASTICSEARCH_CLUSTER_NAME: elastic
35+
ELASTICSEARCH_PASSWORD: qwerty
36+
ELASTICSEARCH_ENABLE_SECURITY: true
37+
ELASTICSEARCH_ENABLE_REST_TLS: false
38+
ELASTICSEARCH_TLS_VERIFICATION_MODE: none
39+
ELASTICSEARCH_TRANSPORT_TLS_KEYSTORE_LOCATION: /opt/bitnami/elasticsearch/config/certs/ca-elastic.p12
40+
ELASTICSEARCH_TRANSPORT_TLS_TRUSTSTORE_LOCATION: /opt/bitnami/elasticsearch/config/certs/ca-elastic.p12
41+
ELASTICSEARCH_CLUSTER_HOSTS: elastic-1,elastic-2,elastic-3
42+
ELASTICSEARCH_HEAP_SIZE: 1g
43+
ports:
44+
- "9201:9200"
45+
- "9301:9300"
46+
healthcheck:
47+
test: [ "CMD-SHELL", "curl --silent --fail --user elastic:qwerty localhost:9200/_cluster/health?local=true || exit 1" ]
48+
interval: 20s
49+
timeout: 20s
50+
retries: 10
51+
volumes:
52+
- elastic-2:/bitnami
53+
- ./certs/:/opt/bitnami/elasticsearch/config/certs/
54+
55+
elastic-3:
56+
image: "bitnami/elasticsearch:8.17.1"
57+
container_name: elastic-3
58+
environment:
59+
ELASTICSEARCH_NODE_NAME: elastic-3
60+
ELASTICSEARCH_CLUSTER_NAME: elastic
61+
ELASTICSEARCH_PASSWORD: qwerty
62+
ELASTICSEARCH_ENABLE_SECURITY: true
63+
ELASTICSEARCH_ENABLE_REST_TLS: false
64+
ELASTICSEARCH_TLS_VERIFICATION_MODE: none
65+
ELASTICSEARCH_TRANSPORT_TLS_KEYSTORE_LOCATION: /opt/bitnami/elasticsearch/config/certs/ca-elastic.p12
66+
ELASTICSEARCH_TRANSPORT_TLS_TRUSTSTORE_LOCATION: /opt/bitnami/elasticsearch/config/certs/ca-elastic.p12
67+
ELASTICSEARCH_CLUSTER_HOSTS: elastic-1,elastic-2,elastic-3
68+
ELASTICSEARCH_HEAP_SIZE: 1g
69+
ports:
70+
- "9202:9200"
71+
- "9302:9300"
72+
healthcheck:
73+
test: [ "CMD-SHELL", "curl --silent --fail --user elastic:qwerty localhost:9200/_cluster/health?local=true || exit 1" ]
74+
interval: 20s
75+
timeout: 20s
76+
retries: 10
77+
volumes:
78+
- elastic-3:/bitnami
79+
- ./certs/:/opt/bitnami/elasticsearch/config/certs/
80+
81+
kibana:
82+
image: "bitnami/kibana:8.17.1"
83+
container_name: kibana
84+
environment:
85+
KIBANA_CREATE_USER: yes
86+
KIBANA_PASSWORD: qwerty
87+
KIBANA_ELASTICSEARCH_PASSWORD: qwerty
88+
KIBANA_ELASTICSEARCH_URL: elastic-1
89+
ports:
90+
- "5601:5601"
91+
healthcheck:
92+
test: [ "CMD-SHELL", "curl --silent --fail localhost:5601/api/status || exit 1" ]
93+
interval: 15s
94+
timeout: 15s
95+
retries: 5
96+
volumes:
97+
- kibana:/bitnami/kibana
98+
depends_on:
99+
elastic-1:
100+
condition: service_healthy
101+
elastic-2:
102+
condition: service_healthy
103+
elastic-3:
104+
condition: service_healthy
105+
106+
volumes:
107+
elastic-1:
108+
elastic-2:
109+
elastic-3:
110+
kibana:

elastic/docker-compose.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
services:
22
elastic:
3-
image: elasticsearch:8.12.2
3+
image: "bitnami/elasticsearch:8.17.1"
44
container_name: elastic
55
environment:
6-
discovery.type: single-node
7-
node.name: elastics
8-
bootstrap.memory_lock: true
9-
cluster.routing.allocation.disk.threshold_enabled: false
10-
xpack.security.enabled: false
11-
ES_JAVA_OPTS: "-Xms1024m -Xmx1024m"
6+
ELASTICSEARCH_NODE_NAME: elastic
7+
ELASTICSEARCH_CLUSTER_NAME: elastic
8+
ELASTICSEARCH_ENABLE_SECURITY: false
9+
ELASTICSEARCH_ENABLE_REST_TLS: false
10+
ELASTICSEARCH_LOCK_ALL_MEMORY: true
11+
ELASTICSEARCH_HEAP_SIZE: 1g
1212
healthcheck:
13-
test: [ "CMD-SHELL", "curl -f http://localhost:9200/_cat/health | grep -q green" ]
13+
test: [ "CMD-SHELL", "curl --silent --fail --user elastic:qwerty localhost:9200/_cluster/health?local=true || exit 1" ]
1414
interval: 20s
1515
timeout: 20s
1616
retries: 10
@@ -21,10 +21,10 @@ services:
2121
- elastic:/usr/share/elasticsearch/data
2222

2323
kibana:
24-
image: kibana:8.12.2
24+
image: "bitnami/kibana:8.17.1"
2525
container_name: kibana
2626
environment:
27-
ELASTICSEARCH_HOSTS: http://elastic:9200
27+
KIBANA_ELASTICSEARCH_URL: elastic
2828
healthcheck:
2929
test: [ "CMD-SHELL", "curl --silent --fail localhost:5601/api/status || exit 1" ]
3030
interval: 20s

frontend/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Frontend
2+
3+
* [Simple](docker-compose.yml)

java/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Java
2+
3+
* [Simple](docker-compose.yml)

keycloak/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Keycloak
2+
3+
* [Keycloak + OpenLDAP](docker-compose.yml)

minio/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Minio
22

3+
* [Cluster](docker-compose.yml)
4+
35
```shell
46
$ mc alias set local http://localhost:9000 program qwerty123
57
$ mc mb local/my-bucket

mongo/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Mongo
2+
3+
* [Replica Set](docker-compose.yml)
4+
5+
```shell
6+
$ sudo tee -a /etc/hosts > /dev/null <<EOT
7+
127.0.0.1 mongo-primary
8+
127.0.0.1 mongo-secondary-1
9+
127.0.0.1 mongo-secondary-2
10+
EOT
11+
```
12+
13+
```shell
14+
$ docker-compose up -d --wait
15+
$ mongosh mongodb://localhost:27017,localhost:27018,localhost:27019/ -u program -p test
16+
```

mongo/docker-compose.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
services:
2+
mongo-primary:
3+
image: "bitnami/mongodb:8.0"
4+
container_name: mongo-primary
5+
platform: linux/amd64
6+
environment:
7+
- MONGODB_USERNAME=program
8+
- MONGODB_PASSWORD=test
9+
- MONGODB_DATABASE=services
10+
- MONGODB_ROOT_USER=program
11+
- MONGODB_ROOT_PASSWORD=test
12+
- MONGODB_REPLICA_SET_MODE=primary
13+
- MONGODB_REPLICA_SET_NAME=rs0
14+
- MONGODB_REPLICA_SET_KEY=replicaset
15+
- MONGODB_ADVERTISED_HOSTNAME=mongo-primary
16+
ports:
17+
- "27017:27017"
18+
healthcheck:
19+
test: [ "CMD-SHELL", "mongosh --eval 'quit((db.hello().isWritablePrimary || db.hello().secondary) ? 0 : 2)'" ]
20+
interval: 10s
21+
timeout: 5s
22+
retries: 5
23+
volumes:
24+
- mongo-master:/bitnami/mongodb
25+
26+
mongo-secondary-1:
27+
image: "bitnami/mongodb:8.0"
28+
container_name: mongo-secondary-1
29+
platform: linux/amd64
30+
environment:
31+
- MONGODB_PORT_NUMBER=27018
32+
- MONGODB_REPLICA_SET_MODE=secondary
33+
- MONGODB_ADVERTISED_HOSTNAME=mongo-secondary-1
34+
- MONGODB_INITIAL_PRIMARY_HOST=mongo-primary
35+
- MONGODB_INITIAL_PRIMARY_PORT_NUMBER=27017
36+
- MONGODB_INITIAL_PRIMARY_ROOT_USER=program
37+
- MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD=test
38+
- MONGODB_REPLICA_SET_NAME=rs0
39+
- MONGODB_REPLICA_SET_KEY=replicaset
40+
ports:
41+
- "27018:27018"
42+
healthcheck:
43+
test: [ "CMD-SHELL", "mongosh --port $$MONGODB_PORT_NUMBER --eval 'quit((db.hello().isWritablePrimary || db.hello().secondary) ? 0 : 2)'" ]
44+
interval: 10s
45+
timeout: 5s
46+
retries: 5
47+
volumes:
48+
- mongo-slave-1:/bitnami/mongodb
49+
depends_on:
50+
mongo-primary:
51+
condition: service_started
52+
53+
mongo-secondary-2:
54+
image: "bitnami/mongodb:8.0"
55+
container_name: mongo-secondary-2
56+
platform: linux/amd64
57+
environment:
58+
- MONGODB_PORT_NUMBER=27019
59+
- MONGODB_REPLICA_SET_MODE=secondary
60+
- MONGODB_ADVERTISED_HOSTNAME=mongo-secondary-2
61+
- MONGODB_INITIAL_PRIMARY_HOST=mongo-primary
62+
- MONGODB_INITIAL_PRIMARY_PORT_NUMBER=27017
63+
- MONGODB_INITIAL_PRIMARY_ROOT_USER=program
64+
- MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD=test
65+
- MONGODB_REPLICA_SET_NAME=rs0
66+
- MONGODB_REPLICA_SET_KEY=replicaset
67+
ports:
68+
- "27019:27019"
69+
healthcheck:
70+
test: [ "CMD-SHELL", "mongosh --port $$MONGODB_PORT_NUMBER --eval 'quit((db.hello().isWritablePrimary || db.hello().secondary) ? 0 : 2)'" ]
71+
interval: 10s
72+
timeout: 5s
73+
retries: 5
74+
volumes:
75+
- mongo-slave-2:/bitnami/mongodb
76+
depends_on:
77+
mongo-primary:
78+
condition: service_started
79+
80+
volumes:
81+
mongo-master:
82+
mongo-slave-1:
83+
mongo-slave-2:

monitoring/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Monitoring
2+
3+
* [Simple](docker-compose.yml)

patroni/README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# HA Postgres cluster with Patroni
2+
3+
* [Patroni](docker-compose.yml)
4+
5+
## Описание
6+
7+
Patroni — это шаблон для построения Postgres HA cluster из коробки. Он устанавливается на каждом сервере с базой
8+
данных и является своего рода init-системой для Postgres: запускает, останавливает, перезапускает, меняет конфигурацию и
9+
топологию кластера.
10+
11+
Patroni хранит состояние кластера в DCS (Distributed Configuration Store), это может быть один из вариантов: Etcd,
12+
Consul, ZooKeeper либо Etcd Kubernetes.
13+
14+
## Запуск
15+
16+
```shell
17+
$ docker exec -it patroni1 /bin/bash
18+
19+
$ patronictl --config-file /etc/patroni.yml topology cluster
20+
21+
+ Cluster: cluster -------+---------+---------+----+-----------+
22+
| Member | Host | Role | State | TL | Lag in MB |
23+
+------------+------------+---------+---------+----+-----------+
24+
| patroni2 | 172.22.0.6 | Leader | running | 1 | |
25+
| + patroni1 | 172.22.0.7 | Replica | running | 1 | 0 |
26+
| + patroni3 | 172.22.0.5 | Replica | running | 1 | 0 |
27+
+------------+------------+---------+---------+----+-----------+
28+
29+
# внутри контейнера
30+
$ psql -h patroni1 -p 5432 -U program -d services
31+
32+
# снаружи
33+
$ psql -h localhost -p 5001 -U program -d services
34+
35+
# если упал master и не подключается в роли slave
36+
$ patronictl --config-file /etc/patroni.yml reinit cluster patroni1
37+
```

0 commit comments

Comments
 (0)