Skip to content

Commit e376707

Browse files
committed
Initial commit.
0 parents  commit e376707

File tree

6 files changed

+168
-0
lines changed

6 files changed

+168
-0
lines changed

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# postgres-with-pgpool2
2+
3+
This Dockerfile is a mix of postgres and docker-pgpool2.
4+
5+
THIS IS A WORK IN PROGRESS, DON'T USE IT FOR NOW.
6+
7+
8+
Default users/passwords are docker/docker.
9+
10+
Connect to pgpoolAdmin using your web browser pointed at the port mapped to 80.
11+
Connect your pg client to the port mapped to 9999.
12+
13+
Some settings you may wish to change:
14+
15+
* listen_addresses: to `*` so pgpool allows connections from anywhere
16+
* enable_pool_hba: on so you can use md5 auth (using PG_REPL_USER/PG_REPL_PASS)
17+

pgpool2/Dockerfile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
FROM postgres:9.4
2+
3+
RUN apt-get update
4+
5+
# We'll need postgresql-server-dev-9.4 to build pgpool extensions,
6+
# apache and php to run pgpoolAdmin
7+
RUN apt-get install -y postgresql-server-dev-9.4 apache2 libapache2-mod-php5 curl build-essential
8+
RUN curl -L -o pgpool-II-3.4.0.tar.gz http://www.pgpool.net/download.php?f=pgpool-II-3.4.0.tar.gz
9+
RUN tar zxvf pgpool-II-3.4.0.tar.gz
10+
11+
# Build pgpool2
12+
WORKDIR /pgpool-II-3.4.0
13+
RUN ./configure
14+
RUN make & make install
15+
16+
# Build pgpool2 extensions for postgres
17+
WORKDIR /pgpool-II-3.4.0/src/sql
18+
RUN make & make install
19+
20+
RUN ldconfig
21+
22+
# clean up
23+
RUN rm -rf /pgpool-II-3.4.0 & rm /pgpool-II-3.4.0.tar.gz
24+
25+
# Install pgpoolAdmin
26+
WORKDIR /var/www
27+
RUN rm index.html
28+
RUN curl -O http://www.pgpool.net/mediawiki/images/pgpoolAdmin-3.2.2.tar.gz
29+
RUN tar --strip-components=1 -zxvf pgpoolAdmin-3.2.2.tar.gz
30+
ENV APACHE_RUN_USER www-data
31+
ENV APACHE_RUN_GROUP www-data
32+
ENV APACHE_LOG_DIR /var/log/apache2
33+
ENV PG_REPL_USER docker
34+
ENV PG_REPL_PASS docker
35+
ENV PCP_USER docker
36+
ENV PCP_PASS docker
37+
ADD ./pgmgt.conf.php /var/www/conf/
38+
ADD ./pool_hba.conf /usr/local/etc/
39+
ADD setup.sh /var/www/
40+
RUN sh ./setup.sh
41+
42+
EXPOSE 80
43+
EXPOSE 9999
44+
45+
# Add pgpool extension to the database template
46+
ADD init_sql.sh /docker-entrypoint-initdb.d/

pgpool2/init_sql.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
echo "******CREATING PGPOOL EXTENSIONS******"
3+
gosu postgres postgres --single template1 <<- EOSQL
4+
CREATE EXTENSION pgpool_regclass;
5+
CREATE EXTENSION pgpool_recovery;
6+
CREATE EXTENSION pgpool_adm
7+
EOSQL

pgpool2/pgmgt.conf.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
define('_PGPOOL2_LANG', 'en');
3+
define('_PGPOOL2_CONFIG_FILE', '/usr/local/etc/pgpool.conf');
4+
define('_PGPOOL2_PASSWORD_FILE', '/usr/local/etc/pcp.conf');
5+
define('_PGPOOL2_COMMAND', '/usr/local/bin/pgpool');
6+
define('_PGPOOL2_CMD_OPTION_C', '0');
7+
define('_PGPOOL2_CMD_OPTION_LARGE_D', '0');
8+
define('_PGPOOL2_CMD_OPTION_D', '0');
9+
define('_PGPOOL2_CMD_OPTION_M', 'f');
10+
define('_PGPOOL2_CMD_OPTION_N', '1');
11+
define('_PGPOOL2_LOG_FILE', '/tmp/pgpool.log');
12+
define('_PGPOOL2_PCP_DIR', '/usr/local/bin');
13+
define('_PGPOOL2_PCP_HOSTNAME', 'localhost');
14+
define('_PGPOOL2_PCP_TIMEOUT', '10');
15+
define('_PGPOOL2_STATUS_REFRESH_TIME', '10');
16+
?>

pgpool2/pool_hba.conf

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# pgpool Client Authentication Configuration File
2+
# ===============================================
3+
#
4+
# The format rule in this file follows the rules in the PostgreSQL
5+
# Administrator's Guide. Refer to chapter "Client Authentication" for a
6+
# complete description. A short synopsis follows.
7+
#
8+
# This file controls: which hosts are allowed to connect, how clients
9+
# are authenticated, which user names they can use, which databases they
10+
# can access. Records take one of these forms:
11+
#
12+
# local DATABASE USER METHOD [OPTION]
13+
# host DATABASE USER CIDR-ADDRESS METHOD [OPTION]
14+
#
15+
# (The uppercase items must be replaced by actual values.)
16+
#
17+
# The first field is the connection type: "local" is a Unix-domain
18+
# socket, "host" is either a plain or SSL-encrypted TCP/IP socket.
19+
#
20+
# DATABASE can be "all", "sameuser", a database name, or a comma-separated
21+
# list thereof. Note that "samegroup" like in PostgreSQL's pg_hba.conf
22+
# file is not supported, since pgpool does not know which group a user
23+
# belongs to. Also note that the database specified here may not exist in
24+
# the backend PostgreSQL. pgpool will authenticate based on the database's
25+
# name, not based on whether it exists or not.
26+
#
27+
# USER can be "all", a user name, or a comma-separated list thereof. In
28+
# both the DATABASE and USER fields you can also write a file name prefixed
29+
# with "@" to include names from a separate file. Note that a group name
30+
# prefixed with "+" like in PostgreSQL's pg_hba.conf file is not supported
31+
# because of the same reason as "samegroup" token. Also note that a user
32+
# name specified here may not exist in the backend PostgreSQL. pgpool will
33+
# authenticate based on the user's name, not based on whether he/she exists.
34+
#
35+
# CIDR-ADDRESS specifies the set of hosts the record matches.
36+
# It is made up of an IP address and a CIDR mask that is an integer
37+
# (between 0 and 32 (IPv4) that specifies the number of significant bits in
38+
# the mask. Alternatively, you can write an IP address and netmask in
39+
# separate columns to specify the set of hosts.
40+
#
41+
# METHOD can be "trust", "reject", "md5" or "pam". Note that "pam" sends passwords
42+
# in clear text.
43+
#
44+
# OPTION is the name of the PAM service. Default service name is "pgpool"
45+
#
46+
# Database and user names containing spaces, commas, quotes and other special
47+
# characters must be quoted. Quoting one of the keywords "all" or "sameuser"
48+
# makes the name lose its special character, and just match a database or
49+
# username with that name.
50+
#
51+
# This file is read on pgpool startup. If you edit the file on a running
52+
# system, you have to restart the pgpool for the changes to take effect.
53+
54+
# Put your actual configuration here
55+
# ----------------------------------
56+
#
57+
# If you want to allow non-local connections, you need to add more
58+
# "host" records. In that case you will also need to make pgpool listen
59+
# on a non-local interface via the listen_addresses configuration parameter.
60+
#
61+
62+
# TYPE DATABASE USER CIDR-ADDRESS METHOD
63+
64+
# "local" is for Unix domain socket connections only
65+
local all all trust
66+
# IPv4 local connections:
67+
host all all 0.0.0.0/0 md5

pgpool2/setup.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
chown -R www-data .
2+
chmod 755 /usr/local/bin/pgpool
3+
chmod 755 /usr/local/bin/pcp_*
4+
chmod 777 templates_c
5+
chmod 644 conf/pgmgt.conf.php
6+
cp /usr/local/etc/pgpool.conf.sample /usr/local/etc/pgpool.conf
7+
cp /usr/local/etc/pcp.conf.sample /usr/local/etc/pcp.conf
8+
chown -R www-data /usr/local/etc
9+
echo ${PCP_USER}:`pg_md5 ${PCP_PASS}` >> /usr/local/etc/pcp.conf
10+
mkdir /var/run/pgpool
11+
chown www-data /var/run/pgpool
12+
rm -rf /var/www/install
13+
cd /usr/local/etc
14+
pg_md5 -m -u $PG_REPL_USER $PG_REPL_PASS
15+
chown www-data pool_passwd

0 commit comments

Comments
 (0)