Last active
May 21, 2021 17:39
-
-
Save Lh4cKg/ffc60c312586223ca5750fef5879ee99 to your computer and use it in GitHub Desktop.
Install and Configuration Python/Django/Virtualenv/Postgres/Nginx/uWSGI On CentOS 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# -*- MAINTAINER -*- Lasha Gogua Lh4cKg@gmail.com | |
# -*- RUN -*- $ bash install.sh | |
# system update and install epel package | |
yum install epel-release | |
# or | |
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm | |
rpm -ivh epel-release-7-5.noarch.rpm | |
yum update -y && yum upgrade -y | |
sudo yum install redhat-rpm-config | |
# install gcc package and other necessary packages | |
yum groupinstall 'Development Tools' -y | |
yum install vim -y | |
yum install mc -y | |
# install postgres latest version 9.6 | |
yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm | |
yum install postgresql96-server postgresql96-devel postgresql96-contrib -y | |
postgresql-setup initdb | |
# or | |
/usr/pgsql-9.6/bin/postgresql96-setup initdb | |
# use md5 insted of ident | |
vim /var/lib/pgsql/9.6/data/pg_hba.conf | |
systemctl start postgresql-9.6 | |
systemctl enable postgresql-9.6 | |
# configure postgresql.conf - parameters of your system http://pgtune.leopard.in.ua/ | |
max_connections = 100 | |
shared_buffers = 256MB | |
effective_cache_size = 768MB | |
work_mem = 2621kB | |
maintenance_work_mem = 64MB | |
min_wal_size = 1GB | |
max_wal_size = 2GB | |
checkpoint_completion_target = 0.7 | |
wal_buffers = 7864kB | |
default_statistics_target = 100 | |
fsync = off | |
synchronous_commit = off | |
full_page_writes = off | |
# create user and database | |
create user myuser with password 'myuserpass'; | |
create database mydb; | |
grant ALL privileges on database mydb to myuser; | |
# read this post - https://gist.github.com/Lh4cKg/4ef5f8fe46abd07819f1636501bfe27f | |
# backup database | |
pg_dump -Fc —username "postgres" —no-password —blobs —encoding UTF8 —verbose —file "/tmp/mydb_2017-07-22.backup" "mydb" | |
# restore database | |
pg_restore -d mydb /path/to/mydb_2017-07-22.backup | |
# also read this post for postgresql performance | |
# http://pydanny-event-notes.readthedocs.io/en/latest/DjangoConEurope2012/10-steps-to-better-postgresql-performance.html | |
# install nginx | |
yum install nginx -y | |
mv -f nginx.conf /etc/nginx/nginx.conf | |
systemctl start nginx | |
systemctl enable nginx | |
# nginx configure | |
# vim /etx/nginx/nginx.conf | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
server_tokens off; | |
systemctl restart nginx | |
# required libraries for Python installation | |
yum install libjpeg libjpeg-devel freetype-devel libpng-devel zlib zlib-devel krb5-devel openssl openssl-devel libffi libffi-devel gmp gmp-devel -y | |
# install Python.x.x version | |
# example: x.x.x = 3.3.6 => Python.3.3.6 or x.x.x=2.7.11 => Python.2.7.11 | |
wget http://python.org/ftp/python/x.x.x/Python-x.x.x.tgz | |
tar -xvf Python-x.x.x.tgz | |
mv -f Python-x.x.x /opt/ && cd /opt/Python-x.x.x | |
./configure | |
make && make altinstall | |
cd | |
# install pip | |
wget https://bootstrap.pypa.io/get-pip.py | |
# use Python version | python3.3 or python | |
pythonX.X get-pip.py | |
pip install uwsgi | |
pip install virtualenv | |
# create project and configure | |
virtualenv --python=pythonX.X --no-site-packages testenv | |
cd testenv && source bin/activate | |
# install latest version django, celery and RabbitMQ | |
# read this post | |
# https://gist.github.com/Lh4cKg/d17b5791563414ab3b1faabd0b5d5ebf | |
# install packages | |
pip install -r requirements.txt | |
# also read intresting post if you need | |
# https://gist.github.com/Lh4cKg/aa24c0e0532051d0800ca73e680be1e0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the upstream component nginx needs to connect to | |
upstream django { | |
#server unix:///home/<username>/env/<project_name>/project_name.sock; # for a file socket | |
server 127.0.0.1:8001; # for a web port socket (we'll use this first) | |
} | |
server { | |
listen 80; | |
server_name 46.101.88.90; # if you need ip addr load on www domain | |
rewrite ^ $scheme://www.your_domain.ge$request_uri redirect; | |
} | |
server { | |
listen 80; | |
server_name bukinistebi.ge; # if you need domain load on www | |
rewrite ^ $scheme://www.your_domain.ge$request_uri redirect; | |
} | |
# configuration of the server | |
server { | |
# the port your site will be served on | |
listen 80; | |
# the domain name it will serve for | |
server_name your_domain.ge www.your_domain.ge; # substitute your machine's IP address or FQDN | |
charset utf-8; | |
# max upload size | |
client_max_body_size 75M; # adjust to taste | |
# Django media | |
location /media { | |
alias /home/<project_name>/env/<project_name>/media; # your Django project's media files | |
} | |
location /static { | |
alias /home/<username>/env/<project_name>/static; # your Django project's static files | |
} | |
# Finally, send all non-media requests to the Django server. | |
location / { | |
uwsgi_pass django; | |
include /home/<username>/env/<project_name>/uwsgi_params; # the uwsgi_params file you installed | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PostgreSQL Client Authentication Configuration File | |
# =================================================== | |
# TYPE DATABASE USER ADDRESS METHOD | |
# "local" is for Unix domain socket connections only | |
local all all md5 | |
# IPv4 local connections: | |
host all all 127.0.0.1/32 md5 | |
# IPv6 local connections: | |
host all all ::1/128 md5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# project_uwsgi_production.ini file | |
# read this post for configure uwsgi | |
# http://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html | |
[uwsgi] | |
project = project_name | |
# Django-related settings | |
# the base directory (full path) | |
chdir = /home/user/project/source | |
# Django's wsgi file | |
module = %(project).wsgi:application | |
# the virtualenv (full path) | |
home = /home/user/venv | |
# export lang | |
env = LANG=en_US.UTF-8 | |
env = LC_ALL=en_US.UTF-8 | |
env = DJANGO_SETTINGS_MODULE=project_name.settings.prod | |
wsgi-file = /home/user/project/source/project_name/wsgi.py | |
# process-related settings | |
master = true | |
pidfile = /home/user/project/run/project.pid | |
# number of workers | |
#workers = 15 | |
# maximum number of worker processes | |
processes = 15 | |
# threads | |
#threads = 4 | |
max-requests = 50000 | |
# ... with appropriate permissions - may be needed | |
uid = user | |
gid = user | |
# the socket | |
socket = /var/run/muwsgi.sock | |
# use always this path | |
chown-socket = user:user | |
chmod-socket = 666 | |
# clear environment on exit | |
vacuum = true | |
enable-threads = true | |
single-interpreter = true | |
lazy-apps = false | |
# background the process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uwsgi_param QUERY_STRING $query_string; | |
uwsgi_param REQUEST_METHOD $request_method; | |
uwsgi_param CONTENT_TYPE $content_type; | |
uwsgi_param CONTENT_LENGTH $content_length; | |
uwsgi_param REQUEST_URI $request_uri; | |
uwsgi_param PATH_INFO $document_uri; | |
uwsgi_param DOCUMENT_ROOT $document_root; | |
uwsgi_param SERVER_PROTOCOL $server_protocol; | |
uwsgi_param REQUEST_SCHEME $scheme; | |
uwsgi_param HTTPS $https if_not_empty; | |
uwsgi_param REMOTE_ADDR $remote_addr; | |
uwsgi_param REMOTE_PORT $remote_port; | |
uwsgi_param SERVER_PORT $server_port; | |
uwsgi_param SERVER_NAME $server_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment