温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

linux安装postgresql的方法

发布时间:2020-07-24 15:26:16 来源:亿速云 阅读:175 作者:清晨 栏目:编程语言

小编给大家分享一下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的方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI