CLUSTERPRO + PostgreSQL


node1: mmm121 CentOS7 PostgreSQL11
node2: mmm122 CentOS7 PostgreSQL11
iSCSItarget: mmm123 CentOS7
管理サーバ: mmm161 Windows Server2012R2


構築手順

1. フェイルオーバグループの作成
→「CLUSTERPROインストール」参照

2. PostgreSQL のインストール[node1,node2]

yum update -y

--yum リポジトリの追加

yum -y install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
yum info postgresql11-server


--インストール
yum -y install postgresql11-server postgresql11-contrib postgresql11-devel postgresql11-libs
/usr/pgsql-11/bin/postgres --version

--DB初期化
export PGSETUP_INITDB_OPTIONS='-E UTF8 --locale=C'

/usr/pgsql-11/bin/postgresql-11-setup initdb

 


--DB起動
systemctl restart postgresql-11
systemctl status postgresql-11
systemctl disable postgresql-11


--DB接続
su - postgres
psql

 


3. データベースディレクトリの変更[node1,node2]

--node1での作業

mkdir -p /mnt/sdc2/pgsql/11/data
chown -R postgres:postgres /mnt/sdc2/pgsql
chmod -R 700 /mnt/sdc2/pgsql

systemctl stop postgresql-11
cp -a /var/lib/pgsql/11/data/* /mnt/sdc2/pgsql/11/data

systemctl restart postgresql-11
systemctl status postgresql-11

vim /usr/lib/systemd/system/postgresql-11.service
Environment=PGDATA=/var/lib/pgsql/11/data/

Environment=PGDATA=/mnt/sdc2/pgsql/11/data/

systemctl daemon-reload

 

su - postgres
vim .bash_profile

PGDATA=/var/lib/pgsql/11/data

PGDATA=/mnt/sdc2/pgsql/11/data

. .bash_profile


--node2での作業

systemctl stop postgresql-11

su - postgres
vim .bash_profile

PGDATA=/var/lib/pgsql/11/data

PGDATA=/mnt/sdc2/pgsql/11/data

. .bash_profile

 


4. CLUSTERPRO へのサービスの組み込み[管理サーバ]

タイプ: execute resource
名前: pgsql

依存するリソース: disk1,fip1


--start.sh
同期
タイムアウト:300秒

#! /bin/sh
#***************************************
#* start.sh *
#***************************************

#ulimit -s unlimited

if [ "$CLP_EVENT" = "START" ]
then
if [ "$CLP_DISK" = "SUCCESS" ]
then
echo "NORMAL1"

systemctl start postgresql-11
sleep 10

if [ "$CLP_SERVER" = "HOME" ]
then
echo "NORMAL2"
else
echo "ON_OTHER1"
fi
else
echo "ERROR_DISK from START"
exit 1
fi
elif [ "$CLP_EVENT" = "FAILOVER" ]
then
if [ "$CLP_DISK" = "SUCCESS" ]
then
echo "FAILOVER1"

systemctl start postgresql-11
sleep 10


if [ "$CLP_SERVER" = "HOME" ]
then
echo "FAILOVER2"
else
echo "ON_OTHER2"
fi
else
echo "ERROR_DISK from FAILOVER"
exit 1
fi
else
echo "NO_CLP"
exit 1
fi
echo "EXIT"
exit 0


--stop.sh
同期
タイムアウト:300秒

#! /bin/sh
#***************************************
#* stop.sh *
#***************************************

#ulimit -s unlimited

if [ "$CLP_EVENT" = "START" ]
then
if [ "$CLP_DISK" = "SUCCESS" ]
then
echo "NORMAL1"

systemctl stop postgresql-11
sleep 10

if [ "$CLP_SERVER" = "HOME" ]
then
echo "NORMAL2"
else
echo "ON_OTHER1"
fi
else
echo "ERROR_DISK from START"
exit 1
fi
elif [ "$CLP_EVENT" = "FAILOVER" ]
then
if [ "$CLP_DISK" = "SUCCESS" ]
then
echo "FAILOVER1"

systemctl stop postgresql-11
sleep 10


if [ "$CLP_SERVER" = "HOME" ]
then
echo "FAILOVER2"
else
echo "ON_OTHER2"
fi
else
echo "ERROR_DISK from FAILOVER"
exit 1
fi
else
echo "NO_CLP"
exit 1
fi
echo "EXIT"
exit 0

 

 

5. 監視リソースの設定[管理サーバ]

タイプ:custom monitor
名前: pgsql_mon

監視タイプ:同期

--genw.sh


#! /bin/sh
#***********************************************
#* genw.sh *
#***********************************************

ulimit -s unlimited

CNT=`ps -ef | grep /usr/pgsql-11/bin/postmaster | grep -v grep | wc -l`

if [ $CNT -ne 1 ]; then
exit 1
fi

exit 0


回復動作: failover1に対してフェイルオーバ実行