This repository has been archived by the owner on Jan 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Admin Sys
Jpy edited this page Apr 26, 2018
·
39 revisions
setup de base 'step-by-step' pour installer python et mongodb sur un container LXC Ubuntu 16.04 PROXMOX ( voir aussi les explications de Bastien ici et son screencast )
- CONFIGURATION DE BASE DU SERVEUR - from here
- users...
- public key auth...
- disable pwd auth...
- INSTALL BASIC STUFF
$ sudo apt-get update
$ sudo apt install vim
- INSTALL GIT - from here
$ sudo apt-get update
$ sudo apt-get install git
< create a dir for the app and pull code >
$ cd ~
$ mkdir my_app
$ cd my_app
$ git init .
$ git remote add origin https://github.com/entrepreneur-interet-general/<your repo eig>.git
$ git pull origin master
- INSTALL NGINX
$ sudo apt-get update
$ sudo apt-get install nginx
< update firewall >
$ sudo ufw app list
$ sudo ufw allow 'Nginx HTTP'
$ sudo ufw status
< check nginx status >
$ systemctl status nginx
< enable nginx at reload >
$ sudo systemctl enable nginx
< create a nginx conf file for the app >
$ cd /etc/nginx/sites-available
$ sudo vim my_app
< copy this in file >
# Enumerate all the Tornado servers here
upstream frontends {
server YOUR_SERVER_IP_HERE:8000;
server YOUR_SERVER_IP_HERE:8001;
}
server {
listen YOUR_SERVER_IP_HERE:8000;
server_name http://YOUR_DOMAIN_NAME_HERE;
location / {
try_files $uri @tornado;
}
# increase allowed header size to accept large URI in the case of an API/GET
client_header_buffer_size 128k ;
large_client_header_buffers 4 128k;
location @tornado {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://frontends;
}
}
< Enable the server configuration we just made by linking it to the sites-enabled directory >
$ sudo ln -s /etc/nginx/sites-available/my_app /etc/nginx/sites-enabled
< check for syntax errors >
$ sudo service nginx configtest
$ sudo service nginx restart
< if needed >
$ sudo systemctl stop nginx
$ sudo systemctl start nginx
$ sudo systemctl restart nginx
$ sudo systemctl reload nginx
$ sudo systemctl disable nginx
$ systemctl status nginx
- INSTALL MONGO DB (community edition) - from here
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
$ echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org
- RUN MONGODB - from here
< start mongo >
$ sudo systemctl start mongod
< enable automatically starting MongoDB when the system starts >
$ sudo systemctl enable mongod
< to check if mongo is running >
$ sudo systemctl status mongod
< or open a mongo shell >
$ mongo
- IF YOU NEED TO CONNECT TO DISTANT MONGODB FROM OUTSIDE
< allow port 27017 to your IP only >
sudo ufw allow from you_IP_adress_here/32 to any port 27017
< in server change bindIp 0.0.0.0 instead of 127.0.0.1 >
sudo vim /etc/mongod.conf
>>>
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
sudo systemctl restart mongod
- SETUP FIREWALL - from here
sudo apt-get install ufw
sudo ufw status
< Using IPv6 with UFW >
sudo vim /etc/default/ufw
IPV6=yes
< set default >
sudo ufw default deny incoming
sudo ufw default allow outgoing
< allow ports >
sudo ufw allow OpenSSH
sudo ufw allow ssh
sudo ufw allow ftp
sudo ufw allow www
sudo ufw allow 80
sudo ufw allow 8000
sudo ufw allow 8001
< if you want to access to mongodb from ext >
sudo ufw allow 27017
< if you want to access to mongodb from specific Ops >
sudo ufw allow from XXX.XXX.X.XXX proto udp to any port 27017
< if you want to allow some specific port range >
sudo ufw allow 8000:8010/tcp
< if you want to allow some specific address >
sudo ufw allow from XXX.XXX.X.XXX
< check which apps are allowed >
sudo ufw app list
< enable UFW >
sudo ufw enable
sudo ufw status
- INSTALL PYTHON BASIC TOOLS
$ sudo apt-get update
$ sudo apt-get install build-essential python-dev python-setuptools python-mysqldb
<here more stuff in case you got those needs fort specific pip libs>
$ sudo apt-get install libssl-dev libffi-dev python-psycopg2 libgnutls-dev libcurl4-gnutls-dev
- INSTALL PIP - from here
$ sudo apt-get install python-pip
$ sudo pip install --upgrade pip
$ pip install --upgrade setuptools
- INSTALL YOUR REQUIREMENTS
$ cd <your repo folder where is stored requirements.txt >
$ pip install -r requirements.txt
- INSTALL SUPERVISOR (daemonize
$ sudo apt-get update
$ sudo apt-get install supervisor
< create your supervisor conf file >
$ sudo vim /etc/supervisor/conf.d/my_app.conf
< add those lines >
[group:tornadoes]
programs=my_program_8000, my_program_8001
[program:my_program_1]
command=python main.py --port:8000
directory=/home/user_name/my_app/my_main_py_folder
user=user_name
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/tornado.log
loglevel=info
[program:my_program_8001]
command=python main.py --port:8001
directory=/home/user_name/my_app/my_main_py_folder
user=user_name
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/tornado.log
loglevel=info
- HEROKU / python : https://devcenter.heroku.com/articles/getting-started-with-python#introduction
- CLEVERCLOUD : https://www.clever-cloud.com/
- DIGITAL OCEAN : https://www.digitalocean.com/