Skip to content
This repository has been archived by the owner on Nov 18, 2017. It is now read-only.

Changes I've done to get Governor to work other then localhost #9

Open
tvb opened this issue May 8, 2015 · 7 comments
Open

Changes I've done to get Governor to work other then localhost #9

tvb opened this issue May 8, 2015 · 7 comments

Comments

@tvb
Copy link

tvb commented May 8, 2015

I had to change some things to get governor work with something other then localhost.
First I had to change etcd so it uses init and my own config:

In /etc/init/etcd.override:

# Override file for etcd Upstart script providing some environment variables
env ETCD_INITIAL_CLUSTER="sql1=http://10.0.0.75:2380,sql2=http://10.0.0.76:2380,etcd=http://10.0.0.77:2380"
env ETCD_INITIAL_CLUSTER_STATE="new"
env ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
env ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.0.0.75:2380"
env ETCD_DATA_DIR="/var/lib/postgresql/governor/data/etcd"
env ETCD_LISTEN_PEER_URLS="http://10.0.0.75:2380"
env ETCD_LISTEN_CLIENT_URLS="http://10.0.0.75:2379"
env ETCD_ADVERTISE_CLIENT_URLS="http://10.0.0.75:2379"
env ETCD_NAME="sql1"

In helpers/postgresql.py I added the following line:

        f.write("host all all %(self)s trust\n" % {"self": self.replication["self"]} )

right after:

     def write_pg_hba(self):
         f = open("%s/pg_hba.conf" % self.data_dir, "a")

and lastly added:

self: 10.0.0.0/24

to the postgresX.yml files. This not ideal as now the hole 10.0.0.0/24 network is trusted. But it did the trick for now. I would like to know you guys thought on this.

@tvb tvb changed the title Governor only works with localhot Changes I've done to get Governor to work other then localhost May 8, 2015
@Winslett
Copy link
Contributor

I'm thinking we should add rows for pg_hba.conf to the postgresX.yml files. As part of the initialization process, Governor should create the proper pg_hba.conf records. That would allow people to customize the cluster based on their needs.

postgres:
  pg_hba:
    - type: local
      database: all
      user: all
      method: trust
    - type: host    
      database: all
      user: all
      address: 127.0.0.1/32
      method: trust
    - type: host    
      database: all
      user: all
      address:  "::1/128"
      method: trust
    - type: hostssl
      database: all
      user: all
      address: 0.0.0.0/0
      type: md5

The replication user should automatically be added when creating the pg_hba.conf.

@tvb
Copy link
Author

tvb commented May 15, 2015

@Winslett yes that would be a nice start.

@tvb
Copy link
Author

tvb commented May 18, 2015

I think we need to (re)write the postgresql.conf as well for this to work:

Note: Remote TCP/IP connections will not be possible unless the server is started with an appropriate value for the listen_addresses configuration parameter, since the default behavior is to listen for TCP/IP connections only on the local loopback address localhost.

@s200999900
Copy link

Thank for interesting HA solution!

I tried to implement Postgres HA solution with governor not on localhost and that is not implement, there are many errors, fault's and etc (
I think bug need to prioritize.

@tvb
Copy link
Author

tvb commented May 21, 2015

It is not really a bug. I have it working now on non-localhost ip addresses. I had to change the helpers/postgresql.py file so it will write the correct listen_addresses to postgresql.conf and had to move the write_pg_hba() en the extra write_postgresql_conf() function before the pg_ctl start function together with the changes in the first post to get postgres to start correctly.

def initialize(self):
        if os.system("initdb -D %s" % self.data_dir) == 0:
            # start Postgres without options to setup replication user indepedent of other system settings
            self.write_postgresql_conf()
            self.write_pg_hba()
            os.system("pg_ctl start -w -D %s" % self.data_dir)

the postgresql_conf function itself:

    def write_postgresql_conf(self):
        f = open("%s/postgresql.conf" % self.data_dir, "a")
        f.write("listen_addresses = '%s'" % self.host )
        f.close()

@wkielas
Copy link

wkielas commented May 26, 2015

@tvb, do you have the non-localhost code available somewhere, like a fork or a branch? I'd love to take a look at it ;-)

@tvb
Copy link
Author

tvb commented Aug 27, 2015

@wkielas sorry. I do not :(

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants