-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path03-pgbouncer-install.sh
53 lines (47 loc) · 2.07 KB
/
03-pgbouncer-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
#####################################################################################################
# This script will install PgBouncer on your Ubuntu 16.04 server.
# Author: Mohamed Hammad
#----------------------------------------------------------------------------------------------------
# Make a new file:
# sudo nano 03-pgbouncer-install.sh
# Place this content in it and then make the file executable:
# sudo chmod +x 03-pgbouncer-install.sh
# Execute the script to install Postgres:
# sudo ./03-pgbouncer-install.sh
#######################################################################################################
MASTER_IP="192.168.1.10"
SLAVE_IP="192.168.1.11"
ODOO_DB_USER="odoo"
ODOO_DB_PASS="odoo"
#--------------------------------------------------
# Update Server
#--------------------------------------------------
echo -e "\n---- Update Server ----"
sudo apt update
sudo apt upgrade -yV
#--------------------------------------------------
# Install PgBouncer
#--------------------------------------------------
echo -e "\n---- Install PgBouncer ----"
sudo apt install postgresql-client pgbouncer -yV
echo -e "\n---- Configure PgBouncer ----"
sudo sed -i "s/;\* = host=testserver/* = host=$MASTER_IP/g" /etc/pgbouncer/pgbouncer.ini
sudo sed -i "s/listen_addr = 127.0.0.1/listen_addr = 0.0.0.0/g" /etc/pgbouncer/pgbouncer.ini
sudo sed -i "s/auth_type = trust/auth_type = md5/g" /etc/pgbouncer/pgbouncer.ini
echo "admin_users = odoo" | sudo tee -a /etc/pgbouncer/pgbouncer.ini
echo "\"$ODOO_DB_USER\" \"$ODOO_DB_PASS\"" | sudo tee -a /etc/pgbouncer/userlist.txt
sudo service pgbouncer restart
echo -e "\n---- Prepare Failover Scripts ----"
cat <<EOF > ~/switch-node1
#!/bin/bash
sudo sed -i "s/\* = host=$SLAVE_IP/* = host=$MASTER_IP/g" /etc/pgbouncer/pgbouncer.ini
sudo service pgbouncer restart
EOF
cat <<EOF > ~/switch-node2
sudo sed -i "s/\* = host=$MASTER_IP/* = host=$SLAVE_IP/g" /etc/pgbouncer/pgbouncer.ini
sudo service pgbouncer restart
EOF
sudo chmod +x ~/switch-node1
sudo chmod +x ~/switch-node2
echo -e "\n---- Completed PgBouncer Installation Successfully ----"