Target deployment diagram
Our target deployment environment in AWS is like above diagram. we have two odoo system running on two AWS EC2 Ubuntu instances, the two instances will share odoo data file using AWS EFS, so the two odoo instances can share same data files. All requests will go to AWS load balancer via domain name on 80 port. The Postgresql12 database setup in AWS RDS instance, odoo instance1, instance2 remotely connect to the Postgresql12 RDS instance, so the two odoo instances always share the same databse.
1, Setup AWS RDS PostgreSQL Instance
- Go to Amzon RDS services, create PostgreSQL 12.3 Database following the instructions. if you need public access outside the VPC, make sure you check the ‘Public accessibility’ options to ‘Yes’.
- After DB created, you will get the Endpoint details like:
database-postgresql1-test.xxxxx-southeast-1.rds.amazonaws.com - Check the database security group, make sure it allow access on the DB port
- Connect to DB instance, the host is your RDS DB instance Endpoint
psql --host=database-postgresql1-test.xxxxx-southeast-1.rds.amazonaws.com --port=5432 --username=postgres --password --dbname=postgres
- Create odoo user: odoo12 and database: odoo
postgres=> CREATE ROLE odoo12;
CREATE ROLE
postgres=> GRANT odoo12 TO postgres;
GRANT ROLE
postgres=> CREATE DATABASE odoo OWNER = odoo12;
CREATE DATABASE
- Restore the database from existing odoo EC2 instance.
If you want to migrate existing DB to the RDS odoo DB, you need login the EC2 instance, dump the existing db to sql file, then restore it to the RDS DB instance. In EC2 instance, do below:
# dump existing db to sql file:
$ pg_dump -h localhost -p 5432 -U odoo12 odoo > db_backup.sql
#restore the dump file to RDS DB instance, host is the instance Endpoint
$ psql -f db_backup.sql --host database-postgresql1-test.xxxxx-southeast-1.rds.amazonaws.com --port 5432 --username odoo12 --dbname odoo
2, Setup AWS Elastic File System
- Go to AWS EFS services and follow the instructions to create EFS, this EFS will attach to our two EC2 odoo instances later.
- Mount the EFS in the two EC2 instances, directory name like ‘efs’, the EFS directory can only be accessed by root user after mount, need to change the directory owner to odoo user. we have odoo12 user in the EC2 instance, change owner:
sudo chown odoo12:odoo12 /efs
3, Config odoo instances
- Login both EC2 instances, that you can see and access the EFS directory.
- Copy your odoo data file to this EFS directory
- Config the two odoo instances to connect to the RDS Postgresql instance and also change the data_dir to the EFS directory. Change db_host to the Endpoint of RDS instance.
db_host = database-postgresql1-test.xxxxx-southeast-1.rds.amazonaws.com
data_dir = /opt/efs/data/Odoo
- Start odoo service for both instance1 and 2.
4, Create Load Balancer in AWS
- Create load balancer in AWS
- Register the two odoo EC2 instances to the created load balancer
- Refer to article below for the details of setup domain and load balancer.
Setup Odoo12 service in AWS