Odoo is the world's most popular all-in-one business software. CRM, website, e-Commerce, billing, accounting, manufacturing, wareho...
Odoo is the world's most popular all-in-one business software. CRM, website, e-Commerce, billing, accounting, manufacturing, warehouse, project management, inventory, and many more business systems are all seamlessly connected.
Odoo can be installed in a variety of methods, based on the use case and technology available. Using the official Odoo APT repository is the simplest and fastest approach to install Odoo.
Odoo may be installed in a virtual environment or as a Docker container, giving you more control over the programme and allowing you to run many Odoo instances on the same server.
This article describes how to install and run Odoo 14 on CentOS 8 in a Python virtual environment. We'll use Nginx as a reverse proxy and download Odoo from the official GitHub repository.
Installing Prerequisites
Odoo is written in Python. The first step is to install Python 3 , Git, pip , and all the libraries and tools required to build Odoo from source:
$ sudo dnf install python3 python3-devel git gcc sassc redhat-rpm-config libxslt-devel \
bzip2-devel openldap-devel libjpeg-devel freetype-devel
Creating a System User
It is not permitted to run Odoo as the root user, as this poses a security risk. Create a new system user and group for the Odoo service, with a home directory of /opt/odoo:
$ sudo useradd -m -U -r -d /opt/odoo14 -s /bin/bash odoo14
You can give the user any name you choose, as long as you also establish a PostgreSQL user with the same name.
PostgreSQL Installation and Configuration
The database backend of Odoo is PostgreSQL. We'll use the normal CentOS 8 repository to install PostgreSQL 12:
$ sudo dnf install @postgresql:12
Once the installation is completed, create a new PostgreSQL database cluster:
$ sudo postgresql-setup initdb
Enable and start the PostgreSQL service:
$ sudo systemctl enable --now postgresql
Create a PostgreSQL user with the same name as the previously created system user. In this example, that is odoo14:
$ sudo su - postgres -c "createuser -s odoo14"
Installing Wkhtmltopdf
wkhtmltopdf is a collection of open-source command-line programmes for converting HTML pages to PDF and other image formats. You'll need to install the wkhtmltox package in Odoo to print PDF reports. Odoo version 0.12.5 is suggested, and it may be downloaded and installed from Github:
$ sudo dnf install https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox-0.12.5-1.centos8.x86_64.rpm
Installing and Configuring Odoo 14
We’ll install Odoo from the source inside an isolated Python virtual environment.
First, change to user “odoo14”:
$ sudo su - odoo14
Clone the Odoo 14 source code from the Odoo GitHub repository:
$ git clone https://www.github.com/odoo/odoo --depth 1 --branch 14.0 /opt/odoo14/odoo
Navigate to the /opt/odoo14 directory and create a new Python virtual environment for the Odoo installation:
$ cd /opt/odoo14 $ python3 -m venv venv
Activate the environment using the source command:
$ source venv/bin/activate
Install the required Python modules:
(venv) $ pip3 install -r odoo/requirements.txt
You can press the Tab key, which will autocomplete the filename.
- [message]
- If you encounter any compilation error during the installation, make sure all required dependencies listed in the Installing Prerequisites section are installed.
Once done, deactivate the environment by typing:
(venv) $ deactivate
Create a new directory for the custom addons:
$ mkdir /opt/odoo14/odoo-custom-addons
We’ll add this directory to the addons_path parameter. This parameter defines a list of directories where Odoo searches for modules.
Switch back to your sudo user:
$ exit
Create a configuration file with the following content:
$ sudo nano /etc/odoo14.conf
- [message]
- /etc/odoo14.conf
[options]
admin_passwd = superadmin_passwd
db_host = False
db_port = False
db_user = odoo14
db_password = False
addons_path = /opt/odoo14/odoo/addons, /opt/odoo14/odoo-custom-addons
Save and close the file.
- [message]
- Do not forget to change the superadmin_passwd to something more secure.
Creating Systemd Unit File
$ sudo nano /etc/systemd/system/odoo14.service
Paste the following content:
- [message]
- /etc/systemd/system/odoo14.service
[Unit] Description=Odoo14 Requires=postgresql.service After=network.target postgresql.service [Service] Type=simple SyslogIdentifier=odoo14 PermissionsStartOnly=true User=odoo14 Group=odoo14 ExecStart=/opt/odoo14/venv/bin/python3 /opt/odoo14/odoo/odoo-bin -c /etc/odoo14.conf StandardOutput=journal+console [Install] WantedBy=multi-user.target
Notify systemd that a new unit file exists:
$ sudo systemctl daemon-reload
Start and enable the Odoo service:
$ sudo systemctl enable --now odoo14
Verify that Odoo is running with the following command:
$ sudo systemctl status odoo14
The output should look something like below, showing that the Odoo service is active and running:
Output ● odoo14.service - Odoo14 Loaded: loaded (/etc/systemd/system/odoo14.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2020-11-02 20:12:24 UTC; 3s ago ...
To see the messages logged by the Odoo service, use the following command:
$ sudo journalctl -u odoo14
Test the Installation
Open your browser and type: http://<your_domain_or_IP_address>:8069
Assuming the installation is successful, a screen similar to the following will appear:
If you can’t access the page, make sure port 8069 is open in your firewall :
$ sudo firewall-cmd --permanent --zone=public --add-port=8069/tcp $ sudo firewall-cmd --reload
Configuring Nginx as SSL Termination Proxy
The HTTP protocol is used by the Odoo web server by default. We'll configure Nginx as an SSL termination proxy that will deliver traffic over HTTPS to make the Odoo instance more secure.
A proxy server that handles SSL encryption and decryption is known as an SSL termination proxy. This indicates that the terminating proxy (Nginx) will examine and decrypt incoming TLS (HTTPS) connections before passing unencrypted requests to the internal service (Odoo). There will be no encryption between Nginx and Odoo communications (HTTP).
Load balancing, SSL termination, caching, compression, serving static content, and more are all advantages of using a reverse proxy.
Ensure that you have met the following prerequisites before continuing with this section:
- Domain name pointing to your public server IP. We’ll use example.com.
- Nginx installed .
- SSL certificate for your domain. You can install a free Let’s Encrypt SSL certificate .
Open your text editor and create/edit the domain server block:
$ sudo nano /etc/nginx/conf.d/example.com
The following configuration sets up SSL Termination, HTTP to HTTPS redirection , WWW to non-WWW redirection, cache the static files, and enable GZip compression.
- [message]
- /etc/nginx/conf.d/example.com
[# Odoo servers upstream odoo { server 127.0.0.1:8069; } upstream odoochat { server 127.0.0.1:8072; } # HTTP -> HTTPS server { listen 80; server_name www.example.com example.com; include snippets/letsencrypt.conf; return 301 https://example.com$request_uri; } # WWW -> NON WWW server { listen 443 ssl http2; server_name www.example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem; include snippets/ssl.conf; return 301 https://example.com$request_uri; } server { listen 443 ssl http2; server_name example.com; proxy_read_timeout 720s; proxy_connect_timeout 720s; proxy_send_timeout 720s; # Proxy headers proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; # SSL parameters ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem; include snippets/ssl.conf; include snippets/letsencrypt.conf; # log files access_log /var/log/nginx/odoo.access.log; error_log /var/log/nginx/odoo.error.log; # Handle longpoll requests location /longpolling { proxy_pass http://odoochat; } # Handle / requests location / { proxy_redirect off; proxy_pass http://odoo; } # Cache static files location ~* /web/static/ { proxy_cache_valid 200 90m; proxy_buffering on; expires 864000; proxy_pass http://odoo; } # Gzip gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript; gzip on; }]
- [message]
- Don’t forget to replace example.com with your Odoo domain and set the correct path to the SSL certificate files. The snippets used in this configuration are created in this guide .
Once you’re done, restart the Nginx service :
$ sudo systemctl restart nginx
Next, we need to tell Odoo to use the proxy. To do so, open the configuration file and add the following line:
- [message]
- /etc/odoo14.conf
- proxy_mode = True
Restart the Odoo service for the changes to take effect:
$ sudo systemctl restart odoo14
At this point, the reverse proxy is configured, and you can access your Odoo instance at https://example.com.
Changing the Binding Interface
This step is optional, but it is a good security practice.
By default, the Odoo server listens to port 8069 on all interfaces. To disable direct access to the Odoo instance, you can either block port 8069 for all public interfaces or force Odoo to listen only on the local interface.
We’ll configure Odoo to listen only on 127.0.0.1. Open the configuration add the following two lines at the end of the file:
- [message]
- /etc/odoo14.conf
xmlrpc_interface = 127.0.0.1 netrpc_interface = 127.0.0.1
Save the configuration file and restart the Odoo server for the changes to take effect:
$ sudo systemctl restart odoo14
Enabling Multiprocessing
Odoo runs in multithreading mode by default. It is suggested that production deployments switch to the multiprocessing server since it improves stability and makes better use of system resources.
You must change the Odoo configuration and set a non-zero number of worker processes to enable multiprocessing. The number of employees is determined by the number of CPU cores and the amount of RAM available.
According to the official Odoo documentation , to calculate the workers' number and required RAM memory size, you can use the following formulas and assumptions:
Worker number calculation
- Theoretical maximal number of worker = (system_cpus * 2) + 1
- 1 worker can serve ~= 6 concurrent users
- Cron workers also require CPU
RAM memory size calculation
- We will consider that 20% of all requests are heavy requests, and 80% are lighter ones. Heavy requests are using around 1 GB of RAM while the lighter ones are using around 150 MB of RAM
- Needed RAM = number_of_workers * ( (light_worker_ratio * light_worker_ram_estimation) + (heavy_worker_ratio * heavy_worker_ram_estimation) )
If you do not know how many CPUs you have on your system, use the following grep command:
$ grep -c ^processor /proc/cpuinfo
Let’s say you have a system with 4 CPU cores, 8 GB of RAM memory, and 30 concurrent Odoo users.
- 30 users / 6 = **5** (5 is theoretical number of workers needed )
- (4 * 2) + 1 = **9** ( 9 is the theoretical maximum number of workers)
Based on the calculation above, you can use 5 workers + 1 worker for the cron worker, a total of 6 workers.
Calculate the RAM consumption based on the number of workers:
- RAM = 6 * ((0.8*150) + (0.2*1024)) ~= 2 GB of RAM
The calculation shows that the Odoo installation will need around 2GB of RAM.
To switch to multiprocessing mode, open the configuration file and append the calculated values:
- [message]
- /etc/odoo14.conf
limit_memory_hard = 2684354560 limit_memory_soft = 2147483648 limit_request = 8192 limit_time_cpu = 600 limit_time_real = 1200 max_cron_threads = 1 workers = 5
Restart the Odoo service for the changes to take effect:
$ sudo systemctl restart odoo14
Other services that operate on this system will utilise the remaining system resources. We installed Odoo, PostgreSQL, and Nginx on the same server in this guide. Other services may be operating on your server, depending on your setup.
Conclusion
This post demonstrated how to install Odoo 14 in a Python virtual environment using Nginx as a reverse proxy on CentOS 8. We've also demonstrated how to set up multiprocessing and optimise Odoo for use in a production setting.
COMMENTS