Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mohit4buntikki authored Aug 2, 2024
1 parent 7e43a1e commit fcedf03
Showing 1 changed file with 53 additions and 10 deletions.
63 changes: 53 additions & 10 deletions common/db/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,60 @@
### Generating Key Pair for DB
### STEP 1 Generating Key Pair for DB

1. RUN `ssh-keygen -t rsa` to generate a key pair
2. Set value of `cat ~/.ssh/id_rsa | base64 -w 0` in DB_SSH_PRIVATE_KEY (change the location of private key in command if needed)
3. Set value of `cat ~/.ssh/id_rsa.pub | base64 -w 0` in DB_SSH_PUBLIC_KEY (change the location of private key in command if needed)
A. RUN `ssh-keygen -t rsa` to generate a key pair
B. Set value of `cat ~/.ssh/id_rsa | base64 -w 0` in DB_SSH_PRIVATE_KEY (change the location of private key in command if needed)
C. Set value of `cat ~/.ssh/id_rsa.pub | base64 -w 0` in DB_SSH_PUBLIC_KEY (change the location of private key in command if needed)

### Steps to follow after the db container is started (only if you have enabled barman)
### Step 2 Follow after the db container is started (only if you have enabled barman)

1. Currently the ssh server doesn't start automatically, run `docker exec -it DB_CONTAINER_ID /usr/sbin/sshd` to start the ssh server inside the db container
A. Currently the ssh server doesn't start automatically, run `docker exec -it DB_CONTAINER_ID /usr/sbin/sshd` to start the ssh server inside the db container
B. Create barman and streaming_barman user in postgres to setup barman disaster recovery later.

`docker exec -it DB_CONTAINER_ID bash`

`su - postgres`

`createuser --superuser --replication -P barman` password you set will be needed to setup barman later.

`createuser --replication -P streaming_barman` password you set will be needed to setup barman later

Now exit from container using `exit` command twice.

C. Copy the public key of postgres user which is required to setup barman later, run `docker exec -it DB_CONTAINER_ID cat /var/lib/postgresql/.ssh/id_rsa.pub` to get the public key.

### Steps to setup Barman
### Step 3 Follow to setup Barman.
A. Switch to root user `sudo -i`
B. Create a DNS entry in /etc/hosts file for postgres server.

1. Run `make setup-barman` to setup barman
`vi /etc/hosts` edit the file and add `POSTGRES_IP mydb` replace POSTGRES_IP with actual IP address of postgres container/server and mydb with name you want to set this domain name is required while setting up barman.

C. Run `make setup-barman` in barman server to setup barman, provide the following value when asked :
```
- HOSTNAME/DOMAIN name of your server (e.g mydb.example.com , mydb) which you have set in previous step.
- Database name for which backup needs to be created (e.g postgres or any database name).
- Password of user 'barman' which was created while configuring barman user in STEP 2.B.
- Password of user 'streaming_barman' which was created while configuring streaming_barman user in STEP 2.B.
```

D. Switch to barman user and generate the barman key pair.

`su - barman`

`ssh-keygen -t rsa`

E. Add the postgres public key (refer to STEP 2.C) in .ssh/authorized_keys file located in barman's home directory.

`vi ~/.ssh/authorized_keys` paste the public key of postgres user.

F. Copy the public key of barman user and paste it in the postgres user's authorized_keys running in container

`cat ~/.ssh/id_rsa.pub` copy the content

#### STEP 4 connect to postgres container and add public key of barman to postgres user's authorized key.

`docker exec -it CONTAINER_ID bash`

`su - postgres`

`vi ~/.ssh/authorized_keys`

> [!NOTE]

> 1. We will require the public key generated here while we setup Barman

0 comments on commit fcedf03

Please sign in to comment.