rpm -Uvh https://yum.postgresql.org/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
yum install postgresql10-server postgresql10
/usr/pgsql-10/bin/postgresql-10-setup initdb
edit the following two conf files, configure who can access the site and what address the site listens to.
/var/lib/pgsql/10/data/postgresql.conf
/var/lib/pgsql/10/data/pg_hba.conf
CREATE DATABASE azendb;
CREATE USER azen WITH ENCRYPTED PASSWORD ‘password’;
GRANT ALL PRIVILEGES ON DATABASE azendb TO azen;
$ python manage.py migrate
$ python manage.py makemigrations blogs
$ python manage.py migrate
pg_dump azendb > azendb.bak
psql azendb < azendb.bak
crontab to back up data regularly:
59 23 * * * /usr/bin/pg_dump “host=localhost hostaddr=127.0.0.1 port=5432 user=azen password=azen dbname=azendb” > azendb.bak
sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm
sudo yum update
sudo yum install -y python36u python36u-libs python36u-devel python36u-pip
Remember that yum, firewall-cmd, urlgrabber use python 2.7. Modify python files’ first line when necessary.
Pull codes
cd /var/www
git clone git@github.com:xxx/xx.git (pull codes through ssh)
set up venv
python -m venv venv4zen
activate the virtual environment
source ./venv4azen/bin/activate
pip3 install Django
pip3 install Django-Markdownx
deactivate
pip3 install psycopg2-binary
pip3 install uwsgi
make uwsgi.service file so that uWSGI can work as a deamon
touch /etc/systemd/system/uwsgi.service
[Unit]
Description = uWSGI Emperor
After = syslog.target
[Service]
ExecStart=/usr/local/bin/uwsgi --ini /etc/uwsgi/emperor.ini
ExecStop = kill -INT `cat /run/uwsgi.pid`
ExecReload = kill -TERM `cat /run/uwsgi.pid`
Restart = always
Type = notify
NitifyAccess = main
PIDFile = /run/uwsgi.pid
[Install]
Wantedby=multi-user.target
create uwsgi user.
useradd uwsgi -s /bin/false
create file /etc/uwsgi/emperor.ini
[uwsgi]
emperor = /etc/uwsgi/vassals
uid = uwsgi
gid = nginx
logto = /etc/uwsgi/log
create file azen.ini under /etc/uwsgi/vassals
[uwsgi]
socket = 127.0.0.1:3030
chdir = /var/www/azen
venv = /var/www/venv4azen
wsgi-file = azen/wsgi.py
uid = uwsgi
gid = nginx
#uwsgi --socket 127.0.0.1:3030 --chdir /var/www/azen --venv /var/www/azen/venv4azen --wsgi-file azen/wsgi.py --master --processes 4 --threads 2 --logto /etc/uwsgi/log
configure a file azen.conf under /etc/nginx/conf.d/
server{
listen 80 default_server;
listen [::]:80 default_server;
server_name 192.168.56.101;
error_log /var/www/azen/log/error_log;
access_log /var/www/azen/log/access_log;
charset utf-8;
location /static/ {
alias /var/www/azen/static/;
}
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3030;
}
}
https://gist.github.com/mtigas/952344