运维自动化需要涉及到rpmbuild的学习,现对rpmbuild进行打包,以下是spec文件内容:

# online rpmbulid for h5_back

Name:             h5_bak
Version:          0.0.1
Release:          1%{?dist}
Summary:          data_back for h5
Group:            Applications/File
License:          BSD
URL:              http://www.youyuan.com/
Source:          %{name}-%{version}.tar.gz
BuildRoot:        %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

#BuildRequires:    jdk >= 1.7
ExcludeArch:      ppc64

#Requires:         logrotate
#Requires(post):   chkconfig
#Requires(postun): initscripts
#Requires(pre):    shadow-utils
#Requires(preun):  chkconfig
Requires(postun): /bin/rm

%description
autoinstall for h5 youyuan_back_Platform

%prep
%setup -q

%install
%{__mkdir_p} %{buildroot}/www/youyuan.com.1
cp -r ${RPM_BUILD_DIR}/%{name}-%{version}/* %{buildroot}/www/youyuan.com.1/.

%clean
rm -fr %{buildroot}

%postun
if [ $1 = 0 ]; then
   /bin/rm -rf /www/youyuan.com.1
fi

%files
%defattr(-,www,www)
/www/youyuan.com.1

安装只需要:

root@pts/16 # rpm -ivh /opt/rpmbuild/RPMS/x86_64/h5_bak-0.0.1-1.el6.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:h5_bak                 ########################################### [100%]

卸载:

root@pts/15 # rpm -qa | grep h5
h5_bak-0.0.1-1.el6.x86_64
192.168.3.89 [/opt/rpmbuild/SPECS] 2015-06-29 14:16:50
root@pts/15 # ls -lSd /www/youyuan.com.1
drwxr-xr-x 4 root root 4096 Jun 29 14:02 /www/youyuan.com.1
192.168.3.89 [/opt/rpmbuild/SPECS] 2015-06-29 14:17:08
root@pts/15 # rpm -ev h5_bak-0.0.1-1.el6.x86_64
192.168.3.89 [/opt/rpmbuild/SPECS] 2015-06-29 14:17:26
root@pts/15 # ls -lSd /www/youyuan.com.1       
ls: cannot access /www/youyuan.com.1: No such file or directory

参考资料:

http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-specfiles.html

https://fedoraproject.org/wiki/How_to_create_an_RPM_package/zh-cn