In part one we were introduced to Polaris-GSLB which is a cool little open source GSLB solution, we went through a simple use case scenario and discussed the features it supports. In part two of this Blog I’m going to show you how to build Polaris-GSLB on CentOS 7. I assume you already have a CentOS 7 minimal or better installed and that you've configured the basics such as set an IP address, installed your favourite editor and generally got the server setup how you want it.

Okay so lets start with installing some pre-reqs and enable / start memcached.

[root@gslb ~]# yum install -y make gcc gcc-c++ openssl-devel sqlite-devel bzip2-devel boost-devel zlib-devel memcached wget bind-utils bzip2 git

[root@gslb ~]# systemctl enable memcached
[root@gslb ~]# systemctl start memcached

Next we need our own Python as the one included with CentOS 7 is too old for our purposes, I've gone for 3.5.2 because trying 3.4.3 which was recommended on the Polaris-GSLB Github page didn't seem to support the topology function properly.

[root@gslb ~]# PYTHON_VERSION=3.5.2
[root@gslb ~]# wget -P /tmp/ http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz
[root@gslb ~]# tar -xvJf /tmp/Python-${PYTHON_VERSION}.tar.xz -C /tmp
[root@gslb ~]# cd /tmp/Python-${PYTHON_VERSION}
[root@gslb ~]# ./configure --prefix=/opt/python-${PYTHON_VERSION}
[root@gslb ~]# make -j 4 && make altinstall

Symlink Python and Pip.

[root@gslb ~]# ln -s /opt/python-3.5.2/bin/python3.5 /opt/python-3.5.2/bin/python3
[root@gslb ~]# ln -s /opt/python-3.5.2/bin/pip3.5 /opt/python-3.5.2/bin/pip3

Install Python modules.

[root@gslb ~]# /opt/python-${PYTHON_VERSION}/bin/pip3 install pyyaml
[root@gslb ~]# /opt/python-${PYTHON_VERSION}/bin/pip3 install python-memcached
[root@gslb ~]# /opt/python-${PYTHON_VERSION}/bin/pip3 install python-daemon-3K

Now that we have successfully built and installed Python we need to install PowerDNS which is used for the back-end.

[root@gslb ~]# PDNS_VERSION=3.4.8
[root@gslb ~]# wget -P /tmp/ https://downloads.powerdns.com/releases/pdns-${PDNS_VERSION}.tar.bz2
[root@gslb ~]# tar -xvf /tmp/pdns-${PDNS_VERSION}.tar.bz2 -C /tmp
[root@gslb ~]# cd /tmp/pdns-${PDNS_VERSION}
[root@gslb ~]# ./configure --with-modules="remote" && make -j 4 && make install

Next we'll need to grab Polaris-GSLB from Git, build and install it.

[root@gslb ~]# cd /tmp
[root@gslb ~]# git clone https://github.com/polaris-gslb/polaris-gslb.git
[root@gslb ~]# cd polaris-gslb
[root@gslb ~]# /opt/python-${PYTHON_VERSION}/bin/python3 setup.py install
[root@gslb ~]# cp /opt/polaris/etc/pdns.conf.dist /usr/local/etc/pdns.conf
[root@gslb ~]# cp /opt/polaris/etc/polaris-lb.yaml.dist /opt/polaris/etc/polaris-lb.yaml
[root@gslb ~]# cp /opt/polaris/etc/polaris-topology.yaml.dist /opt/polaris/etc/polaris-topology.yaml
[root@gslb ~]# cp /opt/polaris/etc/polaris-health.yaml.dist /opt/polaris/etc/polaris-health.yaml
[root@gslb ~]# cp /opt/polaris/etc/polaris-pdns.yaml.dist /opt/polaris/etc/polaris-pdns.yaml
[root@gslb ~]# sed -i '1s/.*/export\ PATH=\/opt\/python-3.5.2\/bin\:\$PATH/' /etc/default/polaris
[root@gslb ~]# sed -i '2s/.*/export\ POLARIS_INSTALL_PREFIX=\/opt\/polaris/' /etc/default/polaris

Create systemd scripts and start remaining services.
PowerDNS Script: /usr/lib/systemd/system/pdns.service

[Unit]
Description=PowerDNS Authoritative Server
Documentation=man:pdns_server(1) man:pdns_control(1)
Documentation=https://doc.powerdns.com
Wants=network-online.target
After=network-online.target mysqld.service postgresql.service slapd.service

[Service]
Type=notify
ExecStart=/usr/local/sbin/pdns_server
Restart=on-failure
RestartSec=1
StartLimitInterval=0
PrivateTmp=true
PrivateDevices=true
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_SETGID CAP_SETUID CAP_CHOWN CAP_SYS_CHROOT
NoNewPrivileges=true
# ProtectSystem=full will disallow write access to /etc and /usr, possibly
# not being able to write slaved-zones into sqlite3 or zonefiles.
ProtectSystem=full
ProtectHome=true
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6

[Install]
WantedBy=multi-user.target

Polaris-GSLB script : /usr/lib/systemd/system/polaris-gslb.service

[Unit]
Description=Polaris-GSLB
After=network-online.target

[Service]
ExecStart=/opt/polaris/bin/polaris-health start
Type=forking
Restart=on-failure
RestartSec=1
StartLimitInterval=0

[Install]
WantedBy=multi-user.target

Finally start the PowerDNS and Polaris-GSLB services.

[root@gslb ~]# systemctl enable pdns
[root@gslb ~]# systemctl start pdns

[root@gslb ~]# systemctl enable polaris-gslb
[root@gslb ~]# systemctl start polaris-gslb

And that's it! It should be all installed now, you can test if it's working by using the examples in the first part of the Blog : GSLB – Why Global Server Load Balancers Don’t Always Suck? (Polaris-GSLB)