Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The process of RPM package production under Linux

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Preparation before starting

Install the rpmbuild package

Yum-y install rpm-build

Generate related directories

To generate rpm-related directories, you can create them either manually or through the rpmbuild command. Such as:

[root@yang data] # rpmbuild zabbix_agentd_ops.spec error: File / root/rpmbuild/SOURCES/zabbix-3.0.3.tar.gz: No such file or directory reported an error. Ignore it. You can see that the rpmbuild directory has been created [root@yang ~] # tree rpmbuild/rpmbuild/ ├── BUILD ├── BUILDROOT ├── RPMS ├── SOURCES SPECS └── SRPMS

Write SPEC files

SPEC keyword

Name: the name of the package, which can be referenced later using% {name}

Summary: a summary of the contents of the package

Version: the actual version number of the software, for example, 1.0.1, etc., which can be referenced later using% {version}

Release: publish the serial number, such as 1linuxing, etc., indicating the number of packages, which can be referenced later using% {release}

Group: software grouping. Standard grouping is recommended.

License: software licensing method, usually GPL

Source: source code package with multiple sources such as Source1, Source2, etc., and can also be referenced later with% {source1},% {source2}

BuildRoot: this is the "virtual directory" used for installation or compilation. Considering the multi-user environment, it is generally defined as:% {tmppath} / {name} -% {version} -% {release}-root or% {tmppath} /% {name} -% {version} -% {release}-buildroot-%%__id_u}-n}. This parameter is very important because in the process of generating rpm, the software will be installed in the above path when make install is executed, and when packaging, it also depends on the "virtual directory" for the "root directory" operation. It can be referenced later using the $RPM_BUILD_ROOT method.

URL: the home page of the software

Vendor: information about the publisher or packaging organization, such as RedFlag Co,Ltd

Disstribution: distribution identity

Patch: patch source code, multiple patches can be identified using Patch2, Patch3, etc., referenced by% patch0 or% {patch0}

Prefix:% {_ prefix} this is mainly to solve the situation that when you install the rpm package in the future, you may not necessarily install the software to the directory packaged in rpm. In this way, the identity must be defined here and referenced when writing the% install script in order to achieve the function of reassigning the location during rpm installation

The reason for Prefix:% {sysconfdir} is the same as above, but since% {prefix} refers to / usr, other files, such as configuration files under / etc, need to be identified with% {_ sysconfdir}

Build Arch: refers to the target processor architecture for compilation. The noarch identity is not specified, but the default value is usually the content in / usr/lib/rpm/marcros.

Requires: the package names that the rpm package depends on can be separated by spaces on both sides of the > = or = 1.0.20 zlib packages "> =", and different software names are also separated by spaces. For example, PreReq, Requires (pre), Requires (post), Requires (preun), Requires (postun), BuildRequires, etc. are all specified for different stages of dependencies.

Provides: indicate some specific functions of this software for other rpm to identify

Packager: information of the Packer

Detailed description of% description software

SPEC script body

% prep preprocessing script

% setup-n% {name} -% {version} * * decompress the source package and put it away, usually from the package in / usr/src/asianux/SOURCES to / usr/src/asianux/BUILD/% {name} -% {version}. Generally, it is OK to use% setup-c, but there are two cases: one is to compile multiple source code packages at the same time, and the other is that the name of the tar package of the source code is not consistent with the extracted directory. In this case, you need to specify it with the-n parameter.

% patch patches are usually put together in the source tar.gz package or in the SOURCES directory. The general parameters are:

% patch-p1 uses the Patch patch defined earlier,-p1 is the first tier that ignores patch,% Patch3-p1-b xxx.patch is patched with the specified patch, and-b refers to the generation of backup files

Supplement

% setup does not add any options and only opens the package. % setup-n newdir unzipped the package in the newdir directory. % setup-c generates a directory before unzipping. % setup-b num unzipped the num source file. % setup-T does not use default's decompression operation. % setup-T-b 0 unzips the 0th source code file. % setup-c-n newdir specifies the directory name newdir and generates a rpm suite in this directory. % patch is the simplest patch that automatically specifies patch level. Patch 0 uses the 0th patch file, which is equivalent to patch? P 0. % patch-s does not display patch information. % patch-T deletes all output files generated when patching.

The% configure is not a keyword, but a standard macro command defined by rpm. It means to perform the configure configuration of the source code, in the / usr/src/asianux/BUILD/% {name} -% {version} directory, using standard writing, referencing the parameters defined in / usr/lib/rpm/marcros. Another non-standard way to write it is to customize the parameters in the source code, such as:

Quote CFLAGS= "$RPM_OPT_FLAGS" CXXFLAGS= "$RPM_OPT_FLAGS". / configure-- prefix=% {_ prefix}

% build starts building the package, doing make work in the / usr/src/asianux/BUILD/% {name} -% {version} directory

% install starts installing the software into the virtual root directory. Make install is performed in the / usr/src/asianux/BUILD/% {name} -% {version} directory. This is important because if the path here is wrong, the search for the file in the% file below will fail. The common contents are:

% makeinstall this is not a keyword, but a standard macro command defined by rpm. You can also use non-standard writing: make DESTDIR=$RPM_BUILD_ROOT install or reference make prefix=$RPM_BUILD_ROOT install need to note that the% install here is mainly for the later% file service. Therefore, you can also use regular system commands: reference install-d $RPM_BUILD_ROOT/ and cp-a * $RPM_BUILD_ROOT/

Clean cleans up temporary files

Scripts executed before pre rpm installation

Scripts executed after post rpm installation

Script executed before preun rpm is uninstalled

Script executed after postun rpm is uninstalled

% files defines which files or directories will be put into rpm

% defattr (-, root,root) * * specifies the properties of the wrapper file, which are (mode,owner,group),-for default values, 0644 for text files, and 0755 for executable files

% changelog change Log

Example:

% define zabbix_user zabbix # custom macro named zabbix_ user value zabbix,% {zabbix_user} reference the name of the Name: zabbix # package, followed by% {name} to refer to the actual version number of Version: 3.0.3 # software, and to publish the serial number using% {version} reference Release: 1% {? dist} # Indicate the number of packages Summary: zabbix_agentd # package content summary Group: zabbix # package grouping License: GPL # license method URL: www.yang.com # Home page of the software Source0: zabbix-3.0.3.tar.gz # source code package You can have sources such as Source0,Source1: BuildRequires: gcc, gcc-c++ # when making rpm packages, the basic libraries Requires: gcc, gcc-c++, chkconfig # that you depend on when installing rpm packages Dependent software package% description # defines the description of the rpm package Zabbix agentd 3.0.3%pre # script executed before installation of the rpm package grep zabbix / etc/passwd > / dev/nullif [$?! = 0] then useradd zabbix-M-s / sbin/nologinfi [- d / etc/zabbix] | | rm-rf / etc/zabbix*%post # rpm package Script sed-I "/ ^ ServerActive=/c\ ServerActive=172.30.17.35" / etc/zabbix/etc/zabbix_agentd.confsed-I "/ ^ Server=/c\ Server=172.30.17.35" / etc/zabbix/etc/zabbix_agentd.confsed-I "/ Timeout=3/c\ Timeout=30" / etc/zabbix/etc/zabbix_agentd.confsed-I "/ HostMetadata=/c\ HostMetadata=PostgreSQL" / etc/zabbix/etc/zabbix_agentd.confsed-I "/ ^ Hostname=/c" executed after installation \ Hostname=PostgreSQL "/ etc/zabbix/etc/zabbix_agentd.confecho" UnsafeUserParameters=1 "> > / etc/zabbix/etc/zabbix_agentd.confecho" EnableRemoteCommands=1 "> > / etc/zabbix/etc/zabbix_agentd.confecho" Include=/etc/zabbix/etc/zabbix_agentd.conf.d/*.conf "> > / etc/zabbix/etc/zabbix_agentd.confchkconfig zabbix_agentd on%preun # rpm script systemctl stop zabbix_agentd%postun executed before uninstallation # script userdel zabbixrm-rf / etc/zabbix*%prep # executed after rpm uninstall this macro starts% setup-Q # unzipped and cd to the relevant directory% build # to define the operation when compiling the package. / configure-- prefix=/etc/% {name} -% {version}-- enable-agentmake-j16% {? _ smp _ mflags}% install # defines the installation package Test-L% {buildroot} / etc/% {name} & & rm-f% {buildroot} / etc/% {name} install-d% {buildroot} / etc/profile.dinstall-d% {buildroot} / etc/init.dmake install DESTDIR=% {buildroot} echo 'export PATH=/etc/zabbix/bin:/etc/zabbix/sbin:$PATH' >% {buildroot} / etc/profile.d/% {name} .shln-sf / etc/% {name} -% {version }% {buildroot} / etc/% {name} cp% {_ buildrootdir} / postgresql.conf% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/postgresql.confcp% {_ buildrootdir} / tcp_connections.sh% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/tcp_connections.shcp% {_ buildrootdir} / iostat-collect.sh% {buildroot} / Etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/iostat-collect.sh cp% {_ buildrootdir} / iostat-parse.sh% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/iostat-parse.shcp% {_ buildrootdir} / iostat-zabbix.conf% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/iostat-zabbix.conf cp% { _ buildrootdir} / zabbix_agentd% {buildroot} / etc/init.d/zabbix_agentd%files # defines the relevant directories and files created during the installation of the rpm package. In this option,% defattr (-, root,root) must be noted. It is the property of the specified installation file, which is (mode,owner,group),-represents the default value, 0644 for text files, and 0755 for executable files. / etc/% {name} / etc/% {name} -% {version} / * / etc/init.d/zabbix_agentd/etc/profile.d/% {name} .sh% changelog # is mainly used for software change logs. This option may or may not% clean rm-rf% {buildroot} # Clean temporary files

Expansion of RPM package production

If you want to add a startup control script or some other configuration file to zabbix, you can put it under SOURCE and copy it.

Put the startup script in the SOURCE directory

[root@yang ~ / rpmbuild/SOURCES] # ll total 15116-rwxr-xr-x 1 root root 362Aug 1 12:03 hostmonitor.conf-rwxr-xr-x 1 root root 505Aug 1 12:03 iostat-collect.sh-rwxr-xr-x 1 root root 953 Aug 1 12:03 iostat-parse.sh-rw-r--r-- 1 root root 772 Aug 1 12:03 iostat-zabbix.conf-rwxr-xr-x 1 root root 813 Aug 1 12: 03 nginx_monitor.sh-rw-r--r-- 1 root root 14868 Aug 1 12:03 postgresql.conf-rw-r--r-- 1 root root 77 Aug 1 12:03 process.discovery-rw-r--r-- 1 root root 552 Aug 1 12:03 redis_check.conf-rw-r--r-- 1 root root 356 Aug 1 12:03 redis_cluster_check.py-rw-r--r-- 1 root root 363 Aug 1 12:03 redis_multiport_check.py-rwxr-xr-x 1 root root 783 Aug 1 12:03 tcp_connections.sh-rw-r--r-- 1 root root 852 Aug 1 12:03 userparameter_nginx.conf-rw-r--r-- 1 root root 172 Aug 1 12:03 userparameter_process.conf-rw-r--r-- 1 root root 15407273 Jul 20 10:53 zabbix-3.0.3.tar.gz-rwxr-xr-x 1 root root 2182 Aug 1 12:03 zabbix_agentd

Edit the SPEC file

Add the following under Source0:

Source0: zabbix-3.0.3.tar.gz Source1: zabbix_agentd Source2: nginx_monitor.sh Source3: userparameter_nginx.conf Source4: hostmonitor.conf Source5: process.discovery Source6: userparameter_process.conf Source7: redis_check.conf Source8: redis_cluster_check.py Source9: redis_multiport_check.py Source10: tcp_connections.sh Source11: iostat- Collect.sh Source12: iostat-parse.sh Source13: iostat-zabbix.conf

The installation area is added as follows:

Make install DESTDIR=% {buildroot} install-p-D-m 0755 {SOURCE1}% {buildroot} / etc/init.d/zabbix_agentd install-p-D% {SOURCE2}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/nginx_monitor.sh install-p-D% {SOURCE3}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd. Conf.d/userparameter_nginx.conf install-p-D% {SOURCE4}% {buildroot} / etc/nginx/conf.d/hostmonitor.conf install-p-D% {SOURCE5}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/process.discovery install-p-D% {SOURCE6}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd. Conf.d/userparameter_process.conf install-p-D% {SOURCE7}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/redis_check.conf install-p-D% {SOURCE8}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/redis_cluster_check.py install-p-D% {SOURCE9}% {buildroot } / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/redis_multiport_check.py install-p-D% {SOURCE10}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/tcp_connections.sh install-p-D% {SOURCE11}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/iostat- Collect.sh install-p-D% {SOURCE12}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/iostat-parse.sh install-p-D% {SOURCE13}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/iostat-zabbix.conf

The% file area is added as follows:

% files% defattr (-, root,root,0755) / etc/% {name} / etc/% {name} -% {version} / * / etc/profile.d/% {name} .sh / etc/nginx/conf.d/hostmonitor.conf% attr

The following is the complete SPEC file:

Name: zabbix Version: 3.0.3 Release: 1% {? dist} Summary: zabbix_agentdGroup: zabbixLicense: GPLURL: www.yang.comSource0: zabbix-3.0.3.tar.gzSource1: zabbix_agentdSource2: nginx_monitor.shSource3: userparameter_nginx.confSource4: hostmonitor.confSource5: process.discoverySource6: userparameter_process.confSource7: redis_check.confSource8: redis_cluster_check.pySource9: redis_multiport_check.pySource10: tcp _ connections.shSource11: iostat-collect.shSource12: iostat-parse.shSource13: iostat-zabbix.confBuildRequires: gcc Gcc-c++Requires: gcc, gcc-c++ Chkconfig%descriptionZabbix agentd 3.0.3%pregrep zabbix/etc/ passwd > / dev/nullif [$?! = 0] then useradd zabbix- M-s / sbin/nologinfi [- d / etc/zabbix] | | rm-rf / etc/zabbix [- d / etc/zabbix] | | rm-rf / etc/zabbix-3.0.3%postsed-I "/ ^ ServerActive=/c\ ServerActive=172.30.17." / etc/zabbix/etc/zabbix_agentd.confsed-I "/ ^ Server=/c\ Server=172. 30.17. "/ etc/zabbix/etc/zabbix_agentd.confsed-I" / Timeout=3/c\ Timeout=30 "/ etc/zabbix/etc/zabbix_agentd.confsed-I" / HostMetadata=/c\ HostMetadata=OPS-TMP "/ etc/zabbix/etc/zabbix_agentd.confsed-I" / ^ Hostname=/c\ Hostname=OPS-TMP "/ etc/zabbix/etc/zabbix_agentd.confecho" UnsafeUserParameters=1 "> / etc/zabbix/etc/zabbix_agentd.confecho" EnableRemoteCommands=1 "> / etc/zabbix/etc/zabbix_ Agentd.confecho "Include=/etc/zabbix/etc/zabbix_agentd.conf.d/*.conf" > > / etc/zabbix/etc/zabbix_agentd.confchkconfig zabbix_agentd on%preunsystemctl stop zabbix_agentd%postunuserdel zabbixrm-rf / etc/zabbix*%prep%setup-q%build./configure-- prefix=/etc/% {name} -% {version}-- enable-agentmake-j16% {? _ smp_mflags}% installtest-L% {buildroot} / etc/% {name} & & rm-f % {buildroot} / etc/% {name} install-d% {buildroot} / etc/profile.dmake install DESTDIR=% {buildroot} install-p-D-m 0755% {SOURCE1}% {buildroot} / etc/init.d/zabbix_agentdinstall-p-D% {SOURCE2}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/nginx_monitor.shinstall-p-D% {SOURCE3}% {buildroot} / etc /% {name} -% {version} / etc/zabbix_agentd.conf.d/userparameter_nginx.confinstall-p-D% {SOURCE4}% {buildroot} / etc/nginx/conf.d/hostmonitor.confinstall-p-D% {SOURCE5}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/process.discoveryinstall-p-D% {SOURCE6}% {buildroot} / etc/% {name}- % {version} / etc/zabbix_agentd.conf.d/userparameter_process.confinstall-p-D% {SOURCE7}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/redis_check.confinstall-p-D% {SOURCE8}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/redis_cluster_check.pyinstall-p-D% {SOURCE9} % {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/redis_multiport_check.pyinstall-p-D% {SOURCE10}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/tcp_connections.shinstall-p-D% {SOURCE11}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/iostat- Collect.shinstall-p-D% {SOURCE12}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/iostat-parse.shinstall-p-D% {SOURCE13}% {buildroot} / etc/% {name} -% {version} / etc/zabbix_agentd.conf.d/iostat-zabbix.confecho 'export PATH=/etc/zabbix/bin:/etc/zabbix/sbin:$PATH' >% {buildroot} / etc/profile. Files%defattr% {name} .shln-sf / etc/% {name} -% {version}% {buildroot} / etc/% {name}% files%defattr (- Root,root,0755) / etc/% {name} / etc/% {name} -% {version} / * / etc/profile.d/% {name} .sh / etc/nginx/conf.d/hostmonitor.conf%attr / etc/rc.d/init.d/zabbix_agentd%changelog%clean rm-rf% {buildroot}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report