Comment installer plusieurs instances d’odoo9 sur un vps avec nginx en reverse proxy?
Odoo (anciennement appelé Open ERP) est un ERP libre plein de fonctionalités ceci faisant de lui l’ERP preféré des fans de l’open source. Très souvent, on est ammené à vouloir installer plussieur instance sur un meme serveur et ceci peut poser probleme au niveau des domaines.
Dans le tutoriel suivant, je vais vous montrer comment déployer étape apres étapes, deux instances de odoo 9 sur un VPS.
Prérequis:
Debian 9, odoo9, accès supper utilisateur.
- Connexion au VPS
ssh admin@yourdomain.tld
- Mise a jour des paquets
sudo apt-get update && sudo apt-get dist-upgrade
- Installation des dépendances odoo 9
sudo apt-get install python-dateutil python-docutils python-feedparser python-jinja2 python-ldap python-libxslt1 python-lxml python-mako python-mock python-openid python-psycopg2 python-psutil python-pybabel python-pychart python-pydot python-pyparsing python-reportlab python-simplejson python-tz python-unittest2 python-vatnumber python-vobject python-webdav python-werkzeug python-xlwt python-yaml python-zsi poppler-utils python-pip python-pyPdf python-passlib python-decorator Installation des utilitaires sudo apt-get install gcc python-dev mc bzr python-setuptools python-markupsafe python-reportlab-accel python-zsi python-yaml python-argparse python-openssl python-egenix-mxdatetime python-usb python-serial python-jinja2 python-unittest2 python-mock python-docutils lptools make python-pydot python-psutil python-paramiko poppler-utils python-pdftools antiword
- Installation des dépendances web d’Odoo
sudo apt-get install -y npm sudo ln -s /usr/bin/nodejs /usr/bin/node sudo npm install -g less less-plugin-clean-css
- Installation de PostgreSQL
sudo apt-get install python-software-properties sudo apt-get update sudo apt-get install postgresql-9.4
- Creation des Bases de données pour chacune des instances
sudo su postgres cd createuser -s odoo1 createuser -s odoo2 createuser -s system_name exit
- Creation des utilisateur odoo
sudo adduser --system --home=/opt/odoo1 --group odoo1 sudo adduser --system --home=/opt/odoo2 --group odoo2
- Téléchargement et installation des Gdata
cd /opt/odoo1 sudo wget https://fossies.org/linux/privat/gdata-2.0.18.tar.gz sudo tar zxvf gdata-2.0.18.tar.gz sudo chown -R odoo1: gdata-2.0.18 sudo -s cd gdata-2.0.18 python setup.py install exit cd /opt/odoo2 wget https://fossies.org/linux/privat/gdata-2.0.18.tar.gz sudo tar zxvf gdata-2.0.18.tar.gz sudo chown -R odoo1: gdata-2.0.18 sudo -s cd gdata-2.0.18/ python setup.py install exit
- Installation odoo
cd /opt/odoo1 sudo apt-get install git git clone https://www.github.com/odoo/odoo --depth 1 --branch 9.0 --single-branch sudo chown -R odoo1: odoo1 cd /opt/odoo2 git clone https://www.github.com/odoo/odoo --depth 1 --branch 9.0 --single-branch sudo chown -R odoo2: odoo2
- Creation des environnements virtuels de python
cd /opt/odoo1/odoo/ virtualenv ./venv source ./venv/bin/activate pip install -r requirements.txt cd /opt/odoo2/odoo/ virtualenv ./venv source ./venv/bin/activate pip install -r requirements.txt
- Création des fichiers log
sudo mkdir /var/log/odoo1 sudo touch /var/log/odoo1/odoo1.log sudo chown -R odoo1:root /var/log/odoo1 sudo mkdir /var/log/odoo2 sudo touch /var/log/odoo2/odoo2.log sudo chown -R odoo2:root /var/log/odoo2
- création des fichiers de configurations
sudo cp /opt/odoo1/odoo-9.0/debian/openerp-server.conf /etc/odoo1.conf sudo chown odoo: /etc/odoo1.conf sudo vim /etc/odoo1.conf #Copy and paste below content in config file , write correct addons paths [options] ; This is the password that allows database operations: admin_passwd = PASSWORD db_host = False db_port = False db_user = odoo1 db_password = False xmlrpc_port = 8001 addons_path = /opt/odoo1/odoo-9.0/addons ;Log settings logfile = /var/log/odoo1/odoo1.log log_level = error sudo cp /opt/odoo/odoo-9.0/debian/openerp-server.conf /etc/odoo2.conf sudo chown odoo: /etc/odoo2.conf sudo gedit /etc/odoo2.conf #Copy and paste below content in config file , write correct addons paths [options] ; This is the password that allows database operations: admin_passwd = PASSWORD db_host = False db_port = False db_user = odoo1 db_password = False xmlrpc_port = 8002 addons_path = /opt/odoo2/odoo-9.0/addons ;Log settings logfile = /var/log/odoo2/odoo2.log log_level = error
- Installation et configuration de NGINX
sudo apt-get install nginx cd /etc/nginx/sites-available/ sudo vim odoo1
## Odoo Backend ## upstream odooerp { server yourIP@:8001; } ## https site## server { listen 443 default_server; server_name odoo1domain.tld odoo1domain.tld; # log files access_log /var/log/nginx/odoo.access.log; error_log /var/log/nginx/odoo.error.log; # ssl files ssl on; ssl_ciphers ALL:!ADH:!MD5:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_certificate /etc/nginx/ssl/odoo.crt; ssl_certificate_key /etc/nginx/ssl/odoo.key; # proxy buffers proxy_buffers 16 64k; proxy_buffer_size 128k; ## odoo proxypass with https ## location / { proxy_pass http://odooerp; # force timeouts if the backend dies proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_redirect off; # set headers proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; } # cache some static data in memory for 60mins location ~* /web/static/ { proxy_cache_valid 200 60m; proxy_buffering on; expires 864000; proxy_pass http://odooerp; } } ## http redirects to https ## server { listen yourIP@:80; server_name odoo1domain.tld odoo1domain.tld; return 301 https://$server_name$request_uri; } ##Odoo2 configuration ## vim odoo2 ## Odoo Backend ## upstream odooerp2 { server yourIP@:8002; } ## https site## server { listen 443 default_server; server_name odoo2domain.tld odoo2domain.tld; # log files access_log /var/log/nginx/odoo.access.log; error_log /var/log/nginx/odoo.error.log; # ssl files ssl on; ssl_ciphers ALL:!ADH:!MD5:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_certificate /etc/nginx/ssl/odoo.crt; ssl_certificate_key /etc/nginx/ssl/odoo.key; # proxy buffers proxy_buffers 16 64k; proxy_buffer_size 128k; ## odoo proxypass with https ## location / { proxy_pass http://odooerp2; # force timeouts if the backend dies proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_redirect off; # set headers proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; } # cache some static data in memory for 60mins location ~* /web/static/ { proxy_cache_valid 200 60m; proxy_buffering on; expires 864000; proxy_pass http://odooerp2; } } ## http redirects to https ## server { listen yourIP@:80; server_name odoo2domain.tld odoo2domain.tld; return 301 https://$server_name$request_uri; }
Creation des repertoire ssl et generation des certificats
mkdir -p /etc/nginx/ssl cd /etc/nginx/ssl openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/odoo.key -out /etc/nginx/ssl/odoo.crt chmod 600 odoo.key ln -s /etc/nginx/sites/available/odoo1 /etc/nginx/sites-enabled/odoo1 ln -s /etc/nginx/sites/available/odoo2 /etc/nginx/sites-enabled/odoo2
- Test configuration
nginx -t
- Redémarrer NGINX
sudo service nginx restart
- Création des scripts de lancements
vim /lib/systemd/system/odoo1.service #copier et coller [Unit] Description=Odoo 1 Requires=postgresql.service After=postgresql.service [Service] Type=simple PermissionsStartOnly=true User=odoo1 Group=odoo1 SyslogIdentifier=odoo1 ExecStart=/opt/odoo1/odoo/venv/bin/python2 /opt/odoo1/odoo/openerp-server -c /etc/odoo.conf [Install] WantedBy=multi-user.target vim /lib/systemd/system/odoo2.service #copier et coller [Unit] Description=Odoo 2 Requires=postgresql.service After=postgresql.service [Service] Type=simple PermissionsStartOnly=true User=odoo2 Group=odoo2 SyslogIdentifier=odoo2 ExecStart=/opt/odoo2/odoo/venv/bin/python2 /opt/odoo2/odoo/openerp-server -c /etc/odoo2.conf [Install] WantedBy=multi-user.target
- Activation des instances Odoo1 et Odoo2
sudo systemctl enable odoo1.service sudo systemctl enable odoo2.service
- Configuration des services odoo1 et odoo2
sudo cp /opt/odoo/odoo-9.0/openerp-server /etc/init.d/odoo1 sudo chmod 755 /etc/init.d/odoo1 sudo chown root: /etc/init.d/odoo1 sudo cp /opt/odoo/odoo-9.0/openerp-server /etc/init.d/odoo2 sudo chmod 755 /etc/init.d/odoo2 sudo chown root: /etc/init.d/odoo2
- Démarrer les services Odoo
sudo service odoo1 start sudo service odoo2 start
- Ouvrez le navigateur et tester
http://localhost:8001 ou https://odoo1domain.tld
http://localhost:8002 ou https://odoo2domain.tld