一、安装打包软件
yum install rpm-build
yum install rpmdevtools
二、复制tar包
注意:如果要修改配置文件需要把tar包解压,修改tomcat配置文件
cp apache-tomcat-8.5.93.tar.gz /root/rpm-build/SOURCES
三、编辑/root/rpm-build/SOURCES/tomcat.service 可以选择
vim /root/rpm-build/SOURCES/tomcat.service
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/run/tomcat.pid
ExecStart=/usr/local/tomcat/bin/startup.sh &>/dev/null
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.target
四、编辑/root/rpm-build/SPECS/tomcat.spec
vim /root/rpm-build/SPECS/tomcat.spec
%define path_name usr/local
%define name_ apache-tomcat-8.5.93
Name: apache-tomcat
Version: 8.5.93
Release: 1%{?dist}
Summary: apache-tomcat
Group: apache-tomcat
License: GPL
URL: https://tomcat.apache.org/
Packager: apache-tomcat
Vendor: apache-tomcat
Source0: apache-tomcat-8.5.93.tar.gz
Source1: tomcat.service
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
%description
tomcat%prep
mkdir -pv %{buildroot}/%{path_name}
%setup -q%install
mkdir -p $RPM_BUILD_ROOT/%{path_name}/%{name_}/varcp -rf * $RPM_BUILD_ROOT/%{path_name}/%{name_}/
#%{__install} -p -D %{SOURCE1} %{buildroot}/usr/lib/systemd/system/tomcat.service%post
ln -s $RPM_BUILD_ROOT/%{path_name}/%{name_}/ $RPM_BUILD_ROOT/%{path_name}/apache-tomcat%postun
rm -fr /%{path_name}/%{name_}
rm -fr /%{path_name}/apache-tomcat%files
%defattr(-,root,root,-)
%attr(0755,root,root) /usr/local/
#%attr(0755,root,root) /usr/lib/systemd/system/tomcat.service
%attr(0755,root,root) /usr/local/apache-tomcat-8.5.93/var%changelog
* Sat Oct 24 2015 yeho 1.15-1
- Initial version
五、打包在/root目录下执行
sudo rpmbuild -bb rpmbuild/SPECS/tomcat.spec