centos7安装postgresql9.4

1.软件下载

cd /usr/java/postgres/

wget https://ftp.postgresql.org/pub/source/v9.4.1/postgresql-9.4.1.tar.gz

2.安装依赖包

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

3.安装postgresql

tar xf postgresql-9.4.1.tar.gz

cd postgresql-9.4.1

./configure --prefix=/usr/local/pgsql --with-perl --with-python --with-libxml --with-libxslt

gmake

gmake install

4.安装PG插件

cd /usr/java/postgres/postgresql-9.4.1/contrib

gmake

gmake install

5.加载动态库

echo "/usr/local/pgsql/lib" >> /etc/ld.so.conf.d/pgsql.conf(此处为显示)

ldconfig

6.初始化数据库

   创建用户postgres

useradd postgres

echo "postgres"|passwd --stdin postgres

7.创建PG数据目录

mkdir -p /data/pg/data

chown -R postgres:postgres /data/pg

/usr/local/pgsql/bin/initdb --no-locale -U postgres -E utf8 -D /data/pg/data -W

(在初始化的时候,注意看提示 设置 超级用户的密码,切换为postgres用户)

备注

  initdb [选项]... [DATADIR]

  -A, --auth=METHOD         本地连接的默认认证方法

  -D, --pgdata=DATADIR       当前数据库簇的位置

  -E, --encoding=ENCODING   为新数据库设置默认编码

      --locale=LOCALE      为新数据库设置默认语言环境

  --lc-collate, --lc-ctype, --lc-messages=LOCALE

  --lc-monetary, --lc-numeric, --lc-time=LOCALE

                            为新的数据库簇在各自的目录中分别

                   设定缺省语言环境(默认使用环境变

                   量)

  --no-locale               等同于 --locale=C

  --pwfile=文件名           对于新的超级用户从文件读取口令

  -T, --text-search-config=CFG

                   缺省的文本搜索配置

  -U, --username=NAME       数据库超级用户名

  -W, --pwprompt              对于新的超级用户提示输入口令

  -X, --xlogdir=XLOGDIR        当前事务日志目录的位置

非普通使用选项:

  -d, --debug               产生大量的除错信息

  -L DIRECTORY              输入文件的位置

  -n, --noclean             出错后不清理

  -s, --show                显示内部设置

其它选项:

  -?, --help                显示此帮助, 然后退出

  -V, --version             输出版本信息, 然后退出

如果没有指定数据目录, 将使用环境变量 PGDATA

8.配置运行环境变量(方便管理)

切换到root

vim /etc/profile

最后一行添加以下代码:

export PGDATA=/data/pg/data

export PATH=/usr/local/pgsql/bin:$PATH

  

9.执行生效

source /etc/profile

10.postgresql服务管理

启动:(地址为你的data地址,重启restart)

pg_ctl start -D /data/pg/data

11、修改配置文件允许远程访问

cd /data/pg/data

(1)vimpg_hba.conf

修改pg_hba.conf文件,配置用户的访问权限(#开头的行是注释内容):

  1. # TYPE DATABASE  USER    CIDR-ADDRESS     METHOD
  2.  
  3. # "local" is for Unix domain socket connections only
  4. local all    all               trust
  5. # IPv4 local connections:
  6. host  all    all    127.0.0.1/32     trust
  7. host  all    all    0.0.0.0/0    md5
  8. # IPv6 local connections:
  9. host  all    all    ::1/128       trust

保存

(2)vim postgresql.conf

将#listen_addresses=’localhost’改为#listen_addresses=’*’

附:我的安装目录/usr/local/sql/pgsql

猜你喜欢

转载自blog.csdn.net/tianshuhao521/article/details/83343880