mirror of
https://github.com/IntenseWebs/servercode.git
synced 2024-11-21 16:27:22 -06:00
Add Kubernetes, Major Updates to postgres-python3-django
This commit is contained in:
parent
95fabffee8
commit
50ce324cb2
13
kubernetes.txt
Normal file
13
kubernetes.txt
Normal file
@ -0,0 +1,13 @@
|
||||
https://www.youtube.com/watch?v=yn95Cv7Xr7Q
|
||||
kind, minicube, k3s
|
||||
|
||||
kind create cluster
|
||||
kns
|
||||
kctx
|
||||
kubectl apply -f app.yaml
|
||||
kubectl get pods
|
||||
kns
|
||||
kubectl get svc
|
||||
docker ps
|
||||
docker inspect cd45b1645d41 | grep 172
|
||||
docker inspect cd45b1645d41 | grep 192
|
143
postgres-pgadmin-python3-django-gunicorn-nginx
Normal file
143
postgres-pgadmin-python3-django-gunicorn-nginx
Normal file
@ -0,0 +1,143 @@
|
||||
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04
|
||||
https://tonyteaches.tech/django-nginx-uwsgi-tutorial/
|
||||
https://www.datadoghq.com/blog/nginx-502-bad-gateway-errors-gunicorn/#nginx-cant-access-the-socket
|
||||
OLD Writings (2008): Virtual MSCS Server w/ VMWare ESX 3.5 Server, Microsoft Server Cluster Services (MSCS), SQL Server 2005 Cluster, same physical box,Windows 2008 Server AD Domain Controller VM's, Group Policy, Lowest User Access Privileges Service Accounts for Audit Compliance
|
||||
sudo apt install python3-pip python3-dev python3-venv libpq-dev postgresql postgresql-contrib nginx curl
|
||||
sudo apt install virtualenv python3-virtualenv
|
||||
|
||||
su - postgres
|
||||
psql
|
||||
# ONLY DROP IF NEEDED TO FIX: DROP DATABASE MYDATABASE;
|
||||
CREATE USER MYDBUSERNAME WITH PASSWORD 'MYDBPASSWORD' CREATEDB;
|
||||
CREATE DATABASE MYDATABASE WITH OWNER MYDBUSERNAME;
|
||||
ALTER ROLE MYDBUSERNAME SET client_encoding TO 'utf8';
|
||||
ALTER ROLE MYDBUSERNAME SET default_transaction_isolation TO 'read committed';
|
||||
ALTER ROLE MYDBUSERNAME SET timezone TO 'UTC';
|
||||
GRANT ALL PRIVILEGES ON DATABASE MYDATABASE TO MYDBUSERNAME;
|
||||
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO MYDBUSERNAME;
|
||||
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO MYDBUSERNAME;
|
||||
grant postgres to MYDBUSERNAME
|
||||
\q
|
||||
|
||||
sudo adduser MYUSERNAME
|
||||
sudo usermod -aG sudo MYUSERNAME
|
||||
su - MYUSERNAME
|
||||
|
||||
# sudo ufw allow 5432
|
||||
# sudo vi /etc/postgresql/15/main/postgresql.conf
|
||||
listen_addresses = 'localhost, 192.168.1.3, 192.168.1.6, 192.168.1.7, 192.168.1.66, 192.168.1.123, 192.168.1.126, 192.168.1.127, 192.168.1.222'
|
||||
|
||||
# sudo vi /etc/postgresql/15/main/pg_hba.conf
|
||||
local MYDATABASE MYDBUSERNAME scram-sha-256
|
||||
host MYDATABASE MYDBUSERNAME 192.168.1.0/24 scram-sha-256
|
||||
|
||||
# TEST DATABASE CONNECTION
|
||||
psql "postgres://MYDBUSERNAME@192.168.1.6/MYDATABASE"
|
||||
|
||||
mkdir ~/env
|
||||
python3 -m venv /home/MYUSERNAME/env/MYPROJECTDIR
|
||||
ls ~/env/MYPROJECTDIR/bin
|
||||
source ~/env/MYPROJECTDIR/bin/activate
|
||||
which python
|
||||
pip install Django gunicorn psycopg2-binary
|
||||
django-admin startproject iwebcity
|
||||
cd iwebcity
|
||||
vi ~/iwebcity/iwebcity/settings.py
|
||||
ALLOWED_HOSTS = ['.iweb.city', '.localhost', '127.0.0.1', '[::1]', '192.168.1.6']
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'MYDATABASE',
|
||||
'USER': 'MYDBUSERNAME',
|
||||
'PASSWORD': 'MYDBPASSWORD',
|
||||
'HOST': 'localhost',
|
||||
'PORT': '',
|
||||
}
|
||||
}
|
||||
STATIC_URL = '/static/'
|
||||
import os
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
|
||||
|
||||
~/iwebcity/manage.py makemigrations
|
||||
~/iwebcity/manage.py migrate
|
||||
~/iwebcity/manage.py createsuperuser
|
||||
~/iwebcity/manage.py collectstatic
|
||||
|
||||
# sudo ufw allow 8001
|
||||
# TEST DJANGO PYTHON INCLUDED WEBSERVER ONLY - REBOOT TO APPLY ALL FIREWALL AND POSTGRES CHANGES
|
||||
~/iwebcity/manage.py runserver 0.0.0.0:8001
|
||||
gunicorn --bind 0.0.0.0:8001 iwebcity.wsgi
|
||||
deactivate
|
||||
_______________________________________________________________
|
||||
|
||||
vi /etc/systemd/system/gunicorn.socket
|
||||
[Unit]
|
||||
Description=gunicorn socket
|
||||
[Socket]
|
||||
ListenStream=/run/gunicorn.sock
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
|
||||
vi /etc/systemd/system/gunicorn.service
|
||||
Unit]
|
||||
Description=gunicorn daemon
|
||||
Requires=gunicorn.socket
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=serv
|
||||
Group=nginx
|
||||
WorkingDirectory=/home/serv/iwebcity
|
||||
ExecStart=/home/serv/env/MYPROJECTDIR/bin/gunicorn \
|
||||
--access-logfile - \
|
||||
--workers 3 \
|
||||
--bind unix:/run/gunicorn.sock \
|
||||
iwebcity.wsgi:application
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
_______________________________________________________________
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl restart gunicorn
|
||||
systemctl start gunicorn.socket
|
||||
systemctl enable gunicorn.socket
|
||||
systemctl enable gunicorn.service
|
||||
systemctl status gunicorn.socket
|
||||
curl --unix-socket /run/gunicorn.sock localhost
|
||||
sudo journalctl -u gunicorn
|
||||
sudo tail -F /var/log/nginx/error.log
|
||||
file /run/gunicorn.sock
|
||||
namei -l /run/gunicorn.sock
|
||||
The following logs may be helpful:
|
||||
Check the Nginx process logs: sudo journalctl -u nginx
|
||||
Check the Nginx access logs: sudo less /var/log/nginx/access.log
|
||||
Check the Nginx error logs: sudo less /var/log/nginx/error.log
|
||||
Check the Gunicorn application logs: sudo journalctl -u gunicorn
|
||||
Check the Gunicorn socket logs: sudo journalctl -u gunicorn.socket
|
||||
_______________________________________________________________
|
||||
#NGINX
|
||||
|
||||
vi dj.iweb.city.conf
|
||||
upstream django {
|
||||
server unix:///home/iw/iwebcity/iwebcity.sock;
|
||||
}
|
||||
# configuration of the server
|
||||
server {
|
||||
listen 8001;
|
||||
server_name django.iweb.city www.django.iweb.city dj.iweb.city;
|
||||
charset utf-8;
|
||||
# max upload size
|
||||
client_max_body_size 75M;
|
||||
# Django media and static files
|
||||
location /media {
|
||||
alias /home/iw/iwebcity/media;
|
||||
}
|
||||
location /static {
|
||||
alias /home/iw/iwebcity/static;
|
||||
}
|
||||
# Send all non-media requests to the Django server.
|
||||
location / {
|
||||
uwsgi_pass django;
|
||||
include /home/iw/iwebcity/uwsgi_params;
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04
|
||||
# sudo apt install python3 python3-pip
|
||||
# NORMAL USER - INSTALL PYTHON VIRTUAL ENVIRONMENT & OPEN FIREWALL PORTS
|
||||
|
||||
sudo apt-get install python3-venv
|
||||
|
||||
mkdir ~/env
|
||||
python3 -m venv /home/iw/env/firstenv
|
||||
ls ~/env/firstenv/bin
|
||||
source ~/env/firstenv/bin/activate
|
||||
which python
|
||||
pip install Django gunicorn
|
||||
# pip install uwsgi --use-pep517
|
||||
django-admin startproject iwebcity
|
||||
cd iwebcity
|
||||
~/iwebcity/manage.py makemigrations
|
||||
python ~/iwebcity/manage.py migrate
|
||||
~/iwebcity/manage.py createsuperuser
|
||||
|
||||
vi ~/iwebcity/iwebcity/settings.py
|
||||
ALLOWED_HOSTS = ['.iweb.city', '.localhost', '127.0.0.1', '[::1]', '192.168.1.6']
|
||||
|
||||
|
||||
# TEST DJANGO PYTHON INCLUDED WEBSERVER ONLY
|
||||
python manage.py runserver 0.0.0.0:8000
|
||||
|
||||
~/iwebcity/manage.py makemigrations
|
||||
python ~/iwebcity/manage.py migrate
|
||||
~/iwebcity/manage.py collectstatic
|
||||
|
||||
cd ~/iwebcity
|
||||
vi test.py
|
||||
def application(env, start_response):
|
||||
start_response('200 OK', [('Content-Type','text/html')])
|
||||
return [b"Hello World!"]
|
||||
|
||||
_________________________________________________________________________
|
||||
|
||||
source ~/env/firstenv/bin/activate
|
||||
cd ~/iwebcity
|
||||
# ~/iwebcity/manage.py runserver 0.0.0.0:8001
|
||||
|
||||
gunicorn --bind 0.0.0.0:8001 iwebcity.wsgi
|
||||
|
||||
vi /etc/systemd/system/gunicorn.socket
|
||||
[Unit]
|
||||
Description=gunicorn socket
|
||||
|
||||
[Socket]
|
||||
ListenStream=/run/gunicorn.sock
|
||||
SocketUser=www-data
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
|
||||
vi /etc/systemd/system/gunicorn.service
|
||||
[Unit]
|
||||
Description=gunicorn daemon
|
||||
Requires=gunicorn.socket
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=iw
|
||||
Group=www-data
|
||||
WorkingDirectory=/home/iw/iwebcity
|
||||
ExecStart=/home/iw/iwebcity/env/bin/gunicorn \
|
||||
--access-logfile - \
|
||||
--workers 3 \
|
||||
--bind unix:/run/gunicorn.sock \
|
||||
iwebcity.wsgi:application
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
systemctl start gunicorn.socket
|
||||
systemctl enable gunicorn.socket
|
||||
systemctl status gunicorn.socket
|
||||
file /run/gunicorn.sock
|
||||
|
||||
|
||||
_______________________________________________________________
|
||||
#NGINX
|
||||
|
||||
vi dj.iweb.city.conf
|
||||
upstream django {
|
||||
server unix:///home/iw/iwebcity/iwebcity.sock;
|
||||
}
|
||||
# configuration of the server
|
||||
server {
|
||||
listen 8001;
|
||||
server_name django.iweb.city www.django.iweb.city dj.iweb.city;
|
||||
charset utf-8;
|
||||
# max upload size
|
||||
client_max_body_size 75M;
|
||||
# Django media and static files
|
||||
location /media {
|
||||
alias /home/iw/iwebcity/media;
|
||||
}
|
||||
location /static {
|
||||
alias /home/iw/iwebcity/static;
|
||||
}
|
||||
# Send all non-media requests to the Django server.
|
||||
location / {
|
||||
uwsgi_pass django;
|
||||
include /home/iw/iwebcity/uwsgi_params;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user