`
贝特虫子
  • 浏览: 154793 次
  • 性别: Icon_minigender_1
  • 来自: 昆明
社区版块
存档分类
最新评论

在Ubuntu下使用源代码安装PostgreSQL

阅读更多
xmarklet网络书签,收集自己的网络书签,创建自己的网站导航。
http://www.kmimagine.com/xmarklet/index.aspx




在Ubuntu下使用源代码安装PostgreSQL

首先我们要 把 postgresql所需要的库文件 安装好
sudo apt-get install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl libdb4.3-dev libpcre3 libpopt-dev lynx m4 make ncftp nmap perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++ build-essential

sudo apt-get install libncurses5-dev

sudo apt-get install libreadline-dev

接下来就可以按照以下顺序安装了:

1.下载PostgreSQL8.3.7的Linux平台对应的源代码包,可以到PostgreSQL的官方网站:www.postgresql.org上下载。如下所示的为下载在本地计算机上的源码包文件:
postgresql-8.3.7.tar.gz
2.使用gzip命令和tar命令将源代码包进行解压缩,执行如下命令:
sudo gzip -d postgresql-8.3.7.tar.gz
执行gzip命令之后,将把源码包解压缩,得到postgresql-8.3.3.tar文件。
Sudo tar xvzf postgresql-8.3.7.tar
或是直接使用 sudo tar xvzf  postgresql-8.3.7.tar.gz 解压
文件解压出来在这个目录 /home/liangshihong(系统用户名)/postgresql-8.3.7
3.执行如下的命令:
cd postgresql-8.3.7
sudo ./configure --prefix=/usr/local/postgresql
sudo make
sudo make install
第一条命令是进入postgresql源代码文件的根目录,然后第二条命令执行configure,会在源代码根目录中产生Makefile文件,第三和第四个命令分别是执行make对源代码进行编译和安装。
4.接下来在系统中添加postgres用户,分别执行如下命令进行设置:
sudo useradd postgres ---- 添加postgres用户
sudo passwd postgres ---- 重置postgres用户的系统登录密码,根据提示操作
sudo mkdir /usr/local/postgresql/data ---- 创建data目录,此目录可根据需要更改
sudo chown postgres /usr/local/postgresql/data ---- 将data目录的所有者更改为postgres
sudo su -  postgres ---- 切换到postgres用户执行下面的命令
5.接下来初始化并启动数据库服务器,使用postgres用户执行下面的命令:
/usr/local/postgresql/bin/initdb -D  /usr/local/postgresql/data -- 初始化数据库(kmdir创建目录)
/usr/local/postgresql/bin/postmaster -D   /usr/local/postgresql/data – 启动数据库服务器。
至此,PostgreSQL8.3.7数据库便安装完成了。此时可使用postgresql -U postgres命令来连接数据库了。
我直接安装pgadmin3图形界面工具来连接数据库进行操作;
安装pgadmin3很简单,我直接使用以下命令来安装:
sudo apt-get  install pgadmin3

其中要注意几个配置文件:
要让pgadmin3连接postgresql雪要配置一下pg_hba.conf和Postgresql.conf

修改Postgresql的配置文件Postgresql.conf,该文件在数据目录/usr/local/postgresql/data下,
将其中的一句:
listen_address=’localhost’
前面的注释去掉,并把’localhost’该为’*’。

修改Postgresql的配置文件pg_hba.conf,该文件在数据目录/usr/local/postgresql/data下,
在文件后面加一句:
host all all 192.168.1.0/24 password
这句的意思是:同网络中192.168.0.*的机器可以以密码的形式使用所有的数据库。
24表示的是允许一个网段的用户,32表示允许某一个具体的ip
就是允许192.168.0.0网段的所有用户通过密码来访问数据库。
更具体的参数意义直接看该配置文件中的注释就可以了。

由于linux的安全性,如果直接按照目录结构找到Postgresql.conf打开修改是无法保存的。
可以使用这个命令来修改:
sudo  gedit  /usr/local/postgresql/data/postgresql.conf
sudo  gedit  /usr/local/postgresql/data/pg_hba.conf

还应该注意以下目录文件
home/liangshihong/postgresql-8.3.7/contrib/start-scripts/linux
在linux文件中
# Installation prefixsudo gem install RMagick  -y

#prefix=/usr/local/pgsql
prefix=/usr/local/postgresql

# Data directory
#PGDATA="/usr/local/pgsql/data"
PGDATA="/usr/local/postgresql/data"


注:
重启,停止,启动服务:
1.切换到postgres用户,sudo su -  postgres
2.进入目录:cd usr/local/postgresql/bin/
3.重启服务:./pg_ctl restart -D /usr/local/postgresql/data
4.停止服务:./pg_ctl stop    -D /usr/local/postgresql/data
5.启动服务:./pg_ctl start   -D /usr/local/postgresql/data

xmarklet网络书签,收集自己的网络书签,创建自己的网站导航。
http://www.kmimagine.com/xmarklet/index.aspx



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics