zoukankan      html  css  js  c++  java
  • CentOS实验十四:安装PostgreSQL

    CentOS 6.4当前软件源中的postgresql-server版本为8.4.13。

    1. 安装PostgreSQL Server:

    $ yum groupinstall "PostgreSQL Database server"

    默认的安装目录是/var/lib/pgsql。安装过程中会创建postgres用户和群组。安装完成后可以将服务postgresql设置成自启动:

    $ chkconfig postgresql on

    2. 启动postgresql服务,在此之前需要先初始化:

    $ service postgresql initdb
    Initializing database:                                     [  OK  ]
    
    $ ls /var/lib/pgsql/data/
    total 76
    drwx------. 5 postgres postgres  4096 May 25 09:53 base
    drwx------. 2 postgres postgres  4096 May 25 10:07 global
    drwx------. 2 postgres postgres  4096 May 25 09:53 pg_clog
    -rw-------. 1 postgres postgres  3411 May 25 09:53 pg_hba.conf
    -rw-------. 1 postgres postgres  1631 May 25 09:53 pg_ident.conf
    drwx------. 2 postgres postgres  4096 May 25 10:06 pg_log
    drwx------. 4 postgres postgres  4096 May 25 09:53 pg_multixact
    drwx------. 2 postgres postgres  4096 May 25 10:07 pg_stat_tmp
    drwx------. 2 postgres postgres  4096 May 25 09:53 pg_subtrans
    drwx------. 2 postgres postgres  4096 May 25 09:53 pg_tblspc
    drwx------. 2 postgres postgres  4096 May 25 09:53 pg_twophase
    -rw-------. 1 postgres postgres     4 May 25 09:53 PG_VERSION
    drwx------. 3 postgres postgres  4096 May 25 09:53 pg_xlog
    -rw-------. 1 postgres postgres 16886 May 25 09:53 postgresql.conf
    -rw-------. 1 postgres postgres    57 May 25 10:06 postmaster.opts
    
    $ service postgresql start
    Starting postgresql service:                               [  OK  ]

    3. 修改postgresql.conf监听地址和端口:

    $ cat /var/lib/pgsql/data/postgresql.conf
    ... ...
    # - Connection Settings -
    listen_addresses = '*'                # what IP address(es) to listen on;
                        # comma-separated list of addresses;
                        # defaults to 'localhost', '*' = all
                        # (change requires restart)
    port = 5432                # (change requires restart)
    ... ...

    4. 修改pg_hba.conf,配置客户端连接权限。详细的pg_hba.conf配置方法参考《pg_hba.conf 文件简析》。

    $ cat /var/lib/pgsql/data/pg_hba.conf
    # TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
    # "local" is for Unix domain socket connections only
    local   all         all                               ident
    # IPv4 local connections:
    host    all         all         127.0.0.1/32          ident
    # IPv6 local connections:
    host    all         all         ::1/128               ident
    host    all         all         192.168.12.0/24       md5

    5. 切换到postgres用户,修改数据库默认角色postgres的密码(默认密码为空):

    $ su - postgres
    
    $ psql
    postgres=# \password postgres
    Enter new password: 
    Enter it again: 

    6. 设置完所有posgresql服务参数后,重新载入配置参数:

    $ pg_ctl reload

    7. 修改iptables规则,允许远程连接5432端口:

    $ cat /etc/sysconfig/iptables
    # Firewall configuration written by system-config-firewall
    # Manual customization of this file is not recommended.
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    COMMIT
    
    $ service iptables restart

    8. 最后,就可以在其它Windows客户端安装pgAdmin,使用postgres角色远程管理服务器了:

  • 相关阅读:
    [转]zxing二维码的生成和解码 j2se
    [转]Android的网络与通信
    (转)Firefox:浏览器内置数据库之路
    dom Framework oop模块
    我的框架 别名机制
    获取屏幕的PDI值
    mass Framework lang模块
    王云飞 《绿色生活》(附译文)
    dom Framework query模块
    dom Framework核心模块发布!(更新)
  • 原文地址:https://www.cnblogs.com/eastson/p/3098396.html
Copyright © 2011-2022 走看看