资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

linux安装postgresql的方法-创新互联

创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

专注于为中小企业提供成都网站建设、网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业望花免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

小编给大家分享一下linux安装postgresql的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

linux安装postgresql

配置用户和组

groupadd postgres
useradd postgres -g postgres

环境准备

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel 
openldap-devel 
 python-devel gcc-c++ openssl-devel cmake gcc* readline-devel

权限配置

mkdir /opt/postgres
chown -R postgres:postgres /opt/postgres/

配置环境变量

vi /etc/profile

#在文件末尾将以下环境变量添加进去
export PATH=/opt/postgres/bin:$PATH
export PGHOME=/opt/postgres
export PGDATA=/opt/postgres/data/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib/
export PATH=$PGHOME/bin:$PATH:$HOME/bin

安装过程

安装数据库

cd 下载好的压缩包存放路径#解压文件tar -zxvf postgresql-9.6.3.tar.gz

cd  postgresql-9.6.3#参数根据自己需求配置./configure --prefix=/opt/postgres/ --with-python --with-libxml 
--with-libxslt
make
make install****,安装过程内容太长就不截图了,从屏显的信息最后看到PostgreSQL installation complete. 就说明安装好了,
如果报错大多数都是安装包问题或者依赖没下载,看下错误信息基本都能解决****

2.初始化数据库

su postgres

#初始化数据库的参数也是根据自己需要添加 ,可以通过--help查看
/opt/postgres/bin/initdb -D $PGDATA  -E  UTF8  

#如果出现以下message就说明初始化成功了
*********************************************************************

    creating directory /opt/postgres/data ... ok
    creating subdirectories ... ok
    selecting default max_connections ... 100
    selecting default shared_buffers ... 128MB
    selecting dynamic shared memory implementation ... posix
    creating configuration files ... ok
    running bootstrap script ... ok
    performing post-bootstrap initialization ... ok
    syncing data to disk ... ok
    
    WARNING: enabling "trust" authentication for local connections
    You can change this by editing pg_hba.conf or using the option -A, or
    --auth-local and --auth-host, the next time you run initdb.
    
    Success. You can now start the database server using:
    
        /opt/postgres/bin/pg_ctl -D /opt/postgres/data -l logfile start
    
********************************************************************
#启动数据库服务

#数据文件和日志文件的路径根据自己需求指定。
/opt/postgres/bin/pg_ctl -D $PGDATA -l /opt/postgres/server.log start

到此postgres服务就安装完毕了。

使用数据库

进入数据库

su postgres

#进入数据库

[postgres@localhost postgres]$ psql
psql (9.6.3)
Type "help" for help.

postgres=#

修改数据库配置,允许其他服务器连接

#postgres安装好以后需要修改2个配置文件才能允许别的服务器访问。
cd /opt/postgres/data

vi postgresql.conf
#找到listen_addresses和port参数,修改如下,也可根据自己需求修改
listen_addresses = '*'
port = 5432

#根据自己的网段设置下放行的ip规则
vi pg_hba.conf

# IPv4 local connections:
host    all             all             192.168.0.0/16            md5

看完了这篇文章,相信你对linux安装postgresql的方法有了一定的了解,想了解更多相关知识,欢迎关注创新互联-成都网站建设公司行业资讯频道,感谢各位的阅读!


当前题目:linux安装postgresql的方法-创新互联
分享URL:http://cdkjz.cn/article/shjhp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220