Cambiar a usuario root
[root@localhost ~]# su -
## O ##
[root@localhost ~]# sudo -i
Excluir los paquetes de postgreSQL del repositorio de la distribución. Incluir exclude=postgresql* en el archivo /etc/yum.repos.d/CentOS-Base.repo en las secciones [base] y [updates].
[root@localhost ~]# nano /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releaserver - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
exclude=postgresql*
[updates]
name=CentOS-$releaserver - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
exclude=postgresql*
Si el paquete nano no está instalado, instalarlo con YUM.
[root@localhost ~]# yum install nano -y
Instalar el repositorio de PostgreSQL 11.1
[root@localhost ~]# yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
Instalar PostgreSQL 11.1 con YUM
[root@localhost ~]# yum install postgresql11 postgresql11-server
Inicializar el cluster con el comando initdb
[root@localhost ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb
Initializing database ... OK
Modificar el archivo /var/lib/pgsql/11/data/potgresql.conf, para aceptar/restringir conexiones entrantes desde la red.
[root@localhost ~]# nano /var/lib/pgsql/11/data/postgresql.conf
listen_addresses = 'localhost'
port = 5432
## O ##
listen_addresses = '*'
port = 5432
## O ##
listen_addresses = '10.0.0.11'
port = 5432
Configurar los permisos modificando el archivo de autenticación /var/lib/pgsql/11/data/pg_hba.conf
[root@localhost ~]# nano /var/lib/pgsql/11/data/pg_hba.conf
# Mis configuraciones
host all all 10.0.0.0/24 md5
Iniciar el servicio
[root@localhost ~]# systemctl start postgresql-11.service
Configurando el inicio automático de PostgreSQL al encender el servidor
[root@localhost ~]# systemctl enable postgresql-11.service
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-11.service to /usr/lib/systemd/system/postgresql-11.service
Cambiar contraseña de usuario postgres
Cambiar a usuario postgres
[root@localhost ~]# su postgres
bash-4.2$
Ejecutar PSQL
bash-4.2$ psql
psql (11.3)
Type "help" for help.
postgres=#
Cambiar contraseña de usuario postgres
postgres=# ALTER USER postgres WITH PASSWORD 'nueva_contraseña';
ALTER ROLE
Salir de PSQL
postgres=# \q
bash-4.2$
## O ##
postgres=# exit
bash-4.2$
Salir del usuario postgres
bash-4.2$ exit
exit
[root@localhost ~]#
Habilitar conexiones externas
Listar las interfases de red activas
[root@localhost ~]# firewall-cmd --get-active-zones
public
interfaces: ens33
Agregar una nueva regla al Firewall
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=5432/tcp
## O ##
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=postgresql
Reiniciar el firewall
[root@localhost ~]# systemctl restart firewalld
