Cài đặt odoo 13 trên Centos7

Cài đặt odoo 13 trên Centos7

Chuẩn bị cài đặt

sudo yum -y install epel-release wget vim bash-completion git unzip nano

sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

Cài đặt PostgreSQL 12 on CentOS 7

file conf:

nano /var/lib/pgsql/12/data/postgresql.confnano /var/lib/pgsql/12/data/pg_hba.conf

Cài đặt PostgreSQL 12

sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

rpm -qi pgdg-redhat-repo

sudo yum -y install epel-release yum-utils
sudo yum-config-manager --enable pgdg12
sudo yum install postgresql12-server postgresql12

sudo /usr/pgsql-12/bin/postgresql-12-setup initdb

sudo systemctl enable --now postgresql-12

systemctl status postgresql-12

Sửa file /var/lib/pgsql/12/data/pg_hba.conf

nano /var/lib/pgsql/12/data/pg_hba.conf

Tìm dòng

# IPv4 local connections:host all all 127.0.0.1/32 ident

Thay bằng

host all all 127.0.0.1/32 md5

Mở cổng Firewall

sudo firewall-cmd --add-service=postgresql --permanent
sudo firewall-cmd --reload

Tạo User

sudo su - postgres
psql

CREATE USER odoo13 WITH PASSWORD '123456';
CREATE DATABASE odoo13_db;
GRANT ALL PRIVILEGES ON DATABASE "odoo13_db" to odoo13;
alter role odoo13_user with superuser createdb;

Restart postgresql12

sudo systemctl restart postgresql-12
sudo systemctl status postgresql-12

Test kết nối

psql -U odoo13_user -h 127.0.0.1 -p 5432 odoo13_db

Cài đặt Odoo 13 on CentOS 7

Cài Python 3

yum install python3

Cài các pakage liên quan

yum install git gcc wget nodejs-less libxslt-devel bzip2-devel openldap-devel libjpeg-devel freetype-devel
yum install python3-devel libxml2-devel libxslt1-devel libldap2-devel libsasl2-devel
yum install -y libpng libjpeg openssl icu libX11 libXext libXrender xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi

Cài Odoo từ Source

Cài đặt wkhtmltopdf

sudo yum install -y https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox-0.12.5-1.centos7.x86_64.rpm

yum install wkhtmltopdf

wkhtmltopdf --version

Tạo user Odoo

useradd -m -U -r -d /opt/odoo -s /bin/bash odoo

Clone source code odoo13 từ github

git clone https://www.github.com/odoo/odoo --depth 1 --branch 13.0 /opt/odoo/odoo13

Cài các requirements

pip3 install --upgrade pip
pip3 install wheel
pip3 install -r /opt/odoo/odoo13/requirements.txt

Tạo file cấu hình odoo

nano /etc/odoo.conf

Nội dung

[options]
;This is the password that allows database operations:
#admin_passwd = master_password
db_host = 127.0.0.1
db_port = 5432
db_user = odoo13
db_password = 123456
addons_path = /opt/odoo/odoo13/addons
; You can enable log file with uncommenting the next line
logfile = /var/log/odoo13/odoo.log
; If you are using custom modules
; addons_path = /opt/odoo/odoo12/addons,/opt/odoo/odoo12-custom-addons

Tạo file dịch vụ odoo13 chạy như service của hệ điều hành

nano /etc/systemd/system/odoo13.service

Nội dung

[Unit]
Description=Odoo13
Requires=postgresql-12.service
After=network.target postgresql-12.service
[Service]
Type=simple
SyslogIdentifier=odoo13
PermissionsStartOnly=true
User=odoo
Group=odoo
ExecStart=/usr/bin/python3 /opt/odoo/odoo13/odoo-bin -c /etc/odoo.conf
StandardOutput=journal+console
[Install]
WantedBy=multi-user.target

Tạo log files

mkdir /var/log/odoo13/

touch /var/log/odoo13/odoo.log

Restart odoo13

systemctl enable odoo13

systemctl restart odoo13

Cài đặt Nginx Proxy (With SSL Certificate)

Cài đặt Nginx

sudo yum -y install nginx
sudo systemctl enable --now nginx

Cài đặt certbot-auto

wget https://dl.eff.org/certbot-auto
chmod +x certbot-auto
sudo mv certbot-auto /usr/local/bin/certbot-auto

Cấu hình nginx

sudo systemctl stop nginx

Mở cổng firewall

firewall-cmd --permanent --add-port=80/tcp

firewall-cmd --permanent --add-port=443/tcp

firewall-cmd --reload

Tạo chứng chỉ

export DOMAIN="erp.jdc.vn"
export EMAIL="erp@jdc.vn"
sudo /usr/local/bin/certbot-auto certonly --standalone -d ${DOMAIN} --preferred-challenges http --agree-tos -n -m ${EMAIL} --keep-until-expiring

Tạo cronjob cho certbot-auto

sudo crontab -e

15 3 * * * /usr/local/bin/certbot-auto renew --pre-hook "systemctl stop nginx" --post-hook "systemctl start nginx"

Tạo file cấu hình nginx cho odoo

nano /etc/nginx/conf.d/odoo.conf

Nội dung

# Odoo Upstreams
upstream odooserver {
server 127.0.0.1:8069;
}

# http to https redirection
server {
listen 80;
server_name erp.jdc.vn;
return 301 https://erp.jdc.vn$request_uri;
}

server {
listen 443 ssl;
server_name erp.jdc.vn;
access_log /var/log/nginx/odoo_access.log;
error_log /var/log/nginx/odoo_error.log;

# SSL
ssl_certificate /etc/letsencrypt/live/erp.jdc.vn/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/erp.jdc.vn/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/erp.jdc.vn/chain.pem;

# Proxy settings
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
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;

# Request for root domain
location / {
proxy_redirect off;
proxy_pass http://odooserver;
}

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

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

Test cấu hình

sudo nginx -t

Nếu OK thì khởi động Nginx

Khởi động Nginx

sudo systemctl restart nginx

 

Article Attachments

Was this article helpful?

Leave A Comment?

This site uses Akismet to reduce spam. Learn how your comment data is processed.