cs151094
5 years ago
commit
57333d9f11
4 changed files with 181 additions and 0 deletions
@ -0,0 +1,37 @@ |
|||||
|
Για την εγκατάσταση την υπηρεσίας προαπετείται η δημηιουργία docker-swarm |
||||
|
Αφού έχουμε φτιάξει το docker-swarm θα πρέπει |
||||
|
|
||||
|
1) Να φτιάξουμε ένα network sto docker (Αυτές οι εντολές γίνονται από το Manager) |
||||
|
|
||||
|
# docker network create --driver overlay mongo-net |
||||
|
|
||||
|
2) Να βάλουμε Labels σε όλα τα nodes |
||||
|
|
||||
|
# docker node update --label-add group=mongo snf... |
||||
|
|
||||
|
3) Τρέχουμε το docker-compose.yml |
||||
|
|
||||
|
docker stack deploy -c docker-compose.yml mongodb |
||||
|
|
||||
|
4) Βρίσκουμε το container που τρέχει η υπηρεσία μας |
||||
|
|
||||
|
#docker ps |
||||
|
|
||||
|
5) Μπαίνουμε στο container |
||||
|
|
||||
|
#docker exec -it <container-id> /bin/bash |
||||
|
|
||||
|
6)Μπαίνουμε στo shell του mongoDB |
||||
|
|
||||
|
/# mongo |
||||
|
|
||||
|
7)Initialise the replica set |
||||
|
|
||||
|
rs.initiate ({ _id: "test-rs", members: [ { _id: 1, host: "mongo-1:27017"}, { _id: 2, host: "mongo-2:27017"}, { _id: 3, host : "mongo-3:27017"}] } ) |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
Για την είσοδο στην βάση χρησιμοποιούμε το Robo3T το οποίο έιναι ένα οπτικό εργαλείο για να διαχειριστούμε την βάσης μας |
||||
|
|
||||
|
|
@ -0,0 +1,8 @@ |
|||||
|
|
||||
|
#MOngoDB-Replica |
||||
|
Η εργασία αφορά την δημιουργία μιας βάσης δεδομένων MongoDB σε docker. Πιο συγκεκριμένα επιτυγχάνεται το replication μιας MongoDB βάσης δεδομένων δηλαδή η δημιουργία 2 αντιγραφών της βάσης σε δύο διαφορετικά μηχανήματα που σε περίπτωση αποτυχίας του κύριου υπολογιστή το replica set θα αποφασίσει ποιος θα πάρει την θέση του κύριου υπολογιστή. |
||||
|
'Εγινε και η ανεπιτυχής προσπάθεια χρήσης reverse nginx proxy στο mongodb-replica set . |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1,100 @@ |
|||||
|
version: "3.7" |
||||
|
|
||||
|
|
||||
|
services: |
||||
|
mongo-1: |
||||
|
image: mongo:4 |
||||
|
command: ["mongod","--replSet","test-rs"] |
||||
|
networks: |
||||
|
- mongo-net |
||||
|
ports: |
||||
|
- "27020:27017" |
||||
|
- "28020:28017" |
||||
|
volumes: |
||||
|
# where mongo stores data |
||||
|
- mongo-data-1:/data/db |
||||
|
#where mongo stores its config files |
||||
|
- mongo-config-1:/data/configdb |
||||
|
deploy: |
||||
|
mode: replicated |
||||
|
replicas: 1 |
||||
|
# restart service everytime it fails |
||||
|
restart_policy: |
||||
|
condition: on-failure |
||||
|
placement: |
||||
|
constraints: |
||||
|
- node.labels.mongo.replica==1 |
||||
|
|
||||
|
mongo-2: |
||||
|
image: mongo:4 |
||||
|
command: ["mongod","--replSet","test-rs"] |
||||
|
networks: |
||||
|
- mongo-net |
||||
|
ports: |
||||
|
- "27021:27017" |
||||
|
- "28021:28017" |
||||
|
volumes: |
||||
|
- mongo-data-2:/data/db |
||||
|
- mongo-config-2:/data/configdb |
||||
|
deploy: |
||||
|
mode: replicated |
||||
|
replicas: 1 |
||||
|
restart_policy: |
||||
|
condition: on-failure |
||||
|
placement: |
||||
|
constraints: |
||||
|
- node.labels.mongo.replica==2 |
||||
|
|
||||
|
|
||||
|
mongo-3: |
||||
|
image: mongo:4 |
||||
|
command: ["mongod","--replSet","test-rs"] |
||||
|
networks: |
||||
|
- mongo-net |
||||
|
ports: |
||||
|
- "27022:27017" |
||||
|
- "28022:28017" |
||||
|
volumes: |
||||
|
# where mongo stores data |
||||
|
- mongo-data-3:/data/db |
||||
|
#where mongo stores its config files |
||||
|
- mongo-config-3:/data/configdb |
||||
|
deploy: |
||||
|
mode: replicated |
||||
|
replicas: 1 |
||||
|
# restart service everytime it fails |
||||
|
restart_policy: |
||||
|
condition: on-failure |
||||
|
placement: |
||||
|
constraints: |
||||
|
- node.labels.mongo.replica==3 |
||||
|
|
||||
|
web: |
||||
|
image: nginx |
||||
|
depends_on: |
||||
|
- mongodb |
||||
|
networks: |
||||
|
- mongo-net |
||||
|
ports: |
||||
|
- 80:80 |
||||
|
- 443:443 |
||||
|
volumes: |
||||
|
- /home/user/mongodb/reverse_proxy/nginx.conf:/etc/nginx/stream/conf.d/default.conf |
||||
|
|
||||
|
networks: |
||||
|
mongo-net: |
||||
|
external: true |
||||
|
volumes: |
||||
|
mongo-data-1: |
||||
|
mongo-config-1: |
||||
|
mongo-data-2: |
||||
|
mongo-config-2: |
||||
|
mongo-data-3: |
||||
|
mongo-config-3: |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1,36 @@ |
|||||
|
upstream mongodb { |
||||
|
server 83.212.77.66:28017; |
||||
|
server 83.212.77.74:28017; |
||||
|
server 83.212.77.49:28017; |
||||
|
|
||||
|
} |
||||
|
proxy_cache_path /var/tmp levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off; |
||||
|
server { |
||||
|
listen 80; |
||||
|
listen [::]:80; |
||||
|
server_name mongodb.example.org$request_uri; |
||||
|
location / { |
||||
|
return 301 https://83.212.77.66; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
server { |
||||
|
listen 443 default_server; |
||||
|
listen [::]:443 http2 ssl default_server; |
||||
|
server_name nginx; |
||||
|
|
||||
|
# Your favorite resolver may be used instead of the Google one below |
||||
|
resolver 8.8.4.4 8.8.8.8 valid=300s; |
||||
|
resolver_timeout 10s; |
||||
|
root /var/www; |
||||
|
index index.html; |
||||
|
location /nginx-status { |
||||
|
default_type application/json; |
||||
|
return 200 '{"code":"1", "message": "Healthcheck OK"}'; |
||||
|
} |
||||
|
location ~^/(contacts|app-back-status) { |
||||
|
proxy_pass http://app-back:3000; |
||||
|
proxy_set_header Host $host; |
||||
|
proxy_set_header X-Real-IP $remote_addr; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue