由于最近在做的tigase应用开发,数据库使用的是postgresql-9.0.12,不能自动的使用yum install安装了,因为现在源里面的版本是8.3,无法满足项目要求,特安装了postgresql-9.0.12,只能源码编译安装了。
1. 提前安装编辑源码所需要的工具和库
# 安装编译源码所需的工具和库
yum -y install wget gcc readline-devel zlib-devel make
2、下载postgresql最新版:http://www.postgresql.org/ftp/source/
wget http://ftp.postgresql.org/pub/source/v9.0.12/postgresql-9.0.12.tar.gz
3、解压文件:
tar zxvf postgresql-9.0.12.tar.gz
cd postgresql-9.0.12
4、配置:
./configure --prefix=/usr/local/pgsql
5、编译:
make
6、安装:
make && make install
7、创建用户组和用户:
groupadd postgres
useradd -g postgres postgres
8、创建数据库库文件存储目录、给postgres赋予权限:
mkdir /usr/local/pgsql/data
cd /usr/local/pgsql
chown postgres.postgres data
9、初始化数据库目录:
切换用户
su - postgres
初始化数据
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data --local=zh_CN.UTF8
启动数据库
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
10、配置监听地址和端口:
vi /usr/local/pgsql/data/postgresql.conf
取消以下两行的注释
listen_addresses = '*'
port = 5432
11、允许远程连接:
vi /usr/local/pgsql/data/pg_hba.conf
添加
host all all 当前机器实际ip/32trust
host all all 0.0.0.0/0trust
每项的具体意思在配置文件中有详细说明
配置iptables让远程主机能访问:
vi /etc/sysconfig
添加
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
service iptables restart
12、让postgresql数据库随系统启动而启动:
将启动脚本拷贝到/etc/init.d/目录下,具体执行如下命令:
cd /etc/rc.d/init.d
cp (第一步解压的安装文件目录)/postgresql-9.0.12/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
如果出错 先rpm -aq |grep chkconfig
export PATH=/sbin:$PATH
启动数据库:
service postgresql start
配置完毕 。