美文网首页
Centos7下离线安装PostgreSQL15

Centos7下离线安装PostgreSQL15

作者: 数据老菜鸟 | 来源:发表于2022-12-22 14:31 被阅读0次

    编译环境 及准备

    Centos7.5   JDK 1.8

    安装编译器

        yum -y install gcc gcc-c++

        查看版本

        gcc -v

    一、安装

    1. 下载

        https://www.postgresql.org/ftp/source/v15.1/

    2.解压

        tar-zxvf   postgresql-15.1.tar.gz

    3.创建用户和目录

        add user postgres

        mkdir /opt/pgsql

        mkdir /opt/pgsql/data

        touch /opt/pgsql/pgsql.log

        chown postgres  -R /opt/pgsql

    4.编译并安装

        cd postgresql-15.1

        ./configure --prefix=/opt/pgsql --without-readline  --without-zlib

    5、初始化数据库目录并启动

         su - postgres

         cd /opt/pgsql/bin

        ./initdb -D /opt/pgsql/data

    启动数据库:

        /opt/pgsql/bin/postmaster -D /opt/pgsql/data > /opt/pgsql/pgsql.log 2>&1 &

    查看数据库状态:

            /opt/pgsql/bin/pg_ctl -D /opt/pgsql/data status

    关闭数据库:

            /opt/pgsql/bin/pg_ctl -D /opt/pgsql/data stop

    进入数据库:

            ./psql

    查看数据库

        \l

    6.查看进程:

         ps -aux | grep postgres

    7. 用户

        安装完毕后超级用户为postgres,密码为空,这个即系统账号 也是数据库账号

    8远程连接

        修改/opt/pgsql/data/pg_hba.conf

        添加:

        host all all 0.0.0.0/0 md5

    #host是连接类型,第一个all是数据库,第二个是用户,第三个是IP,修改成 0.0.0.0/0,代表所有ip都可以连接,默认是你本地IP,(/24 代表掩码255.255.255.0)。md5是传输时使用何种方式进行加密

    修改/opt/pgsql/data/postgresql.conf

    修改 #listen_address='localhost'改成listen_address = '*'

    9.创建用户:

        /opt/pgsql/bin/psql

        alter user postgres with encrypted password 'postgres123';

        创建用户

        create user pgdba with encrypted password 'pgdba';

        授予超级用户权限

        alter role pgdba createrole superuser;

        创建数据库

        create database mytest;

        授予用户数据库权限

        grant all privileges on database mytest to pgdba;

         修改密码后需要使用

         psql -U postgres -h localhost -d postgres -p 5432

    二、设置服务

    开机启动脚本在源安装包的 postgresql-15.1/contrib/start-scripts 目录下

    1、将Linux文件复制到 /etc/init.d 目录下,并且将其重名为postgresql

    cp linux /etc/init.d/postgresql

    2、进入 /etc/init.d 目录下,修改postgresql文件

    cd /etc/init.d/

    vim postgresql

    将prefix设置为postgresql的安装路径:/opt/pgsql

    将PGDATA设置为postgresql的数据目录路径:/opt/pgsql/data

    用户默认就是postgres即可

    3、 添加到开机启动

    chmod a+x postgresql

    chkconfig --add postgresql

    设置开机启动

    systemctl enable postgresql

    操作命令

    systemctl status postgresql

    systemctl start postgresql

    systemctl stop postgresql

    相关文章

      网友评论

          本文标题:Centos7下离线安装PostgreSQL15

          本文链接:https://www.haomeiwen.com/subject/srckhhtx.html