目标:
1.编译安装:postgres9.4
2.实现远程登录
3.安装postgis
环境配置
server:
postgres-test01-0001 172.16.10.214
postgres-test01-0002 172.16.10.160
CentOS Linux release 7.1.1503 (Core)
安装目录:/data
用户:postgres
1.更新源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2.下载postgres
https://ftp.postgresql.org/pub/source/v9.4.16/postgresql-9.4.16.tar.gz
3.安装依赖包
[root@postgres-test01 ~]# yum -y install gcc gcc-c++ make cmake zlib-devel systemtap-sdt-devel.x86_64 openssl-devel libxml2-devel pam-devel libxslt-devel openldap-devel perl-ExtUtils-Embed tcl-devel python-devel
[root@postgres-test01 ~]# yum search dtrace readline-devel.x86_64
4.编译过程
创建用户
[root@postgres-test01 ~]# useradd postgres
创建目录
[root@postgres-test01 postgresql-9.4.16]# mkdir /data
[root@postgres-test01 postgresql-9.4.16]# chown postgres.postgres /data
解压
[root@postgres-test01 src]# cd /usr/local/src/
[root@postgres-test01 src]# ll postgresql-9.4.16.tar.gz
-rw-r--r-- 1 root root 23331396 May 7 14:38 postgresql-9.4.16.tar.gz
[root@postgres-test01 src]# tar xvf postgresql-9.4.16.tar.gz
[root@postgres-test01 src]# cd postgresql-9.4.16/
./configure --prefix=/data/pgsql9.4.16 --with-perl --with-tcl --with-python --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --enable-thread-safety --with-wal-blocksize=16 --with-blocksize=16 --enable-dtrace --enable-debug
gmake world
gmake install-world
5.初始化
[root@postgres-test01-0001 postgresql-9.4.16]# cd /data/
[root@postgres-test01-0001 data]# ls
pgsql-9.4.16
切换用户postgres
su - postgres
配置环境变量
注:下篇文章详解
[postgres@postgres-test01 ~]$ vi ~/.bash_profile
export PGPORT=5456
export PGDATA=/data/pgdata/
export LANG=en_US.utf8
export PGHOME=/data/pgsql
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
export PGUSER=postgres
export PGHOST=$PGDATA
[postgres@postgres-test01-0001 ~]$ source ~/.bash_profile
初始化 (流复制不需要初始化)
[postgres@postgres-test01-0001 ~]$ initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W
输入新密码
Enter new superuser password:
Enter it again:
6.启动服务
启动命令$ pg_ctl -D $PGDATA start
我们需要配置postgres.conf 配置文件,我们设置是端口是5456,,默认的是5432。
[postgres@postgres-test01-0001 ~]$ cd $PGDATA
[postgres@postgres-test01-0001 pgdata]$ vim postgresql.conf
port = 5456
[postgres@postgres-test01-0001 pgdata]$ pg_ctl -D $PGDATA start
查看
[postgres@postgres-test01-0001 pgdata]$ ps -ef |grep postgres
root 12117 1531 0 15:00 pts/0 00:00:00 su - postgres
postgres 12118 12117 0 15:00 pts/0 00:00:00 -bash
postgres 12344 1 0 15:12 pts/0 00:00:00 /data/pgsql-9.4.16/bin/postgres -D /data/pgdata
postgres 12346 12344 0 15:12 ? 00:00:00 postgres: checkpointer process
postgres 12347 12344 0 15:12 ? 00:00:00 postgres: writer process
postgres 12348 12344 0 15:12 ? 00:00:00 postgres: wal writer process
postgres 12349 12344 0 15:12 ? 00:00:00 postgres: autovacuum launcher process
postgres 12350 12344 0 15:12 ? 00:00:00 postgres: stats collector process
postgres 12360 12118 0 15:17 pts/0 00:00:00 ps -ef
postgres 12361 12118 0 15:17 pts/0 00:00:00 grep --color=auto postgres
[postgres@postgres-test01-0001 pgdata]$ netstat -lantp|grep postgres
tcp 0 0 0.0.0.0:5456 0.0.0.0:* LISTEN 12344/postgres
tcp6 0 0 :::5456 :::* LISTEN 12344/postgres
[postgres@postgres-test01-0001 pgdata]$ psql
psql (9.4.16)
Type "help" for help.
postgres=#
至此安装数据库成功