zoukankan      html  css  js  c++  java
  • CentOS6.0安装PostgreSQL9.1

    1、下载postgresql 9.1最新版http://www.postgresql.org/ftp/source/


    2、解压文件

    tar zxvf  postgresql-9.1.1.tar.gz
    cd postgresql-9.1.1

    3、配置

    a)检查系统是否安装 readline 包

    # rpm -qa | grep readline

    没有则需要安装

    yum -y install readline-devel 



    b) 检查是否安装zlib包

    yum install zlib-devel;



    c) 

    ./configure --prefix=/usr/local/pgsql

    4、编译

    make

    5、安装

    make install

    6、创建用户组和用户

    groupadd postgres
    useradd -g postgres postgres



    7、创建数据库库文件存储目录、给postgres赋予权限

    #mkdir /usr/local/pgsql/data
    #cd /usr/local/pgsql
    #chown postgres.postgres data

    #touch /var/log/pgsql.log
    #chown postgres.postgres /var/log/pgsql.log



    8、初始化数据库目录

    切换用户

    su  postgres

    初始化数据并设置locale

    initdb -E UTF-8 -D /usr/local/pgsql/data --locale=zh_CN.UTF-8

    启动数据库

    /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /var/log/pgsql.log start

    9、配置监听地址和端口
    vi /usr/local/pgsql/data/postgresql.conf
    取消以下两行的注释
      listen_addresses = '*'

      port = 5432

    10、允许远程连接
    vi /usr/local/pgsql/data/pg_hba.conf
    添加
      host all all 192.168.1.0/24 md5

      每项的具体意思在配置文件中有详细说明
    配置iptables让远程主机能访问:
      vi /etc/sysconfig
      添加
        -A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
      service iptables restart

    11、让postgresql数据库随系统启动而启动
    将启动脚本拷贝到/etc/init.d/目录下,具体执行如下命令:
    cd /etc/rc.d/init.d
    cp (第一步解压的安装文件目录)/postgresql-9.1.1/contrib/start-scripts/linux postgresql
    chmod +x postgresql
    vi postgresql
      prefix=/usr/local/pgsql
      PGDATA="/usr/local/pgsql/data"
      PGUSER=postgres
      PGLOG="/var/log/pgsql.log"

      chkconfig --add postgresql
    启动数据库:
      service postgresql start


    启动数据库(postgresql)

    $ cd /usr/local/pgsql/bin
    $ ./postmaster -D /usr/local/pgsql/data > /var/log/pgsql.log 2>&1 &
    $ cat /var/log/psql.log
    LOG: checkpoint record is at 0/42C424
    LOG: redo record is at 0/42C424; undo record is at 0/0; shutdown TRUE
    LOG: next transaction ID: 0/593; next OID: 10820
    LOG: next MultiXactId: 1; next MultiXactOffset: 0
    LOG: database system is ready


    创建数据库dm
    $ ./createdb dm
    CREATE DATABASE


    创建用户
    $ ./createuser -A -D -E -P dm
    Enter password for new role: 123456
    Enter it again: 123456
    Shall the new role be allowed to create more new roles? (y/n) y
    CREATE ROLE


    使用psql
    $ ./psql -d dm -U dm
    Welcome to psql 8.2.4, the PostgreSQL interactive terminal.
    Type: \copyright for distribution terms
    \h for help with SQL commands
    \? for help with psql commands
    \g or terminate with semicolon to execute query
    \q to quit

    dm=> \q

    *在psql中若需要使用中文,先发送:
    dm=> set client_encoding to 'gbk';

    配置数据库自启动脚本(root)
    $ (^d)
    # cd /etc/rc.d/init.d
    # cp (安装目录)/postgresql-8.2.4/contrib/start-script/linux postgresql
    # chmod +x postgresql
    # vi postgresql
    prefix=/usr/local/pgsql
    PGDATA="/usr/local/pgsql/data"
    PGUSER=postgresql
    PGLOG="/var/log/pgsql.log"
    # chkconfig --add postgresql

    连接到数据库,修改管理员密码
    使用postgers用户登录
    #su postgers
    #psql -U postgres
    postgres=# ALTER USER postgres WITH PASSWORD 'admin';
    postgres=# \q


    重启数据库
    # /etc/rc.d/init.d/postgresql restart


    重载配置:服务运行是重新加载pg_hba.conf配置文件
    # service postgresql reload

    卸载数据库
    #yum erase postgresql9*

    修改客户端认证配置文件,将METHOD由默认的ident改为md5
    配置POSTGRESQL远程访问
    # vi /var/local/pgsql/data/pg_hba.conf

    # TYPE DATABASE USER CIDR-ADDRESS METHOD
    # "local" is for Unix domain socket connections only
    local all all trust
    # IPv4 local connections:
    host all all 127.0.0.1/32 trust
    host all all 192.168.1.0/24 md5
    # IPv6 local connections:
    host all all ::1/128 trust
    其中加粗标识的内容为新添加的内容,表示允许网段192.168.1.0上的所有主机使用所有合法的数据库用户名访问数据库,并提供加密的密码验证。


    另附:Yum安装PostgreSQL

    1.添加PosgreSQL Yum Repository

     

    访问http://yum.pgrpms.org/reporpms/repoview/letter_p.group.html,下载并安装和当前系统对应的rpm文件。

    # wget http://yum.pgrpms.org/reporpms/9.0/pgdg-centos-9.0-2.noarch.rpm
    #
    rpm -Uvh pgdg-centos-9.0-2.noarch.rpm

    修改原始的yum仓库配置,在[base]和[updates]部分的尾部追加exclude=postgresql*用以取消从默认仓库安装和更新PostgreSQL。

    # cd /etc/yum.repos.d
    # vi CentOS-Base.repo

    安装或者升级postgresql-libs

    # yum upgrade postgresql-libs

    2.安装PostgreSQL Server

    # yum install postgresql90-server

    初始化数据库,默认路径为/var/lib/pgsql/9.0/data

    # service postgresql-9.0 initdb

    启动服务

    # service postgresql-9.0 start  

    连接到数据库,修改管理员密码

    # psql -U postgres
    postgres
    =# ALTER USER postgres WITH PASSWORD 'admin';
    postgres=# \q

    修改客户端认证配置文件,将METHOD由默认的ident改为md5

    # vi /var/lib/pgsql/9.0/data/pg_hba.conf

    重启服务 

    # service postgresql-9.0 restart
  • 相关阅读:
    c++中函数参数传递(值传递、指针传递,引用传递)进一步认识
    时间比金钱金贵得多
    Difference between menu item types; Display, Output and Action in Dynamics Ax
    测试员,敢问路在何方
    C++中++i与i++
    C++中int转string与string转int
    美文共赏
    关于未来十年的思考
    T-SQL_面试题
    [eBook]Inside Microsoft Dynamics AX 2012 R3发布
  • 原文地址:https://www.cnblogs.com/shuaixf/p/2268378.html
Copyright © 2011-2022 走看看