# pgCluu for PostgreSQL

##############################################################################
# Install on PostgreSQL Servers

# Configure postgres:
#vim /etc/postgresql/10/main/postgresql.conf

# Change:

# Set up sysstat:
dpkg-reconfigure sysstat

##############################################################################
# Install on Web Node

# On server pgcluu node, add a user:
adduser pgcluu
sudo su - pgcluu
# copy that key to user pgcluu@pg1 pg2 pg3 pg4 (create users there too)
ssh-keygen -t ed25519

# Set up Debian Stretch node
# Install postgres repos:
echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' > /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
apt update
apt install postgresql-client-10

apt install sysstat

# Install pgcluu from repos: XXX don't do this way
# apt install pgcluu
# Meh, the packaged version is ancient, use latest release
# apt remove pgcluu

# Manual install instead:
sudo apt install make
wget -O pgcluu-2.7.tar.gz https://github.com/darold/pgcluu/archive/v2.7.tar.gz
tar zxf pgcluu-2.7.tar.gz
cd pgcluu-2.7/
perl Makefile.PL
make
sudo make install
sudo mkdir -p /var/lib/pgcluu/data/pg1 /var/lib/pgcluu/data/pg2 /var/lib/pgcluu/data/pg3 /var/lib/pgcluu/data/pg4
sudo chown -R pgcluu:pgcluu /var/lib/pgcluu
sudo mkdir /var/run/pgcluu
sudo chown pgcluu:pgcluu /var/run/pgcluu


# Set up apache2
apt install apache2
rm /var/www/html/index.html
mkdir /var/www/html/pg1 /var/www/html/pg2 /var/www/html/pg3 /var/www/html/pg4
chown -R pgcluu:pgcluu /var/www/html

# Set up script for user pgcluu to run:
# See scripts: forksand-pgcluu forksand-pgcluu_collectd
# XXX forksand-pgcluu_collectd needs to start on boot XXX

# Run that script in cron as user pgcluu:
crontab -e
# m h  dom mon dow   command
*/5 *  *   *   *     /home/pgcluu/forksand-pgcluu


##############################################################################
# Admin Web Client

# On workstation create tunnel:
ssh -N -C -L 54680:localhost:80 pgcluu

# On workstation, in browser:
http://localhost:54680/
##############################################################################
