目录
创建.pgpass文件,指定超级用户为pgadmin 实现免密登录
创建postgres用户
[root@localhost ~]# groupadd postgres
[root@localhost ~]# useradd -g postgres postgres
[root@localhost ~]# passwd postgres
配置yum仓库
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vi local.repo
[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0
挂载镜像站
[root@localhost yum.repos.d]# mount /dev/cdrom /mnt
刷新仓库
[root@localhost yum.repos.d]# yum clean all && yum repolist all
检查openssl是否安装,没有安装需要安装一下
[root@localhost yum.repos.d]# yum list installed | grep openssl
[root@localhost yum.repos.d]# yum install -y openssl-devel gcc gcc-c++ readline-devel zlib-devel
创建安装目录
[root@localhost yum.repos.d]# su - postgres
[postgres@localhost ~]$ mkdir /home/postgres/soft
上传源码并解压
[postgres@localhost ~]$ cd ~
[postgres@localhost ~]$ mkdir resoruce
[postgres@localhost ~]$ cd resoruce/
[postgres@localhost resoruce]$ ls
postgresql-12.0.tar
[postgres@localhost resoruce]$ tar -xvf postgresql-12.0.tar
编译环境检查
[postgres@localhost resoruce]$ cd postgresql-12.0
[postgres@localhost postgresql-12.0]$ ./configure --prefix=/home/postgres/soft/ --with-openssl --with-pgport=5666
编译安装
这里可以不加word 需要的时候再编译也可以 4核可以用j4编译
[postgres@localhost postgresql-12.0]$ make world -j4
[postgres@localhost postgresql-12.0]$ make install-world -j4
检查是否安装成功(出现4个目录即可)
[postgres@localhost postgresql-12.0]$ cd /home/postgres/soft/
[postgres@localhost soft]$ ls
bin include lib share
初始化数据库 并开启checksum(参数 -k)
[postgres@localhost soft]$ /home/postgres/soft/bin/initdb -D /home/postgres/data -k
启动数据库
[postgres@localhost soft]$ /home/postgres/soft/bin/pg_ctl -D /home/postgres/data -l /tmp/logfile start
配置环境变量
[postgres@localhost ~]$ vi ~/.bashrc
export PGHOME=/home/postgres/soft
export PGDATA=${PGHOME}/../data
export PATH=${PGHOME}/bin:${PATH}
[postgres@localhost ~]$ source ~/.bashrc
创建一个超级用户pgadmin
[postgres@localhost ~]$ psql -d postgres
postgres=# create user pgadmin with superuser password '1qaz@WSX';
创建.pgpass文件,指定超级用户为pgadmin 实现免密登录
[postgres@localhost soft]$ cd ~
[postgres@localhost ~]$ touch ~/.pgpass
[postgres@localhost ~]$ chmod 0600 ~/.pgpass
[postgres@localhost ~]$ vi ~/.pgpass
#hostname:port:database:username:password
localhost:5666:postgres:pgadmin:1qaz@WSX