美文网首页
Centos安装PostgreSQL

Centos安装PostgreSQL

作者: 张伟科 | 来源:发表于2020-01-08 11:54 被阅读0次

一、安装必要基本软件

[root@localhost ~]# yum install -y gcc.x86_64 glibc.x86_64 glibc-devel.x86_64 vim-enhanced.x86_64 gcc-java apr apr-devel openssl openssl-devel libgcc.x86_64 java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 perl-Module-Install.noarch readline-devel.x86_64

二、创建postgres用户

[root@localhost ~]# useradd postgres

三、下载并安装

#下载安装包

[root@localhost ~]# cd /usr/local/src/

[root@localhost src]# wget https://ftp.postgresql.org/pub/source/v9.6.0/postgresql-9.6.0.tar.gz

[root@localhost src]# wget ftp://ftp.ossp.org/pkg/lib/uuid/uuid-1.6.2.tar.gz

#解压安装uuid库

[root@localhost src]# tar xf uuid-1.6.2.tar.gz 

[root@localhost src]# cd uuid-1.6.2

[root@localhost uuid-1.6.2]# ./configure

[root@localhost uuid-1.6.2]# make && make install

[root@localhost uuid-1.6.2]# cd ..

# 解压安装postgresql

[root@localhost src]# tar xf postgresql-9.6.0.tar.gz

[root@localhost src]# cd postgresql-9.6.0

[root@localhost postgresql-9.6.0]# ./configure --prefix=/app/postgres --enable-thread-safety --with-uuid=ossp --with-libs=/usr/local/lib

[root@localhost postgresql-9.6.0]# make && make install

# 安装contrib工具包

[root@localhost postgresql-9.6.0]# cd contrib 

[root@localhost contrib]# make && make install

# 配置uuid的软连接

[root@localhost postgresql-9.6.0]# ln -s /usr/local/lib/libuuid.so.16 /app/postgres/lib

#把程序目录全部赋权给postgres用户

[root@localhost postgresql-9.6.0]# chown -R postgres.postgres /app/postgres/

#配置环境变量

[root@localhost postgresql-9.6.0]# su - postgres

[postgres@localhost ~]$ vim .bashrc

行尾添加:

PGHOME=/app/postgres

export PGHOME

PGDATA=$PGHOME/data

export PGDATA

PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin

export PATH

[postgres@localhost ~]$ source .bashrc

#初始化数据库

[postgres@localhost ~]$ initdb -D $PGDATA

#启动数据库

[postgres@localhost ~]$ pg_ctl start -D $PGDATA

#设置用户密码

[postgres@db_postgres_10.8.23.201 ~]$psql

psql (9.6.0)

Type "help" for help.

postgres=# ALTER ROLE postgres password 'postgres';

#设置监听

[postgres@localhost ~]$ vim $PGDATA/pg_hba.conf

# "local" is for Unix domain socket connections only

local  all            all                                    md5

# IPv4 local connections:

host    all            all            0.0.0.0/0            md5

# IPv6 local connections:

host    all            all            ::1/128                md5

#配置postgresql

[postgres@localhost ~]$ vim $PGDATA/postgresql.conf

# - Connection Settings -

listen_addresses = '*'

port = 5432

log_destination = 'stderr'

logging_collector = on

log_directory = '/app/postgres/log/'

log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'

log_file_mode = 0600

log_rotation_age = 1d

log_rotation_size = 100MB

log_min_messages = error

#重启pg服务,使配置生效

[postgres@localhost ~]$ pg_ctl restart -D $PGDATA

四、登录

[postgres@localhost ~]$ psql

Password:postgres

psql (9.6.0)

Type "help" for help.

postgres=#

相关文章

网友评论

      本文标题:Centos安装PostgreSQL

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