top of page

Hướng dẫn cài Odoo 14 trên Ubuntu 20.04

Writer's picture: Tuan NguyenTuan Nguyen



Mình triển khai theo mô hình microservice, chia thành 3 thành phần: App (Odoo14), Database (PostgreSQL), Reverse proxy (Nginx)



Nginx


Cài đặt Nginx #

$ sudo apt-get update
$ sudo apt-get install nginx
$ sudo systemctl status nginx

Cài đặt Let's Encrypt #

$ sudo apt-get update
$ sudo apt-get install certbot -y

Generating Strong Dh (Diffie-Hellman) Group #

$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

Obtaining a Let’s Encrypt SSL certificate #

$ sudo mkdir -p /var/lib/letsencrypt/.well-known
$ sudo chgrp www-data /var/lib/letsencrypt
$ sudo chmod g+s /var/lib/letsencrypt
$ sudo nano /etc/nginx/snippets/letsencrypt.conf

Nội dung file letsencrypt.conf

location ^~ /.well-known/acme-challenge/ {
	allow all;
	root /var/lib/letsencrypt/;
	default_type "text/plain";
try_files $uri =404;
}
$ sudo nano /etc/nginx/snippets/ssl.conf

Nội dung file ssl.conf

ssl_dhparam /etc/ssl/certs/dhparam.pem;

ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers on;

ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 30s;

add_header Strict-Transport-Security "max-age=31536000; 
includeSubDomains" always;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;

Cài đặt Nginx server block #

Nhớ đổi thành tên miền của các bạn nhé

$ sudo rm /etc/nginx/sites-enabled/default
$ sudo rm /etc/nginx/sites-available/default
$ sudo nano /etc/nginx/site-availeble/nguyentolab.com.conf

Nội dung file nguyentolab.com.conf

server {
  listen 80;
  server_name nguyentolab.com;
}
$ sudo ln -s /etc/nginx/sites-available/nguyentolab.com.conf /etc/nginx/sites-enabled/
$ sudo systemctl restart nginx
$ sudo certbot certonly --agree-tos --email admin@nguyentolab.com --webroot -w /var/lib/letsencrypt/ -d nguyentolab.com

Nếu chạy lệnh trên không báo lỗi thì bạn đã có được certificate free của Let's Encrypt

Bây giờ chúng ta chỉnh sửa nginx server block file để add certificate vào website của bạn

$ sudo nano /etc/nginx/sites-available/nguyentolab.com.conf

Nội dung file nguyentolab.com.conf

server {
listen 80;
server_name nguyentolab.com;
include snippets/letsencrypt.conf;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl http2;
server_name www.nguyentolab.com;
ssl_certificate /etc/letsencrypt/live/nguyentolab.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/nguyentolab.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/nguyentolab.com/chain.pem;
include snippets/ssl.conf;include snippets/letsencrypt.conf;
return 301 https://nguyentolab.comg$request_uri;
}
server {
listen 443 ssl http2;
server_name nguyentolab.com;
ssl_certificate /etc/letsencrypt/live/nguyentolab.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/nguyentolab.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/nguyentolab.com/chain.pem;
include snippets/ssl.conf;
include snippets/letsencrypt.conf;
}
$ sudo systemctl reload nginx

Truy cập vào web server nginx để kiểm tra cấu hình https đã thành công hay chưa.

Auto-renewing Let’s Encrypt SSL certificate #

$ sudo nano /etc/letsencrypt/cli.ini

Thêm dòng sau vào file

deploy-hook = systemctl reload nginx

Chạy lệnh bên dưới để kiểm tra, nếu không lỗi thì certificate sẽ tự động gia hạn mới khi hết hạn 90 ngày.

$ sudo certbot renew --dry-run

Cấu hình nginx server block truy cập Odoo #

$ sudo nano /etc/nginx/sites-available/nguyentolab.com.conf

Nội dung file nguyentolab.com.conf đầy đủ như sau:


# Odoo14
upstream odoo14 {
  server 192.168.1.12:8069;
}

upstream odoochat {
 server 192.168.1.12:8072;
}

# HTTP -> HTTPS
server {
  listen 80;
  server_name nguyentolab.com;

  include snippets/letsencrypt.conf;
  return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name www.nguyentolab.com;

    ssl_certificate /etc/letsencrypt/live/nguyentolab.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/nguyentolab.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/nguyentolab.com/chain.pem;
    include snippets/ssl.conf;
    include snippets/letsencrypt.conf;

    return 301 https://nguyentolab.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name nguyentolab.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/nguyentolab.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/nguyentolab.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/nguyentolab.com/chain.pem;
    include snippets/ssl.conf;
    include snippets/letsencrypt.conf;


    # Log file
    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://odoo14;
    }

    # Cache static files
    location ~* /web/static/ {
        proxy_cache_valid 200 90m;
        proxy_buffering on;
        expires 864000;
        proxy_pass http://odoo14;
    }

    # Gzip
    gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
    gzip on;

}

PostgreSQL

$ sudo apt update
$ sudo apt install postgresql postgresql-contrib

Tạo postgreSQL user role cho Odoo

$ sudo su - postgres psql -c "createuser -s odoo-usr-db"

Cấu hình cho phép Odoo remote vào PostgreSQL

$ sudo nano /etc/postgresql/12/main/postgresql.conf

Bỏ comment và sửa dòng sau thành

listen_addresses = '*'
$ sudo nano /etc/postgresql/12/main/pg_hba.conf

Thêm dòng sau vào file, trong đó IP là của Odoo

host    all             all     192.168.1.12/32         trust
$ sudo systemctl restart postgresql

Odoo

Cài đặt các thư viện cần thiết #

$ sudo apt update
$ sudo apt-get install git python3-pip build-essential wget python3-dev python3-venv python3-wheel libfreetype6-dev libxml2-dev libzip-dev libldap2-dev libsasl2-dev python3-setuptools node-less libjpeg-dev zlib1g-dev libpq-dev libxslt1-dev libldap2-dev libtiff5-dev libjpeg8-dev libopenjp2-7-dev liblcms2-dev libwebp-dev libharfbuzz-dev libfribidi-dev libxcb1-dev -y

Cài đặt wkhtmltopdf #

$ sudo apt install ./wkhtmltox_0.12.6-1.bionic_amd64.deb

Tạo user chạy dịch vụ Odoo #

$ sudo useradd -m -d /opt/odoo14 -U -r -s /bin/bash odoo14

Login bằng user odoo14

$ sudo su - odoo14
$ mkdir -p /data/odoo14
$ cd /data/odoo14
$ git clone https://www.github.com/odoo/odoo --depth 1 --branch 14.0

Cài đặt virtual environment và cài các thư viện #

$ python3 -m venv odoo-venv
$ source odoo-venv/bin/activate
(venv) $ pip3 install wheel
(venv) $ pip3 install -r requirements.txt
(venv) $ deactivate

Tạo directory để lưu trữ các custom addons

$ mkdir -p /data/odoo14/odoo/custom-addons
$ exit

Tạo file cấu hình cho Odoo #

$ sudo nano /etc/odoo14.conf

Nội dung file odoo14.conf:

[options]
admin_passwd = my_admin_passwd
db_host = 192.168.1.11        ; IP PostgreSQL server
db_port = 5432
db_user = odoo-usr-db   ;user postgresql đã tạo trong PostgreSQL server
db_password = False
addons_path = /data/odoo14/odoo/addons,/data/odoo14/odoo/custom-addons
proxy_mode = True        ; Dùng Nginx làm reverse proxy

Tạo Systemd Unit File #

$ sudo nano /etc/systemd/system/odoo14.service

Nội dung file odoo14.service

[Unit]
Description=Odoo14
# Requires=postgresql.service
# After=network.target postgresql.service

[Service]
Type=simple
SyslogIdentifier=odoo14
PermissionsStartOnly=true
User=odoo14    # User đã tạo để chạy dịch vụ Odoo
Group=odoo14   # Group cùng tên lúc tạo user ở trên
ExecStart=/data/odoo14/odoo/odoo-venv/bin/python3 /data/odoo14/odoo/odoo-bin -c /etc/odoo14.conf
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now odoo14

Truy cập vào tên miền cấu hình ở bước cài Nginx sẽ chuyển hướng sang trang Odoo.


53 views0 comments

Комментарии


 

© 2018 by Tuấn Nguyễn

 Liên hệ tôi
  • Facebook - Black Circle
  • Google+ - Black Circle
bottom of page