Created
October 25, 2014 07:47
-
-
Save ruzickap/eedcdc1a0faa7a63a35f to your computer and use it in GitHub Desktop.
cz01-psql02 PostgreSQL database installation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#PostgreSQL installation | |
yum localinstall -y http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm | |
yum install -y postgresql93-server repmgr | |
yum install -y --enablerepo=centos-base postgresql93-contrib | |
chkconfig postgresql-9.3 on | |
echo 'PATH=/usr/pgsql-9.3/bin:$PATH' >> /var/lib/pgsql/.bash_profile | |
scp -r cz01-psql01.example.com:/root/{.pgpass,.ssh} /root/ | |
cp -r /root/{.pgpass,.ssh} /var/lib/pgsql/ | |
chown -R postgres:postgres /var/lib/pgsql/.pgpass /var/lib/pgsql/.ssh | |
#Check the connection to primary node | |
su - postgres -c "psql --username=repmgr --dbname=repmgr --host cz01-psql01.example.com -w -l" | |
#Replicate the DB from the master mode | |
su - postgres -c "repmgr -D /var/lib/pgsql/9.3/data -d repmgr -p 5432 -U repmgr -R postgres --verbose standby clone cz01-psql01.example.com" | |
#Configure the repmgr | |
mkdir /var/lib/pgsql/repmgr | |
cat > /var/lib/pgsql/repmgr/repmgr.conf << EOF | |
cluster=pgsql_cluster | |
node=2 | |
node_name=cz01-psql02 | |
conninfo='host=cz01-psql02.example.com user=repmgr dbname=repmgr' | |
pg_bindir=/usr/pgsql-9.3/bin/ | |
master_response_timeout=5 | |
reconnect_attempts=2 | |
reconnect_interval=2 | |
failover=manual | |
promote_command='/usr/pgsql-9.3/bin/repmgr standby promote -f /var/lib/pgsql/repmgr/repmgr.conf' | |
follow_command='/usr/pgsql-9.3/bin/repmgr standby follow -f /var/lib/pgsql/repmgr/repmgr.conf' | |
EOF | |
chown -R postgres:postgres /var/lib/pgsql/repmgr | |
# cz01-psql02 Certificate | |
cd /etc/pki/CA | |
openssl genrsa -passout pass:password123 -des3 -out cz01-psql02.example.com_priv_encrypted.key 2048 | |
openssl rsa -passin pass:password123 -in cz01-psql02.example.com_priv_encrypted.key -out cz01-psql02.example.com_priv.key | |
SUBJ=" | |
C=CZ | |
ST=Czech Republic | |
O=Example | |
OU=Deployment | |
L=Brno | |
CN=cz01-psql02.example.com | |
emailAddress=root@example.com | |
" | |
openssl req -passin pass:password123 -new -subj "$(echo -n "$SUBJ" | tr "\n" "/")" -days 3650 -key cz01-psql02.example.com_priv_encrypted.key -out cz01-psql02.example.com.csr | |
scp /etc/pki/CA/cz01-psql02.example.com.csr root@cz01-psql01.example.com:/etc/pki/CA/ | |
ssh root@cz01-psql01.example.com << EOF | |
cd /etc/pki/CA | |
openssl ca -passin pass:password123 -batch -in cz01-psql02.example.com.csr -out cz01-psql02.example.com.crt | |
openssl x509 -noout -text -in cz01-psql02.example.com.crt > cz01-psql02.example.com.crt.info | |
EOF | |
scp root@cz01-psql01.example.com:/etc/pki/CA/cz01-psql02.example.com.crt /etc/pki/CA/ | |
cp /etc/pki/CA/cz01-psql02.example.com.crt /var/lib/pgsql/9.3/server.crt | |
cp /etc/pki/CA/cz01-psql02.example.com_priv.key /var/lib/pgsql/9.3/server.key | |
chown postgres:postgres /var/lib/pgsql/9.3/server.* | |
chmod 0600 /var/lib/pgsql/9.3/server.key | |
service postgresql-9.3 start | |
#Register the DB instance as slave | |
su - postgres -c "repmgr -f /var/lib/pgsql/repmgr/repmgr.conf --verbose standby register" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment