当前位置:网站首页>Centos7 install PostgreSQL

Centos7 install PostgreSQL

2020-11-10 17:25:23 Irving the procedural ape

1、 Verification environment

  • operating system CentOS-7-x86_64-Everything-1511
  • postgresql edition PostgreSQL 9.6.3:https://www.postgresql.org/download/linux/redhat/

2、 install

  • install rpm
    [root@psql_master ~]# yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
  • Install client
    [root@psql_master ~]# yum install -y postgresql96
  • Install the server side
    #yum install postgresql, By default, a name named ”postgres” System account of , Used to perform PostgreSQL;# At the same time, the database will also generate a named ”postgres” Database users of , And the password has been automatically generated , It needs to be modified after entering the database ;#PostgreSQL Login under the system account with the same name of the database user, and the password is free .[root@psql_master ~]# yum install -y postgresql96-server
  • initialization
    [root@psql_master ~]# /usr/pgsql-9.6/bin/postgresql96-setup initdb
  • Set boot up
    [root@psql_master ~]# systemctl enable postgresql-9.6
  • start-up
    [root@psql_master ~]# systemctl start postgresql-9.6

3、 Configuration and use

  • Change user password
    #yum install postgresql, By default, a name named ”postgres” System account of , Used to perform PostgreSQL;[root@psql_master ~]# su - postgres# After switching users , The prompt changes to “-bash-4.2$”;# At the same time, the database will also generate a named ”postgres” Database users of , And the password has been automatically generated ;#PostgreSQL Login under the system account with the same name of the database user, and the password is free ;-bash-4.2$ psql -U postgres# Change the password after entering the database ;postgres=# alter user postgres with password 'postgres@123'

  • Allow remote access
    # In profile , By default, it can only be accessed locally postgresql;# modify listen_addresses = 'localhost' by listen_addresses = '*', Allow all remote access ;# Modifying the configuration file requires restarting the service .[root@psql_master ~]# sed -i "s|#listen_addresses = 'localhost'|listen_addresses = '*'|g" /var/lib/pgsql/9.6/data/postgresql.conf
  • Host Authentication
    # In the 82 After line ,”IPv4 local connections” Add allowed clients under ;#“host”  Represents the host type , first “all” representative db , the second “all” representative user ,“172.29.3.67/32”  representative client ip,“trust” For authentication ;# Authentication method except “trust” Outside , also “peer”, “ident”, “md5”, “password” etc. , For details, please refer to pg-hba file : https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html# modify pg.hba The file needs to be restarted .[root@psql_master ~]# vim /var/lib/pgsql/9.6/data/pg_hba.confhost all    all    172.29.3.67/32   trust

  • Set the environment variable
    [root@psql_master ~]# vim /etc/profileexport PATH=$PATH:/usr/pgsql-9.6/bin[root@psql_master ~]# source /etc/profile

版权声明
本文为[Irving the procedural ape]所创,转载请带上原文链接,感谢