1. 程式人生 > >企業rpm包的定制

企業rpm包的定制

linux rpm定制 yum

本文以mysql5.5.32源碼源碼包為例定制rpm包,好我就不再啰嗦了直接實戰。更詳細內容請看下方博文。

http://blog.51cto.com/oldboy/1121725

http://oldboy.blog.51cto.com/2561410/1121745

http://blog.51cto.com/dreamway/1110822

特別註意:rpm打包不需要使用root權限,如果一條指令寫錯是很致命的,所以我們用普通用戶定制rpm包。

1.安裝打包工具

[linzhongniao@rpmbaozhizuo ~]# yum install rpm-build –y

2.規劃打包目錄

[linzhongniao@rpmbaozhizuo ~]$ vim .rpmmacros
[linzhongniao@rpmbaozhizuo ~]$ cat .rpmmacros
%_topdir    /home/linzhongniao/rpmbuild
[linzhongniao@rpmbaozhizuo ~]$ mkdir -p /home/linzhongniao/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
[linzhongniao@rpmbaozhizuo ~]$ tree /home/linzhongniao/rpmbuild/
/home/linzhongniao/rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS

3.mysql-5.5.32打包實戰

[linzhongniao@rpmbaozhizuo ~]$ mkdir -p /home/linzhongniao/tools
[linzhongniao@rpmbaozhizuo ~]$ cd /home/linzhongniao/tools

我們將mysql-5.5.32安裝包放到新建的這個裏面

[linzhongniao@rpmbaozhizuo tools]$ ls
mysql-5.5.32.tar.gz

我們把源碼包和啟動腳本放到/home/linzhongniao/rpmbuild/SOURCES/下

[linzhongniao@rpmbaozhizuo tools]$ cp mysql-5.5.32.tar.gz /home/linzhongniao/rpmbuild/SOURCES/
[linzhongniao@rpmbaozhizuo ~]$ cp /home/linzhongniao/tools/mysql-5.5.32/support-files/mysql.server.sh /home/linzhongniao/rpmbuild/SOURCES/

我們先登錄到root用戶解壓mysql-5.5.32並查找一下.spec文件在哪,查找到在哪,再切換回普通用戶將.spce放到/home/linzhongniao/
rpmbuild/SPECS/下 。

 [root@rpmbaozhizuo ~]# find / -name *.spec
/home/linzhongniao/tools/mysql-5.5.32/support-files/mysql.5.5.32.spec
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgomp.spec
/usr/share/vim/vimfiles/template.spec
[linzhongniao@rpmbaozhizuo tools]$ cp /home/linzhongniao/tools/mysql-5.5.32/support-files/mysql.5.5.32.spec /home/linzhongniao/rpmbuild/SPECS/
 [linzhongniao@rpmbaozhizuo ~]$ ll /home/linzhongniao/rpmbuild/SPECS/
總用量 80
 -rw-r--r--. 1 linzhongniao linzhongniao 81051 3月   8 07:09 mysql.5.5.32.spec

查看一下目錄結構

[linzhongniao@rpmbaozhizuo ~]$ tree /home/linzhongniao/rpmbuild/
/home/linzhongniao/rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
│   ├── mysql-5.5.32.tar.gz
│   └── mysql.server.sh
├── SPECS
│   └── mysql.5.5.32.spec
└── SRPMS

4.開始打包

Mysql5.5版本以後需要cmake安裝,所以我們先安裝cmake再開始打包
安裝cmake很簡單直接configure,gmake&&gmake install就可以。

[linzhongniao@rpmbaozhizuo ~]$ rpmbuild  -v -ba /home/linzhongniao/rpmbuild/SPECS/mysql.5.5.32.spec >>/tmp/install.log
error: Failed build dependencies:
    gperf is needed by MySQL-5.5.32-2.linux2.6.x86_64
    ncurses-devel is needed by MySQL-5.5.32-2.linux2.6.x86_64
    readline-devel is needed by MySQL-5.5.32-2.linux2.6.x86_64
    time is needed by MySQL-5.5.32-2.linux2.6.x86_64

好我們上面就是打包的結果,報錯了,缺少依賴包,這些依賴包在mysql.5.5.32.spec都定義了。在進行打包時,如果缺少依賴包就會報錯打包不成功。

define distro_buildreq   gcc-c++ gperf ncurses-devel perl readline-devel time zlib-devel

好我們把缺少的安裝上再打包

[root@rpmbaozhizuo cmake-2.8.8]# yum install gperf ncurses-devel readline-devel time –y
[linzhongniao@rpmbaozhizuo ~]$ rpmbuild  -v -ba /home/linzhongniao/rpmbuild/SPECS/mysql.5.5.32.spec >>/tmp/install.log
+ umask 022
+ cd /home/linzhongniao/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/linzhongniao/rpmbuild/BUILD
+ rm -rf mysql-5.5.32
+ /bin/mkdir -p mysql-5.5.32
+ cd mysql-5.5.32
+ /usr/bin/gzip -dc /home/linzhongniao/rpmbuild/SOURCES/mysql-5.5.32.tar.gz
+ /bin/tar -xvvf –
……省略…..
CMake Error at cmake/build_configurations/mysql_release.cmake:126 (MESSAGE):

  aio is required on Linux, you need to install the required library:

Debian/Ubuntu:  apt-get install libaio-dev
RedHat/Fedora/Oracle Linux: yum install libaio-devel
SuSE:   zypper install libaio-devel

  If you really do not want it, pass -DIGNORE_AIO_CHECK to cmake.

Call Stack (most recent call first):
  CMakeLists.txt:97 (INCLUDE)

error: Bad exit status from /var/tmp/rpm-tmp.jKr0Jj (%build)
Bad exit status from /var/tmp/rpm-tmp.jKr0Jj (%build)

哎啊,我們看又出錯了,提示說需要安裝libaio-devel,我們就把這個包裝上再打包,看到下面的Wrote表示打包完成。

[root@rpmbaozhizuo cmake-2.8.8]# yum install libaio-devel  -y
[linzhongniao@rpmbaozhizuo ~]$ rpmbuild  -v -ba /home/linzhongniao/rpmbuild/SPECS/mysql.5.5.32.spec >>/tmp/install.log
+ umask 022
+ cd /home/linzhongniao/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/linzhongniao/rpmbuild/BUILD
…….省略…….
Wrote: /home/linzhongniao/rpmbuild/SRPMS/MySQL-5.5.32-2.linux2.6.src.rpm
Wrote: /home/linzhongniao/rpmbuild/RPMS/x86_64/MySQL-server-5.5.32-2.linux2.6.x86_64.rpm
Wrote: /home/linzhongniao/rpmbuild/RPMS/x86_64/MySQL-client-5.5.32-2.linux2.6.x86_64.rpm
Wrote: /home/linzhongniao/rpmbuild/RPMS/x86_64/MySQL-test-5.5.32-2.linux2.6.x86_64.rpm
Wrote: /home/linzhongniao/rpmbuild/RPMS/x86_64/MySQL-devel-5.5.32-2.linux2.6.x86_64.rpm
Wrote: /home/linzhongniao/rpmbuild/RPMS/x86_64/MySQL-shared-5.5.32-2.linux2.6.x86_64.rpm
Wrote: /home/linzhongniao/rpmbuild/RPMS/x86_64/MySQL-embedded-5.5.32-2.linux2.6.x86_64.rpm
……省略…….
exit 0

5.列出RPM軟件包內的文件信息

[linzhongniao@rpmbaozhizuo ~]$ rpm -qpl /home/linzhongniao/rpmbuild/RPMS/x86_64/MySQL-server-5.5.32-2.linux2.6.x86_64.rpm 
/etc/init.d/mysql
/etc/logrotate.d/mysql
/etc/my.cnf
/usr/bin/innochecksum
/usr/bin/my_print_defaults
/usr/bin/myisam_ftdump
/usr/bin/myisamchk
/usr/bin/myisamlog
/usr/bin/myisampack
/usr/bin/mysql_convert_table_format
/usr/bin/mysql_fix_extensions
/usr/bin/mysql_install_db
/usr/bin/mysql_plugin
/usr/bin/mysql_secure_installation
/usr/bin/mysql_setpermission
/usr/bin/mysql_tzinfo_to_sql
/usr/bin/mysql_upgrade
/usr/bin/mysql_zap
/usr/bin/mysqlbug
/usr/bin/mysqld_multi
/usr/bin/mysqld_safe
/usr/bin/mysqldumpslow
/usr/bin/mysqlhotcopy
/usr/bin/mysqltest
/usr/bin/perror
/usr/bin/replace
/usr/bin/resolve_stack_dump
/usr/bin/resolveip
/usr/lib64/mysql/plugin/adt_null.so
/usr/lib64/mysql/plugin/auth.so
/usr/lib64/mysql/plugin/auth_socket.so
/usr/lib64/mysql/plugin/auth_test_plugin.so
/usr/lib64/mysql/plugin/daemon_example.ini
/usr/lib64/mysql/plugin/debug/adt_null.so
/usr/lib64/mysql/plugin/debug/auth.so
/usr/lib64/mysql/plugin/debug/auth_socket.so
/usr/lib64/mysql/plugin/debug/auth_test_plugin.so
/usr/lib64/mysql/plugin/debug/libdaemon_example.so
/usr/lib64/mysql/plugin/debug/mypluglib.so
/usr/lib64/mysql/plugin/debug/qa_auth_client.so
/usr/lib64/mysql/plugin/debug/qa_auth_interface.so
/usr/lib64/mysql/plugin/debug/qa_auth_server.so
/usr/lib64/mysql/plugin/debug/semisync_master.so
/usr/lib64/mysql/plugin/debug/semisync_slave.so
/usr/lib64/mysql/plugin/libdaemon_example.so
/usr/lib64/mysql/plugin/mypluglib.so
/usr/lib64/mysql/plugin/qa_auth_client.so
/usr/lib64/mysql/plugin/qa_auth_interface.so
/usr/lib64/mysql/plugin/qa_auth_server.so
/usr/lib64/mysql/plugin/semisync_master.so
/usr/lib64/mysql/plugin/semisync_slave.so
/usr/sbin/mysqld
/usr/sbin/mysqld-debug
/usr/sbin/rcmysql
/usr/share/doc/MySQL-server-5.5.32
/usr/share/doc/MySQL-server-5.5.32/COPYING
/usr/share/doc/MySQL-server-5.5.32/ChangeLog
/usr/share/doc/MySQL-server-5.5.32/INFO_BIN
/usr/share/doc/MySQL-server-5.5.32/INFO_SRC
/usr/share/doc/MySQL-server-5.5.32/README
/usr/share/doc/MySQL-server-5.5.32/my-huge.cnf
/usr/share/doc/MySQL-server-5.5.32/my-innodb-heavy-4G.cnf
/usr/share/doc/MySQL-server-5.5.32/my-large.cnf
/usr/share/doc/MySQL-server-5.5.32/my-medium.cnf
/usr/share/doc/MySQL-server-5.5.32/my-small.cnf
/usr/share/info/mysql.info.gz
/usr/share/man/man1/innochecksum.1.gz
/usr/share/man/man1/my_print_defaults.1.gz
/usr/share/man/man1/myisam_ftdump.1.gz
/usr/share/man/man1/myisamchk.1.gz
/usr/share/man/man1/myisamlog.1.gz
/usr/share/man/man1/myisampack.1.gz
/usr/share/man/man1/mysql.server.1.gz
/usr/share/man/man1/mysql_convert_table_format.1.gz
/usr/share/man/man1/mysql_fix_extensions.1.gz
/usr/share/man/man1/mysql_install_db.1.gz
/usr/share/man/man1/mysql_plugin.1.gz
/usr/share/man/man1/mysql_secure_installation.1.gz
/usr/share/man/man1/mysql_setpermission.1.gz
/usr/share/man/man1/mysql_tzinfo_to_sql.1.gz
/usr/share/man/man1/mysql_upgrade.1.gz
/usr/share/man/man1/mysql_zap.1.gz
/usr/share/man/man1/mysqlbug.1.gz
/usr/share/man/man1/mysqld_multi.1.gz
/usr/share/man/man1/mysqld_safe.1.gz
/usr/share/man/man1/mysqldumpslow.1.gz
/usr/share/man/man1/mysqlhotcopy.1.gz
/usr/share/man/man1/mysqlman.1.gz
/usr/share/man/man1/mysqltest.1.gz
/usr/share/man/man1/perror.1.gz
/usr/share/man/man1/replace.1.gz
/usr/share/man/man1/resolve_stack_dump.1.gz
/usr/share/man/man1/resolveip.1.gz
/usr/share/man/man8/mysqld.8.gz
/usr/share/mysql
/usr/share/mysql/SELinux
/usr/share/mysql/SELinux/RHEL4
/usr/share/mysql/SELinux/RHEL4/mysql.fc
/usr/share/mysql/SELinux/RHEL4/mysql.te
/usr/share/mysql/binary-configure
/usr/share/mysql/charsets
/usr/share/mysql/charsets/Index.xml
/usr/share/mysql/charsets/README
/usr/share/mysql/charsets/armscii8.xml
/usr/share/mysql/charsets/ascii.xml
/usr/share/mysql/charsets/cp1250.xml
/usr/share/mysql/charsets/cp1251.xml
/usr/share/mysql/charsets/cp1256.xml
/usr/share/mysql/charsets/cp1257.xml
/usr/share/mysql/charsets/cp850.xml
/usr/share/mysql/charsets/cp852.xml
/usr/share/mysql/charsets/cp866.xml
/usr/share/mysql/charsets/dec8.xml
/usr/share/mysql/charsets/geostd8.xml
/usr/share/mysql/charsets/greek.xml
/usr/share/mysql/charsets/hebrew.xml
/usr/share/mysql/charsets/hp8.xml
/usr/share/mysql/charsets/keybcs2.xml
/usr/share/mysql/charsets/koi8r.xml
/usr/share/mysql/charsets/koi8u.xml
/usr/share/mysql/charsets/latin1.xml
/usr/share/mysql/charsets/latin2.xml
/usr/share/mysql/charsets/latin5.xml
/usr/share/mysql/charsets/latin7.xml
/usr/share/mysql/charsets/macce.xml
/usr/share/mysql/charsets/macroman.xml
/usr/share/mysql/charsets/swe7.xml
/usr/share/mysql/config.huge.ini
/usr/share/mysql/config.medium.ini
/usr/share/mysql/config.small.ini
/usr/share/mysql/czech
/usr/share/mysql/czech/errmsg.sys
/usr/share/mysql/danish
/usr/share/mysql/danish/errmsg.sys
/usr/share/mysql/dutch
/usr/share/mysql/dutch/errmsg.sys
/usr/share/mysql/english
/usr/share/mysql/english/errmsg.sys
/usr/share/mysql/errmsg-utf8.txt
/usr/share/mysql/estonian
/usr/share/mysql/estonian/errmsg.sys
/usr/share/mysql/fill_help_tables.sql
/usr/share/mysql/french
/usr/share/mysql/french/errmsg.sys
/usr/share/mysql/german
/usr/share/mysql/german/errmsg.sys
/usr/share/mysql/greek
/usr/share/mysql/greek/errmsg.sys
/usr/share/mysql/hungarian
/usr/share/mysql/hungarian/errmsg.sys
/usr/share/mysql/italian
/usr/share/mysql/italian/errmsg.sys
/usr/share/mysql/japanese
/usr/share/mysql/japanese/errmsg.sys
/usr/share/mysql/korean
/usr/share/mysql/korean/errmsg.sys
/usr/share/mysql/magic
/usr/share/mysql/my-huge.cnf
/usr/share/mysql/my-innodb-heavy-4G.cnf
/usr/share/mysql/my-large.cnf
/usr/share/mysql/my-medium.cnf
/usr/share/mysql/my-small.cnf
/usr/share/mysql/mysql-log-rotate
/usr/share/mysql/mysql.server
/usr/share/mysql/mysql_system_tables.sql
/usr/share/mysql/mysql_system_tables_data.sql
/usr/share/mysql/mysql_test_data_timezone.sql
/usr/share/mysql/mysqld_multi.server
/usr/share/mysql/ndb-config-2-node.ini
/usr/share/mysql/norwegian
/usr/share/mysql/norwegian-ny
/usr/share/mysql/norwegian-ny/errmsg.sys
/usr/share/mysql/norwegian/errmsg.sys
/usr/share/mysql/polish
/usr/share/mysql/polish/errmsg.sys
/usr/share/mysql/portuguese
/usr/share/mysql/portuguese/errmsg.sys
/usr/share/mysql/romanian
/usr/share/mysql/romanian/errmsg.sys
/usr/share/mysql/russian
/usr/share/mysql/russian/errmsg.sys
/usr/share/mysql/serbian
/usr/share/mysql/serbian/errmsg.sys
/usr/share/mysql/slovak
/usr/share/mysql/slovak/errmsg.sys
/usr/share/mysql/solaris
/usr/share/mysql/solaris/postinstall-solaris
/usr/share/mysql/spanish
/usr/share/mysql/spanish/errmsg.sys
/usr/share/mysql/swedish
/usr/share/mysql/swedish/errmsg.sys
/usr/share/mysql/ukrainian
/usr/share/mysql/ukrainian/errmsg.sys

6.列出RPM軟件包中的描述信息

[linzhongniao@rpmbaozhizuo ~]$ rpm -qpi /home/linzhongniao/rpmbuild/RPMS/x86_64/MySQL-server-5.5.32-2.linux2.6.x86_64.rpm 
Name: MySQL-server Relocations: (not relocatable)
Version : 5.5.32Vendor: Oracle and/or its affiliates
Release : 2.linux2.6Build Date: 2018年03月08日 星期四 07時52分10秒
Install Date: (not installed)   Build Host: rpmbaozhizuo
Group   : Applications/DatabasesSource RPM: MySQL-5.5.32-2.linux2.6.src.rpm
Size: 173398967License: Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Under GPL license as shown in the Description field.
Signature   : (none)
Packager: MySQL Release Engineering <[email protected]>
URL : http://www.mysql.com/
Summary : MySQL: a very fast and reliable SQL database server
Description :
The MySQL(TM) software delivers a very fast, multi-threaded, multi-user,
and robust SQL (Structured Query Language) database server. MySQL Server
is intended for mission-critical, heavy-load production systems as well
as for embedding into mass-deployed software. MySQL is a trademark of
Oracle and/or its affiliates

The MySQL software has Dual Licensing, which means you can use the MySQL
software free of charge under the GNU General Public License
(http://www.gnu.org/licenses/). You can also purchase commercial MySQL
licenses from Oracle and/or its affiliates if you do not wish to be bound by the terms of
the GPL. See the chapter "Licensing and Support" in the manual for
further info.

The MySQL web site (http://www.mysql.com/) provides the latest news and
information about the MySQL software.  Also please see the documentation
and the manual for more information.

This package includes the MySQL server binary as well as related utilities
to run and administer a MySQL server.

If you want to access and work with the database, you have to install
package "MySQL-client" as well!

7.rpm方式安裝驗證

[root@rpmbaozhizuo x86_64]# pwd
/home/linzhongniao/rpmbuild/RPMS/x86_64
[root@rpmbaozhizuo x86_64]# ls
MySQL-client-5.5.32-2.linux2.6.x86_64.rpm  MySQL-embedded-5.5.32-2.linux2.6.x86_64.rpm  MySQL-shared-5.5.32-2.linux2.6.x86_64.rpm
MySQL-devel-5.5.32-2.linux2.6.x86_64.rpm   MySQL-server-5.5.32-2.linux2.6.x86_64.rpmMySQL-test-5.5.32-2.linux2.6.x86_64.rpm
[root@rpmbaozhizuo x86_64]# rpm -ivh MySQL-*
Preparing...########################################### [100%]
   1:MySQL-devel########################################### [ 17%]
   2:MySQL-client   ########################################### [ 33%]
   3:MySQL-test ########################################### [ 50%]
   4:MySQL-embedded ########################################### [ 67%]
   5:MySQL-shared   ########################################### [ 83%]
   6:MySQL-server   ########################################### [100%]

[root@rpmbaozhizuo x86_64]# ll /etc/init.d/mysql
 -rwxr-xr-x. 1 root root 10815 3月   8 07:51 /etc/init.d/mysql
[root@rpmbaozhizuo x86_64]# rpm -qf /etc/init.d/mysql
MySQL-server-5.5.32-2.linux2.6.x86_64
[root@rpmbaozhizuo x86_64]# /etc/init.d/mysql start
Starting MySQL.. SUCCESS!

好到此rpm包已經制作完成,我們可以把常用的軟件源碼包制作成rpm包,這樣安裝就會很方便了。

將定制的rpm包,用yum安裝請看企業yum倉庫的構建

http://blog.51cto.com/10642812/2072234

企業rpm包的定制