zoukankan      html  css  js  c++  java
  • centos7安装postgres-10

    前一篇的centos6安装postgresql在centos7发生了一些变化。

    安装

    下载yum repo

    https://yum.postgresql.org/repopackages.php

    yum install pgdg-centos10-10-2.noarch.rpm
    

    安装server和客户端

    yum install -y postgresql10-server postgresql10
    

    初始化db

    /usr/pgsql-10/bin/postgresql-10-setup initdb
    

    数据文件依旧是: /var/lib/pgsql/10/data/

    启动Postgres

    systemctl start postgresql-10
    

    确认端口是否启动

    [root@localhost system]# netstat -antup | grep 5432
    tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      2753/postmaster
    

    设置开机启动

     systemctl enable postgresql-10
    

    服务文件: /usr/lib/systemd/system/postgresql-10.service

    修改data目录

    默认安装在系统盘下,通常系统盘只有40g。我们需要将data和log放到我们的数据盘

    停止服务

     systemctl stop postgresql-10
    

    迁移data目录

    复制数据库文件

    cp -R /var/lib/pgsql/10 /data/postgres/db/
    chown -R postgres.postgres   /data/postgres/db/
    

    修改postgres用户的环境变量

    vim /var/lib/pgsql/.bash_profile
    设置
    PGDATA=/data/postgres/db/10/data
    

    修改service文件

    vim /usr/lib/systemd/system/postgresql-10.service
    设置
    Environment=PGDATA=/data/postgres/db/10/data
    

    重启

    systemctl daemon-reload
    systemctl start postgresql-10
    

    连接测试

    切换用户postgres可以免密连接

    su postgres
    psql
    

    设置密码

    password
    

    修改允许远程其他IP连接

    首先进入我们设置的data目录

    cd /data/postgres/db/10/data
    

    然后 vim pg_hba.conf,添加

    # IPv4 local connections:
    host    all             all             127.0.0.1/32            ident
    host    all             all             10.7.10.1/24           md5
    

    第二行是我们新增加的,意思是允许10.7.10.1到10.7.10.254的网段通过密码连接。

    继续修改vim postgresql.conf

    listen_addresses = '*'          # what IP address(es) to listen on;
                                            # comma-separated list of addresses;
                                            # defaults to 'localhost'; use '*' for all
                                            # (change requires restart)
    #port = 5432                            # (change requires restart)
    max_connections = 2000                  # (change requires restart)
    

    打开listen_addresses 顺手修改下最大连接数。

    然后重启就好了。

    systemctl start postgresql-10
    

    在另一台机器上远程连接测试:

    export PGPASSWORD='123456'
    psql -Upostgres  -h10.7.10.111
    

    ,连接成功。

    查看最大连接数

    postgres=# show max_connections;
     max_connections 
    -----------------
     2000
    (1 row)
    
    
  • 相关阅读:
    guxh的python笔记一:数据类型
    guxh的python笔记三:装饰器
    guxh的python笔记十:包和模块
    guxh的python笔记六:类的属性
    guxh的python笔记四:迭代
    流畅的python笔记
    spring面试大全
    Spring面试问答
    Hibernate的10个常见面试问题及答案
    reflect 机制
  • 原文地址:https://www.cnblogs.com/woshimrf/p/centos7-install-pg10.html
Copyright © 2011-2022 走看看