zoukankan      html  css  js  c++  java
  • centos安装postgreSQL

    通过rpm查看是否已经安装postgreSQL

    如果没有查询没有结果, 则说明没有安装

    安装: 官方文档: https://www.postgresql.org/download/linux/redhat/

    1. 安装存储库RPM:
      yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
    2. 安装客户端软件包:
      yum install postgresql96
    3. 安装服务器包:
      yum install postgresql96-server
    4. 初始化数据库:
      /usr/pgsql-9.6/bin/postgresql96-setup initdb 
    5. 启用数据库并设置开机自动启动
      systemctl enable postgresql-9.6 
      systemctl start postgresql-9.6
    6. 设置环境变量: 编辑/etc/profile文件
      PGHOST=127.0.0.1
      PGDATABASE=postgres
      PGUSER=postgres
      PGPORT=5432
      PATH=/usr/pgsql-9.6/bin:$PATH
      export PATH
      export PGDATA PGHOST PGDATABASE PGUSER PGPORT
      export TMOUT=1000
    7. 修改postgres用户默认密码
      1     su - postgres  # 切换用户,执行后提示符会变为 '-bash-4.2$'
      2     psql -U postgres # 登录数据库,执行后提示符变为 'postgres=#'
      3     ALTER USER postgres WITH PASSWORD 'postgres'  # 设置postgres用户密码为postgres
      4     q  # 退出数据库
    8. 设置远程访问数据库
      vim /var/lib/pgsql/9.6/data/postgresql.conf

      ## 更改文件内容
      listen_addresses = '*'
      ...
      log_line_prefix = '%t %u %d '
    9. 设置信任远程连接
      vim /var/lib/pgsql/9.6/data/pg_hba.conf
      
      ## 更改文件内容
      # TYPE        DATABASE        USER            ADDRESS                    METHOD
      
      # "local" is for Unix domain socket connections only
      #local        all                all                                        peer
      local        all                all                                        trust
      # IPv4 local connections:
      host        all                all                127.0.0.1/32            trust
      host        all                all                all                        trust
      # IPv6 local connections:
      host        all                all                ::1/128                    ident
      # Allow replication connections from localhost, by a user with the
      # replication privilege.
      #local        replication        postgres                                peer
      #host        replication        postgres        127.0.0.1/32            ident
      #host        replication        postgres        ::1/128                    ident
    10. 重启数据库
      systemctl restart postgresql-9.6 
    11. 登录数据库

        

      12. 通过远程访问

        

  • 相关阅读:
    Docker 常用命令及操作
    Docker 启动 tomcat 成功,但是访问为 404
    Linux 使用 yum install 安装程序时,提示另外一个程序锁定了 yum 等待它退出...
    Centos 6.8 安装 Docker 及 Docker 入门介绍
    iptables常见的模块拓展-m iprange 、-m multiport、
    iptables -m state模块 注意与-m conntrack的区别
    ros single network adapter的nat
    trap 信号捕捉
    ifconfig命令
    使用pipework给docker配置物理机器网卡上的地址
  • 原文地址:https://www.cnblogs.com/yanwu0527/p/9928529.html
Copyright © 2011-2022 走看看