Skip to content

Instantly share code, notes, and snippets.

@rainly
Created March 7, 2012 08:29
Show Gist options
  • Save rainly/1991923 to your computer and use it in GitHub Desktop.
Save rainly/1991923 to your computer and use it in GitHub Desktop.
Install PostgreSQL from source
1、下载PostgreSQL源码包,放在任意目录
http://www.postgresql.org/ftp/source/v9.0.4/
2、解压文件
#tar zxvf postgresql-9.1.3.tar.gz
#cd postgresql-9.1.3
3.准备安装前需要确认的库(readline,zlib,openssl),如果没有安装,则运行下面命令进行安装:
#yum install readline-devel
#yum install zlib-devel
#yum install openssl-devel
4、配置:
#./configure --prefix=/usr/local/pgsql --with-openssl
5、编译
#make
All of PostgreSQL is successfully made. Ready to install. <==编译成功显示的信息
6.安装
#make install
7、创建用户组和用户:
#groupadd postgres
#useradd -g postgres postgres
8、创建数据库库文件存储目录、日志文件
#mkdir /usr/local/pgsql/data <==创建存放数据的目录
#cd /usr/local/pgsql
#chown -R postgres.postgres data
9、设置环境变量
#cd /home/postgres
#vi .bash_profile 在文件尾添加
export PATH=/usr/local/pgsql/bin:$PATH
export MANPATH=/usr/local/pgsql/man:$MANPATH
export LD_LIBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATH
然后保存退出
10、初始化数据库,启动数据库
#su - postgres
#initdb -D /usr/local/pgsql/data
or
#/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data <==初始化磁盘上的数据库的存储区间
#/usr/local/pgsql/bin/createdb test <== 创建测试数据库,确认安装顺利完成
#/usr/local/pgsql/bin/psql test <== 连接进数据库,可以SQL了
现在就可以启动数据库了
#/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
or
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >/usr/local/pgsql/data/log/logfile 2>&1 &
上面的意思是“指定数据目录启动数据库服务器,输出重定向到logfile,并且运行在后台。当然也可以用pg_ctl来启动数据库,如下:
#pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/serverlog start
提示“server starting”
然后我们执行进程察看命令查看服务是否已经启动:
#ps -A | grep postgres
11、配置监听地址和端口:
#vi /usr/local/pgsql/data/postgresql.conf
取消以下两行的注释
listen_addresses = '*'
port = 5432
12、配置允许远程连接:
#vi /usr/local/pgsql/data/pg_hba.conf
添加
host all all 192.168.1.0/24 trust
host all all samenet trust
每项的具体意思在配置文件中有详细说明
13、配置iptables让远程主机能访问:
#vi /etc/sysconfig
添加:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
保存成功后重启iptables:
#service iptables restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment