一、背景
因工作需要,需要修改pg部分源码,然后重新编译打包。
为了保持与postgresql官方提供的rpm包兼容性,尽量采用官方的编译打包脚本,做到和官方一直的编译和打包选项。
二、环境准备
1. 系统
CentOS6.9 (minimal模式安装)
2. 安装编译相关组件
/* 1. 安装编译工具gcc*/
# yum install gcc
/* 2. 安装wget */
# yum install wget
/* 3. 安装rpm打包工具rpm-build */
# yum install rpm-build
/* 4. 安装postgresql编译依赖组件 */
# yum install bison flex perl-ExtUtils-Embed perl python-devel tcl-devel readline-devel openssl-devel krb5-devel e2fsprogs-devel libxml2-devel libxslt-devel pam-devel libuuid-devel openldap-devel openjade opensp docbook-dtds
# yum install libicu-devel gettext
/* 5. centos 7 下编译,需要安装systemd-devel */
# yum install systemd-devel
3. 用户
/* 1. 添加普通用户 */
useradd postgres
passwd postgres
/* 2. 切换到普通用户postgres */
su – postgres
三、编译测试
编译测试,主要用于检查是否缺失相关编译组件
/* 1. postgres用户下 */
mkdir ws
cd ws
/* 2. 下载postgresql 10.5 源码 */
wget https://ftp.postgresql.org/pub/source/v10.5/postgresql-10.5.tar.bz2
/* 编译测试 */
tar jxvf postgresql-10.5.tar.bz2
cd postgresql-10.5
./configure
make -j4
四、打包rpm
/* 1. 切换到postgres用户下 */
su - postgres
/* 2. 下载打包rpm的工程源码 */
git clone git://git.postgresql.org/git/pgrpms.git
方案1:自动下载/更新源码并打包
此方案要求安装了gnome桌面,因为创建证书过程中,用到窗口界面。
/* 1. 创建rpm签名证书 */
$gpg --gen-key
gpg (GnuPG) 2.0.14; Copyright (C) 2009 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 2048
Requested keysize is 2048 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) y
GnuPG needs to construct a user ID to identify your key.
Real name: www.atlasdata.com.cn
Email address: support@atlasdata.com.cn
Comment: rpm signature
You selected this USER-ID:
"www.atlasdata.com.cn (rpm signature) <support@atlasdata.com.cn>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.
can't connect to `/home/appusr/.gnupg/S.gpg-agent': No such file or directory
gpg-agent[4479]: directory `/home/appusr/.gnupg/private-keys-v1.d' created
/* (此时会弹出图形应用程序,输入并验证密钥)*/
(pinentry-gtk-2:4480): GLib-GObject-CRITICAL **: Object class GtkSecureEntry doesn't implement property 'editing-canceled' from interface 'GtkCellEditable'
(pinentry-gtk-2:4488): GLib-GObject-CRITICAL **: Object class GtkSecureEntry doesn't implement property 'editing-canceled' from interface 'GtkCellEditable'
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: key 6FCA3280 marked as ultimately trusted
public and secret key created and signed.
gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
pub 2048R/6FCA3280 2018-08-22
Key fingerprint = 731C 0727 E8CD BFAC C08A E062 0E3D EA4E 6FCA 3280
uid www.atlasdata.com.cn (rpm signature) <support@atlasdata.com.cn>
sub 2048R/ED8C7AE7 2018-08-22
/* 2. 导出公钥文件 */
gpg --export --armor www.atlasdata.com.cn > ATLASDATA-RPM-GPG-KEY
/* 3. 配置rpmbuild使用刚才创建的文件:把以下内容添加到~/.rpmmacros文件中 */
%_topdir /home/postgres/rpmbuild
%_signature gpg
%_gpg_name www.atlasdata.com.cn (rpm signature) <support@atlasdata.com.cn>
/* 4. 打包postgresql10 */
cd /home/postgres/pgrpms/rpm/redhat/10/postgresql/EL-6
make build10
/* 5. 打包结果 */
cd /home/postgres/rpm10/RPMS
方案2:手工下载源码打包
/* 在home目录下创建rpmbuild目录 */
mkdir -p -v ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
/* 把pgrpms项目中与本地系统版本相对应目录中的文件复制到创建的SOURCES目录下 */
cp ~/pgrpms/rpm/redhat/10/postgresql/EL-6/* ~/rpmbuild/SOURCES
cd ~/rpmbuild/SOURCES
/* 把PG10.5源码包以及PG10.5的PDF文档复制到/home/redhat/rpmbuild/SOURCE */
postgresql-10.5.tar.bz2
postgresql-10-A4.pdf
/* 打包postgresql */
[postgres@hemny SOURCES]$ rpmbuild -bb postgresql-10.spec
error: Bad source: /home/postgres/rpmbuild/SOURCES/postgresql-%{pgmajorversion}-rpm-pgsql.patch: No such file or directory
/* 修改postgresql-10.spec文件,在第三行插入 %global pgmajorversion 10,然后保存退出,内容如下 */
>> # These are macros to be used with find_lang and other stuff
>> %global packageversion 100
>> %global pgpackageversion 10
>> %global pgmajorversion 10 /* 添加的行 */
>> %global prevmajorversion 9.6
>> %global sname postgresql
/* 重写执行打包命令 */
[postgres@hemny SOURCES]$ rpmbuild -bb postgresql-10.spec
/* 打包结果 */
cd ~/rpmbuild/RPMS/x86_64/
五、总结
采用postgresql官方提供的pgrpms进行编译和打包rpm,可以尽可能的保持与官方rpm包的编译选项统一、稳定性最接近。
网友评论