PostgreSQL 10编译安装(CentOS 7)

文档版本:v1.0

环境说明:

PostgreSQL 10.9

CentOS 7.6



1 安装必要软件

# yum groupinstall -y "Development tools"

# yum install -y bison flex readline-devel zlib-devel gcc

2 获取Postgres资源并编译安装

可通过访问https://www.postgresql.org/ftp/source/确定所需版本,以下使用10.9版本进行安装。

# pwd

/opt

# wget https://ftp.postgresql.org/pub/source/v10.9/postgresql-10.9.tar.gz

# tar xf postgresql-10.9.tar.gz

# cd postgresql-10.9/

# ./configure --prefix=/opt/pg10/

(部分输出内容省略)

config.status: creating GNUmakefile

config.status: creating src/Makefile.global

config.status: creating src/include/pg_config.h

config.status: creating src/include/pg_config_ext.h

config.status: creating src/interfaces/ecpg/include/ecpg_config.h

config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s

config.status: linking src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c

config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c

config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c

config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h

config.status: linking src/include/port/linux.h to src/include/pg_config_os.h

config.status: linking src/makefiles/Makefile.linux to src/Makefile.port

# make && make install

(部分输出内容省略)

make[1]: Leaving directory `/opt/postgresql-10.9/src‘

make -C config install

make[1]: Entering directory `/opt/postgresql-10.9/config‘

/usr/bin/mkdir -p ‘/opt/pg10/lib/postgresql/pgxs/config‘

/usr/bin/install -c -m 755 ./install-sh ‘/opt/pg10/lib/postgresql/pgxs/config/install-sh‘

/usr/bin/install -c -m 755 ./missing ‘/opt/pg10/lib/postgresql/pgxs/config/missing‘

make[1]: Leaving directory `/opt/postgresql-10.9/config‘

PostgreSQL installation complete.

# /opt/pg10/bin/postgres --version

postgres (PostgreSQL) 10.9

3 创建用户

# groupadd -g 2000 postgres

# useradd -g 2000 -u 2000 postgres

# id postgres

# uid=2000(postgres) gid=2000(postgres) groups=2000(postgres)

4 创建路径及权限修改

# mkdir -p /pgdata/10/{data,backups,scripts,archive_wals}

# chown -R postgres:postgres /pgdata/10

# chown -R postgres:postgres /opt/pg10

# chmod 0700 /pgdata/10/data

5 环境变量

# su - postgres

$ cat .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# User specific environment and startup programs

export PATH

export PGHOME=/opt/pg10

export PGDATA=/pgdata/10

PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin

$ source .bash_profile

6 初始化数据库

$ /opt/pg10/bin/initdb -D /pgdata/10/data/ -W

The files belonging to this database system will be owned by user "postgres".

This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".

The default database encoding has accordingly been set to "UTF8".

The default text search configuration will be set to "english".

Data page checksums are disabled.

Enter new superuser password:

Enter it again:

fixing permissions on existing directory /pgdata/10/data ... ok

creating subdirectories ... ok

selecting default max_connections ... 100

selecting default shared_buffers ... 128MB

selecting default timezone ... PRC

selecting dynamic shared memory implementation ... posix

creating configuration files ... ok

running bootstrap script ... ok

performing post-bootstrap initialization ... ok

syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections

You can change this by editing pg_hba.conf or using the option -A, or

--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /opt/pg10/bin/pg_ctl -D /pgdata/10/data/ -l logfile start

7 启动&关闭

--启动命令

$ pg_ctl -D /pgdata/10/data start

waiting for server to start....2019-07-19 18:24:02.926 CST [31065] LOG:  listening on IPv6 address "::1", port 5432

2019-07-19 18:24:02.926 CST [31065] LOG:  listening on IPv4 address "127.0.0.1", port 5432

2019-07-19 18:24:02.929 CST [31065] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"

2019-07-19 18:24:02.943 CST [31066] LOG:  database system was shut down at 2019-07-19 18:21:30 CST

2019-07-19 18:24:02.946 CST [31065] LOG:  database system is ready to accept connections

 done

server started

--查看后台进程

$ ps -ef|grep postgres:

postgres  31100  31098  0 18:25 ?        00:00:00 postgres: checkpointer process  

postgres  31101  31098  0 18:25 ?        00:00:00 postgres: writer process  

postgres  31102  31098  0 18:25 ?        00:00:00 postgres: wal writer process  

postgres  31103  31098  0 18:25 ?        00:00:00 postgres: autovacuum launcher process  

postgres  31104  31098  0 18:25 ?        00:00:00 postgres: stats collector process  

postgres  31105  31098  0 18:25 ?        00:00:00 postgres: bgworker: logical replication launcher 

postgres  31107  30025  0 18:25 pts/1    00:00:00 grep --color=auto postgres:

--登录验证

$ /opt/pg10/bin/pg_isready -p 5432

/tmp:5432 - accepting connections

$ psql -p 5432 -U postgres -d postgres

psql (10.9)

Type "help" for help.

postgres=# \q

$
--关闭命令

$ pg_ctl -D /pgdata/10/data/ -ms stop

8 修改白名单

PG默认不允许远程访问数据库,可以通过修改监听地址、修改pg_hba.conf文件来实现远程访问。

--修改监听地址

将配置文件中listen_addresses的值由‘localhost‘修改为‘listen_addresses‘。

$ cp /pgdata/10/data/postgresql.conf /pgdata/10/data/postgresql.conf.bak

$ grep listen /pgdata/10/data/postgresql.conf

listen_addresses = ‘*‘                # what IP address(es) to listen on;

$ pg_ctl -D /pgdata/10/data/ -ms stop

$ pg_ctl -D /pgdata/10/data start

--修改pg_hba.conf文件

$ cp /pgdata/10/data/pg_hba.conf /pgdata/10/data/pg_hba.conf.bak

$ echo "host postgres postgres 0.0.0.0/0 md5" >> /pgdata/10/data/pg_hba.conf

--重新加载配置文件

$  /opt/pg10/bin/pg_ctl -D /pgdata/10/data/ reload

server signaled

参考资料:

《PostgreSQL实战》-第一章

《PostgreSQL 10.1手册》-服务器管理-16.从源码安装

https://blog.csdn.net/helloworld_dream/article/details/81483235

https://www.cnblogs.com/tplife2019/p/10234275.html

http://www.mamicode.com/info-detail-2373348.html



Keep moving

Tank

2019.7.19

原文地址:https://www.cnblogs.com/pgertank/p/11216120.html

时间: 2024-11-05 18:52:31

PostgreSQL 10编译安装(CentOS 7)的相关文章

编译安装 Centos 7 x64 + tengine.2.0.3 (实测+笔记)

环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:CentOS Linux release 7.0.1406 安装步骤: 1.系统环境 1.1 更新系统 [[email protected] ~]# yum update -y 1.2 查看环境 [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core) [[email protected] ~]#

ubuntu 13.10 编译安装conkeror

conkeror几年前我用过,还是一个不错的浏览器,这次因为笔记本只支持Ubuntu 13.10, 而不支持更新版本,就尝试着在Ubuntu 13.10上安装最新conkeror,但是没想到居然没有安装源.于是就编译吧, 当然还是要首先clone到源代码: git clone git://repo.or.cz/conkeror.git 然后根据官方文档的提示: To build your own Conkeror package, install fakeroot, quilt, and deb

Apache httpd-2.4.10编译安装

系统: CentOS6.5_64 软件: httpd-2.4.10.tar.bz2 依赖: openssl-1.0.1j.tar.gz.apr-1.5.1.tar.bz2.apr-util-1.5.4.tar.bz2.pcre-devel 下载地址: http://www.openssl.org/source/            openssl 下载地址: http://httpd.apache.org/download.cgi      httpd 下载地下: http://apr.apa

Ubuntu 18.04 下 PostgreSQL 10 的安装与基础配置

下载安装 在命令行执行如下语句: apt-get install postgresql-10 该指令会帮助你下载如下PostgreSQL组件: ` | ` -- | -- postgresql-client-10 | client libraries and client binaries postgresql-10 | core database server postgresql-contrib-9.x | additional supplied modules (part of the p

rehat7.X下postgresql 11编译安装

文档目录结构: 一.准备 操作系统版本:rehat7.6 Postgresql:11.2 软件安装目录:/pgsql11/basedir 数据文件存放目录:/pgsql11data/ 11.2的下载地址: https://www.postgresql.org/ftp/source/v11.2/ 1.修改防火墙: vim /etc/selinux/config 修改内容: SELINUX=disabled systemctl disable firewalld systemctl stop  fi

ubuntu 14.10 编译安装 Python

从源代码直接编译安装Python2.7 $ wget -c https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz $ tar -xzvf Python-2.7.9.tgz $ cd Python-2.7.9/ $ LDFLAGS="-L/usr/lib/x86_64-linux-gnu" ./configure $ make $ sudo make install 其中, 上面的wget -c (url)是下载命令,参数-c表

ubuntu 14.10 编译安装 Ruby

源码编译安装ruby-2.2 1.获取源码包: wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz 2.安装依赖包 sudo apt-get install -y build-essential openssl curl libcurl3-dev libreadline6 libreadline6-dev git zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev li

linux centos 6.10 编译安装mysql5.6.40版本,数据库主从

主机1 MYSQL配置: /etc/my.cnf : server_id = 41 log_bin=mysql-binbinlog-do-db =dbb1000log_bin_trust_function_creators=TRUEbinlog-ignore-db=mysqlbinlog-ignore-db=information_schemabinlog-ignore-db=performance_schemabinlog-ignore-db=test 给从库添加复制用户: grant rep

Nginx1.10编译安装

企业实战千万PV的Nginx就得这么安装 更多文章请访问 乌龟运维 wuguiyunwei.com 已经上线六个个多月 现在非常稳定 这是现在的整理 Nginx 下载 wget http://nginx.org/download/nginx-1.10.3.tar.gz Openssl 下载 Wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz Pcre 下载 wget ftp://ftp.csx.cam.ac.uk/pub/softw