天天看点

CentOS 6.3下安装Postgresql_9.2.1数据库

操作系统:

CentOS 6.3 x64

数据库版本:

Postgresql 9.2.1

操作系统需要安装的lib包:

yum install readline-devel

yum install zlib-devel

1、  下载postgresql最新版:

postgresql-9.2.1.tar.gz

2、解压文件:

cd /usr/local

mkdir pgsql

cd pgsql

通过ftp上传postgresql-9.2.1.tar.gz至pgsql目录下

tar zxvf postgresql-9.2.1.tar.gz

cd postgresql-9.2.1

3、配置:

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

4、编译:

make

5、安装:

make install

6、创建用户组和用户:

groupadd dba

useradd -g dba postgres

passwd postgres

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

mkdir –p /usr/local/pgsql/data

cd /usr/local/pgsql

chown postgres.dba data

8、初始化数据库目录:

切换用户

su - postgres

初始化数据

/usr/local/pgsql/bin/initdb -D/usr/local/pgsql/data –U ivms8200 –W

9、配置监听地址和端口:

vi /usr/local/pgsql/data/postgresql.conf

取消以下几行的注释,并编辑

listen_addresses = '*'

port = 5432

max_connections = 500

10、允许远程连接:

vi /usr/local/pgsql/data/pg_hba.conf

添加

host all all 127.0.0.1/0 md5

每项的具体意思在配置文件中有详细说明

11、让postgresql数据库随系统启动而启动:

将启动脚本拷贝到/etc/init.d/目录下,具体执行如下命令:

su

cd /etc/rc.d/init.d

cp (第一步解压的安装文件目录)/postgresql-9.2.1/contrib/start-scripts/linuxpostgresql

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

配置完毕。

12、关闭防火墙:

chkconfig iptables off

service iptables stop