Posted on 18 de Março de 2015 by fabio.reis
Neste post será apresentado como instalar o postgres 9.4 através do seu repositório.
1) Instalação do repositório :
CentOS 6 x64
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm
CentOS 7
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm
2) Instalando o banco
yum install
postgresql94-server postgresql94-contrib
3) Iniciando e habilitando o serviço no boot
CentOS 6
service postgresql-9.4 initdb
service postgresql-9.4 start
chkconfig postgresql-9.4 on
CentOS 7
/usr/pgsql-9.4/bin/postgresql94-setup initdb
systemctl enable
postgresql-9.4
systemctl start postgresql-9.4
4) Configurando o Iptables / Firewalld e SELinux
Configuração do Iptables :
vim /etc/sysconfig/iptables
Adicione as linhas :
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
Restarte o serviço :
service iptables restart
Configuração do Firewalld:
firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
Configuração do SELINUX :
setsebool -P httpd_can_network_connect_db 1
5) Configurando o Postgres:
Acesse o prompt do postgres:
su – postgres
psql
Altere a senha do usuário postgres:
postgres=# \password postgres
Enter new password:
Enter it again:
postgres=# \q
Instale o PostgreSQL Adminpack chamado o comando abaixo no prompt:
postgres=# CREATE EXTENSION adminpack;
CREATE EXTENSION
Crie o usuário , role e database:
Entre no prompt do usuário postgres:
su – postgres
Crie o usuário admindb :
$ createuser admindb
Crie o banco phppg :
$ createdb phppg
Entre no banco :
$ psql
psql (9.4.0)
Type "help"
for
help.
postgres=# alter user admindb with encrypted password 'centos';
ALTER ROLE
postgres=# grant all privileges on database phppg to admindb;
GRANT
postgres=#
6) Definindo acesso e autenticação via md5
Altere o arquivo /var/lib/pgsql/9.4/data/pg_hba.conf conforme apresentado abaixo :
10.0.5.0/24 é a rede autorizada para conseguir chegar no banco.
[...]
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local
all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all <strong>10.0.5.0/24 </strong> md5
# IPv6 local connections:
host all all ::1/128 md5
[...]
Restart o serviço :
Centos 6
service postgresql-9.4 restart
Centos 7
systemctl restart postgresql-9.4
7) Configurando o PhpPGAdmin :
Instale o epel release:
yum install
epel-release
Agora instale o PHPPgAdmin :
yum install
phpPgAdmin httpd
vá no arquivo /etc/httpd/conf.d/phpPgAdmin.conf e altere para que fique igual ao meu exemplo:
[...]
Alias /phpPgAdmin /usr/share/phpPgAdmin
<Location /phpPgAdmin>
<IfModule mod_authz_core.c>
# Apache 2.4
Require all granted
#Require host example.com
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order deny,allow
Allow from all
# Allow from .example.com
</IfModule>
</Location>
Restarte o Apache :
Restart o serviço :
Centos 6
service httpd restart
Centos 7
systemctl restart httpd