1. 说明
    在鲲鹏云环境中的CentOS7.5中,yum源自带的PostgreSQL版本是9.2,目前主流使用的10的版本,所以需要编译安装。本安装使用了与官方二进程版本相同的编译参数,所以编译出的PostgreSQL的特性与PostgreSQL官方版本在x86平台上的版本是相同的。
  1. 基础环境配置

2.1 更换yum源
以root用户登录弹性云服务器

执行以下命令,备份CentOS-Base.repo文件。

mkdir -p /etc/yum.repos.d/repo_bak/
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo_bak/
使用curl命令下载对应版本的CentOS-Base.repo文件,并将其放入/etc/yum.repos.d/目录。

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.myhuaweicloud.com/repo/Centos-altarch-7.repo
执行以下命令,生成缓存。

yum makecache
更新yum

yum update
2.2 安装所需的包
yum install -y libicu-devel.aarch64
yum install -y perl-ExtUtils-Embed
yum install -y libxml2 libxml2-devel
yum install -y libxslt-devel.aarch64
yum install -y openldap-devel.aarch64
yum install -y systemd-devel.aarch64
yum install -y python-devel.aarch64
2.3 创建pg用户及目录
此步骤也可以放在编译完成之后初始化数据库时再执行。

groupadd -g 701 postgres
useradd -u 701 -g 701 -s /bin/bash postgres

mkdir -p /usr/csudata
mkdir -p /u01/pgdata
chown -R postgres.postgres /u01/pgdata
chmod -R 700 /u01/pgdata
su - postgres
vi .bash_profile

.bash_profile

Get the aliases and functionsif [ -f ~/.bashrc ]; then

. ~/.bashrcfi

User specific environment and startup programs

PATH=/usr/csudata/pgsql-10/bin:$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export PGDATA=/u01/pgdata
export PGHOST=/tmp
source .bash_profile
3 postgres编译安装
3.1 解压源码包
[root@ecs-cs01-0001 ~]$ cd /usr/src
[root@ecs-cs01-0001 src]# ls
postgresql-10.9.tar.bz2
[root@ecs-cs01-0001 ~]$ tar jxvf postgresql-10.9.tar.bz2
[root@ecs-cs01-0001 ~]$ cd /usr/src/postgresql-10.9
3.2 编译
[root@ecs-cs01-0001 postgresql-10.9]# ./configure —enable-rpath —prefix=/usr/csudata/pgsql-10 —includedir=/usr/csudata/pgsql-10/include —mandir=/usr/csudata/pgsql-10/share/man —datadir=/usr/csudata/pgsql-10/share —with-icu —with-perl —with-python —with-tcl —with-tclconfig=/usr/lib64 —with-openssl —with-pam —with-gssapi —with-includes=/usr/include —with-libraries=/usr/lib64 —enable-nls —with-uuid=e2fs —with-libxml —with-libxslt —with-ldap —with-selinux —with-systemd —with-system-tzdata=/usr/share/zoneinfo —sysconfdir=/etc/sysconfig/pgsql —docdir=/usr/csudata/pgsql-10/doc —htmldir=/usr/csudata/pgsql-10/doc/html
[root@ecs-cs01-0001 postgresql-10.9]# make && make install
3.3 编译成功后的目录文件
[root@ecs-cs01-0001 postgresql-10.9]# ll /usr/csudata/pgsql-10
total 16
drwxr-xr-x 2 root root 4096 Aug 7 11:57 bin
drwxr-xr-x 6 root root 4096 Aug 7 11:56 include
drwxr-xr-x 4 root root 4096 Aug 7 11:57 lib
drwxr-xr-x 6 root root 4096 Aug 7 11:57 share
3.4 初始化数据库
编译成功后我们就可以初始化数据库了

[postgres@ecs-cs01-0001 ~]$ echo $PGDATA
/u01/pgdata
[postgres@ecs-cs01-0001 ~]$ initdb
3.5 启动数据库
[postgres@ecs-cs01-0001 ~]$ pg_ctl start

4 问题及解决方法
问题1:

configure: error: Package requirements (icu-uc icu-i18n) were not met:No package ‘icu-uc’ found
No package ‘icu-i18n’ found
解决办法:

[root@ecs-cs01-0001 postgresql-10.9]# yum install libicu-devel.aarch64
问题2:

configure: error: could not determine flags for linking embedded Perl.
This probably means that ExtUtils::Embed or ExtUtils::MakeMaker is notinstalled.
解决办法:

[root@ecs-cs01-0001 postgresql-10.9]# yum install perl-ExtUtils-Embed -y
问题3:

configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure. It is possible the compiler isn’t looking in the proper directory.
Use —without-readline to disable readline support.
解决办法:

[root@ecs-cs01-0001 postgresql-10.9]# yum install -y readline readline-devel
问题4:

configure: error: library ‘pam’ is required for PAM
解决办法:

[root@ecs-cs01-0001 postgresql-10.9]# yum install -y pam pam-devel
问题5:

configure: error: library ‘xml2’ (version >= 2.6.23) is required for XML support
解决办法:

[root@ecs-cs01-0001 postgresql-10.9]# yum install -y libxml2 libxml2-devel
问题6:

configure: error: library ‘xslt’ is required for XSLT support
解决办法:

[root@ecs-cs01-0001 postgresql-10.9]# yum install -y libxslt-devel.aarch64
问题7:

configure: error: library ‘ldap’ is required for LDAP
解决办法:

[root@ecs-cs01-0001 postgresql-10.9]# yum install -y openldap-devel.aarch64
问题8:

configure: error: header file is required for systemd support
解决办法:

[root@ecs-cs01-0001 postgresql-10.9]# yum install -y systemd-devel.aarch64
问题9:

configure: error: header file is required for Python
解决办法:

[root@ecs-cs01-0001 postgresql-10.9]# yum install -y python-devel.aarch64

0 评论  
添加一条新评论