标签:
一、环境
VM虚拟机
NAME="Ubuntu" VERSION="12.04.4 LTS, Precise Pangolin"
二、过程
1.安装make,现在不装也行。
# apt-get install make
# make --version GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for i686-pc-linux-gnu
2.获取源码
但是现在已经有现成的二进制安装包了,而且根据不同的系统给出了安装方法。http://www.postgresql.org/download/
源代码在File Browser上,或者直接从版本控制仓库获取,就是从git上获取。用源码安装的操作文档在这。http://www.postgresql.org/docs/current/static/installation.html
打开看一下ubuntu选项的页面说了些啥,http://www.postgresql.org/download/linux/ubuntu/。一堆英文大概意思就是说Ubuntu已经默认包含了PostgreSQL,现在可以用apt-get来安装,如果你Ubuntu上的pgsql版本不是你想要的,可以用PostgreSQL Apt 仓库来整合补丁,然后下面是基本操作步骤,更多Apt相关的信息资料见wiki,https://wiki.postgresql.org/wiki/Apt 。
wiki中说是PGDG这个小组在支持维护APT repository,他们致力于building PostgreSQL server packages as well as extensions and modules packages on several Debian/Ubuntu releases for all PostgreSQL versions supported。就是给不同的发行版发布PostgreSQL及其相关的包。下面是一段快速入门的安装步骤,就按着wiki来好了。
3.安装
添加源,更新源
# sudo sh -c ‘echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list‘ # apt-get update
PS:这个变量可以获取版本代号
# echo $(lsb_release -cs) precise # cat /etc/apt/sources.list.d/pgdg.list
deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main
更新好源之后,可以搜索到各个版本的postgresql,大概看了下,8.2的也有,最新的是9.5
# apt-cache search postgresql-|grep ‘object-relational‘|less postgresql-9.1 - object-relational SQL database, version 9.1 server postgresql-8.4 - object-relational SQL database, version 8.4 server postgresql-8.2 - object-relational SQL database, version 8.2 server postgresql-8.3 - object-relational SQL database, version 8.3 server postgresql-9.0 - object-relational SQL database, version 9.0 server postgresql-9.2 - object-relational SQL database, version 9.2 server postgresql-9.3 - object-relational SQL database, version 9.3 server postgresql-9.4 - object-relational SQL database, version 9.4 server postgresql-9.5 - object-relational SQL database, version 9.5 server
安装更新wget和证书
# sudo apt-get install wget ca-certificates
...省略...
正预备替换 ca-certificates 20111211 (使用 .../ca-certificates_20141019ubuntu0.12.04.1_all.deb) ...
正在解压缩将用于更替的包文件 ca-certificates ...
正预备替换 wget 1.13.4-2ubuntu1 (使用 .../wget_1.13.4-2ubuntu1.2_i386.deb) ...
正在解压缩将用于更替的包文件 wget ...
正在处理用于 man-db 的触发器...
正在处理用于 install-info 的触发器...
正在设置 ca-certificates (20141019ubuntu0.12.04.1) ...
Updating certificates in /etc/ssl/certs... 38 added, 17 removed; done.
Running hooks in /etc/ca-certificates/update.d....done.
正在设置 wget (1.13.4-2ubuntu1.2) ...
# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
OK
安装PostgreSQL,暂时先装个9.2来练手
# sudo apt-get install postgresql-9.2 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 将会安装下列额外的软件包: libpq5 pgdg-keyring postgresql-client-9.2 postgresql-client-common postgresql-common ssl-cert 建议安装的软件包: oidentd ident-server locales-all postgresql-doc-9.2 openssl-blacklist 下列【新】软件包将被安装: libpq5 pgdg-keyring postgresql-9.2 postgresql-client-9.2 postgresql-client-common postgresql-common ssl-cert 升级了 0 个软件包,新安装了 7 个软件包,要卸载 0 个软件包,有 140 个软件包未被升级。 需要下载 4,663 kB 的软件包。 解压缩后会消耗掉 22.6 MB 的额外空间。 ... ......省略下载,解压缩过程 ... 正在设置 libpq5 (9.4.4-1.pgdg12.4+1) ... 正在设置 pgdg-keyring (2014.1) ... Removing apt.postgresql.org key from trusted.gpg: OK Importing apt.postgresql.org key: OK 正在设置 postgresql-client-common (169.pgdg12.4+1) ... 正在设置 postgresql-client-9.2 (9.2.13-1.pgdg12.4+1) ... update-alternatives: 使用 /usr/share/postgresql/9.2/man/man1/psql.1.gz 来提供 /usr/share/man/man1/psql.1.gz (psql.1.gz),于 自动模式 中。 正在设置 ssl-cert (1.0.28ubuntu0.1) ... 正在设置 postgresql-common (169.pgdg12.4+1) ... Adding user postgres to group ssl-cert Creating config file /etc/postgresql-common/createcluster.conf with new version Creating config file /etc/logrotate.d/postgresql-common with new version Building PostgreSQL dictionaries from installed myspell/hunspell packages... en_us Removing obsolete dictionary files: * No PostgreSQL clusters exist; see "man pg_createcluster" 正在设置 postgresql-9.2 (9.2.13-1.pgdg12.4+1) ... Creating new cluster 9.2/main ... config /etc/postgresql/9.2/main data /var/lib/postgresql/9.2/main locale zh_CN.UTF-8 port 5432 update-alternatives: 使用 /usr/share/postgresql/9.2/man/man1/postmaster.1.gz 来提供 /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz),于 自动模式 中。 * Starting PostgreSQL 9.2 database server [ OK ] 正在处理用于 libc-bin 的触发器... ldconfig deferred processing now taking place
4.配置远程访问
PostgreSQL刚安装好后的状态应该是,Ubuntu上的postgres用户密码未知,数据库上的postgres密码未设
若用root或允许sudo,可以直接强制以postgres用户登录,不需要知道postgres的密码
root # su postgres postgres $ psql psql (9.2.13) 输入 "help" 来获取帮助信息. postgres=#
(非root,允许sudo的用户,这里设了免密) $ sudo -u postgres psql psql (9.2.13) 输入 "help" 来获取帮助信息. postgres=#
登录后就给SQL的postgres设个密码
postgres#\password postgres
退出去找一个目录,要修改两个文件,postgresql.conf 和 pg_hba.conf
# find / -name postgresql.conf /etc/postgresql/9.2/main/postgresql.conf # cd /etc/postgresql/9.2/main/ # l environment pg_ctl.conf pg_hba.conf pg_ident.conf postgresql.conf start.conf
postgresql.conf 监听所有IP,默认端口,开启日志收集,每天一个新日志,还有很多不懂的参数可以调。
listen_addresses = ‘*‘ # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to ‘localhost‘; use ‘*‘ for all # (change requires restart) port = 5432 # (change requires restart) logging_collector = on # Enable capturing of stderr and csvlog # into log files. Required to be on for # csvlogs. # (change requires restart) log_directory = ‘pg_log‘ # directory where log files are written, # can be absolute or relative to PGDATA log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log‘ # log file name pattern, # can include strftime() escapes log_truncate_on_rotation = off # If on, an existing log file with the # same name as the new log file will be # truncated rather than appended to. # But such truncation only occurs on # time-driven rotation, not on restarts # or size-driven rotation. Default is # off, meaning append to existing files # in all cases. log_rotation_age = 1d # Automatic rotation of logfiles will # happen after that time. 0 disables. log_rotation_size = 0 # Automatic rotation of logfiles will # happen after that much log output. # 0 disables.
pg_hba.conf 加入自己的地址,全部是0.0.0.0/0
# IPv4 local connections: host all all 127.0.0.1/32 md5 host all all 192.168.152.1/24 md5
重启postgresql服务,再用pgAdminIII设置一下地址,端口,用户名称,密码,就可以成功连接了
标签:
原文地址:http://www.cnblogs.com/right-dress/p/4806909.html