Toplam Sayfa Görüntüleme Sayısı

20 Haziran 2019 Perşembe

VAGRANT ile KURULAN SANAL SUNUCU ÜZERİNDE DJANGO FRAMEWORK İÇEREN DOCKER KONTEYNER OLUŞTURMAK

Selamlar, uzun zaman oldu görüşmeyeli. İki yıl kadar :)


Bu paylaşımda Vagrant ile sanal bir sunucu kurup (Centos 7.4), bu sunucu üzerinde iki docker container oluşturup, Django Framework ve reverse proxy konfigürasyonu yapılmış nginx kurulumları yapacağız.


Kurulum yapılan ortam: Ubuntu MATE "18.04.2" LTS

Hızlıca kurulum adımlarını listeliyorum.

1-) VAGRANT KULLANARAK SANAL MAKİNE OLUŞTURMAK

a) sudo su
b) lsb_release -a

c) apt-get update && apt-get install virtualbox && apt-get install vagrant
d) vagrant version

e) mkdir ~/vagrant_barikat
f) cd vagrant_barikat
g) vagrant init centos/7
h) vagrant up
i) vagrant ssh
j) virtualbox
2-) SANAL MAKİNEDE DOCKER SERVİS KURULUMU ve KONTEYNER OLUŞTURMA

  • ssh vagrant@localhost -p 2222 -i 


/home/mocal/vagrant_barikat/.vagrant/machines/default/virtualbox/private_key

  •  sudo su
  •  yum install -y yum-utils device-mapper-persistent-data lvm2
  •  yum-config-manager –add-repo https://download.docker.com/linux/centos/docker-ce.repo
  •  yum install docker-ce docker-ce-cli containerd.io
  •  systemctl enable docker
  •  systemctl start docker
  •  docker run hello-world

Nginx docker container



  • docker pull nginx
  • network create --subnet=172.18.0.0/16 mocalnet
  • docker run --name nginx -d nginx
  • docker cp nginx:/etc/nginx /home/vagrant/nginx
  • yum install nano
  • nano /home/vagrant/nginx.conf
  • mkdir sites-enabled
  • nano sites-enabled/app1

  • cd ~
  • touch hosts
  • nano hosts

  • docker run -d -m 75MB --oom-kill-disable --memory-swappiness=0 --name nginx -v 
    /home/vagrant/hosts:/etc/hosts -v /home/vagrant/nginx.conf:/etc/nginx/nginx.conf:ro -v
    /home/vagrant/sites-enabled:/etc/nginx/sites-enabled -h nginx --net mocalnet --ip 172.18.0.2 -p 8080:80 nginx
  • docker ps

Django docker container

• python –version
• pip –version
• pip install django
• python -c "import django; print(django.get_version())"
• django-admin startproject mocal
• cd mocal
• nano requirements.txt
• nano Dockerfile
• cd mocal
• nano setttins.py --> ALLOWED_HOSTS = ['127.0.0.1',’app-1’]

• cd ~
• docker build -t venv
• docker run -d --name app-1 -h app-1 --net mocalnet --ip 172.18.0.3 -v
/home/vagrant/hosts:/etc/hosts -v /home/vagrant/mocal:/usr/src/app -p 9000:8000 venv
• docker ps

http://127.0.0.1:8080

• docker images

Sistem Tapoloji


Bonus
WatchDog Shell Script


#!/bin/sh
#author: Mehmet ÖCAL
while true
do
#
echo "" > /root/system.log
date=`date "+%d-%m-%Y"`
time=`date +%H:%M:%S`
ram=`free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'`
disk=`df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}'`
cpu=`top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}'`
echo -e "$date\n \
$time\n \
$ram\n \
$disk\n \
$cpu\n " >> /root/system.log
#
a=`free -m | awk 'NR==3{printf "Memory Usage: %s/%sMB %.f\n", $3,$2,$3*100/$2 }' | awk '{ print $4}'`
if [ $a -ge 40 ]; then
echo "Swap alan temizleniyor `sh -c "sync; echo 3 > /proc/sys/vm/drop_caches" && sh -c "swapoff -a && swapon -a"`" >>
/root/system.log
else
echo "Swap alan normal" >> /root/system.log
fi
sleep 5
done



-----------------------------------------------------------------------------------------
• nano watchdog2.sh
• nano /etc/systemd/system/watchdog.service

• systemctl daemon-reload
• systemctl enable watchdog.service
• systemctl start watchdog.service

• systemctl status watchdog.service

• tail -f /root/system.log

Bir başka paylaşımda görüşmek üzere. Kendinize iyi bakın.




Hiç yorum yok: