安装问题是典型的无意义的重复劳动,理应简单,一个软件应该让使用者更专注于软件的用法和配置文件,而不是安装过程。
fastdfs官方的spec文件功能不够完整,仅仅能够完成rpm打包,但是rpm包安装时会有各种问题。极少看到有人反馈spec文件问题,估计使用rpm包进行安装的,只有我一人。而使用rpm安装,可以省略重复无意义且容易出错的编译过程,提升软件安装体验。
(文末有百度网盘的链接)
我对官方的spec文件进行了大幅改造,对默认配置文件也进行了适当调整,改进如下:
1、启动脚本
/usr/bin/stop.sh 和/usr/bin/restart.sh 名字过于霸气,抛弃!
原fdfs_trackerd和fdfs_storaged启动脚本由于调用/usr/bin/stop.sh /usr/bin/restart.sh
新的启动脚本改为调用 /etc/rc.d/init.d/functions 公共函数进行启动、关闭和重启。
2、运行身份
配置文件相关选项默认为空,即探测当前用户身份,这容易误导使用者用root运行程序而造成安全隐患。rpm包安装时会创建普通用户fdfs,配置文件改为,run_by_user=fdfs和run_by_group=fdfs
使用root身份执行启动脚本,程序会自动切换到fdfs用户身份。
4、路径问题
配置文件中的路径,统一归于/var/lib/fastdfs之下,属主fdfs,比如/etc/fdfs/storage.conf
base_path=/var/lib/fastdfs/storage
5、将打包后的二进制包fastdfs-server 拆分成fastdfs-tracker 和fastdfs-storage,便于分别部署。
6、配置文件微调
文件名去掉sample后缀,直接使用conf文件,
将可能被修改的参数放入配置文件前面,方便查找。
附上修改后的fastdfs.spec文件如下:
Name: fastdfs Version: 5.0.5 Release: 7%{?dist} Summary: FastDFS server and client License: GPL Group: Arch/Tech URL: https://github.com/happyfish100/fastdfs BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Source0: %{name}-%{version}.tar.gz Source1: fdfs_trackerd.init Source2: fdfs_storaged.init Source10: fdfs_trackerd.service Source20: fdfs_storaged.service Source3: tracker.conf Source4: storage.conf Source5: client.conf Source6: http.conf Requires: %__cp %__mv %__chmod %__grep %__mkdir %__install %__id BuildRequires: gcc BuildRequires: glibc-devel BuildRequires: libtool BuildRequires: make BuildRequires: libfastcommon-devel Requires(post): chkconfig %description This package provides tracker & storage of fastdfs %package tracker Summary: fastdfs tracker Requires: fastdfs Requires: libfastcommon %package storage Summary: fastdfs storage Requires: fastdfs Requires: libfastcommon %package tool Summary: fastdfs tools Requires: libfastcommon %package -n libfdfsclient Summary: The client dynamic library of fastdfs Requires: libfastcommon %package -n libfdfsclient-devel Summary: The client header of fastdfs Requires: libfdfsclient %description tracker This package provides tracker of fastdfs %description storage This package provides storage of fastdfs %description -n libfdfsclient This package is client dynamic library of fastdfs %description -n libfdfsclient-devel This package is client header of fastdfs client %description tool This package is tools for fastdfs %prep %setup -q %build # FIXME: I need to fix the upstream Makefile to use LIBDIR et al. properly and # send the upstream maintainer a patch. # add DOCDIR to the configure part ./make.sh %install rm -rf %{buildroot} DESTDIR=$RPM_BUILD_ROOT ./make.sh install mkdir -p $RPM_BUILD_ROOT%{_bindir} mkdir -p $RPM_BUILD_ROOT%{_initrddir} mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/fdfs mkdir -p $RPM_BUILD_ROOT%{_sharedstatedir}/fastdfs/{client,storage,tracker} cp conf/storage_ids.conf $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/ cp conf/mime.types $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/ rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/init.d/fdfs_storaged rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/init.d/fdfs_trackerd rm -rf $RPM_BUILD_ROOT%{_bindir}/restart.sh rm -rf $RPM_BUILD_ROOT%{_bindir}/stop.sh rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/tracker.conf.sample rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/storage.conf.sample rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/client.conf.sample rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/storage_ids.conf.sample # install SYSV init stuff %{__mkdir} -p $RPM_BUILD_ROOT%{_initrddir} %{__install} -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_initrddir}/fdfs_trackerd %{__install} -m 755 %{SOURCE2} $RPM_BUILD_ROOT%{_initrddir}/fdfs_storaged %{__install} -m 644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/tracker.conf %{__install} -m 644 %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/storage.conf %{__install} -m 644 %{SOURCE5} $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/client.conf %{__install} -m 644 %{SOURCE6} $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/http.conf %pre # Add the "fdfs" user getent group fdfs >/dev/null || groupadd -r fdfs getent passwd fdfs >/dev/null || \ useradd -r -g fdfs -s /sbin/nologin \ -d /var/lib/fastdfs -c "fastdfs user" fdfs exit 0 %post tracker /sbin/chkconfig --add fdfs_trackerd %preun tracker /sbin/chkconfig --del fdfs_trackerd %post storage /sbin/chkconfig --add fdfs_storaged %preun storage /sbin/chkconfig --del fdfs_storaged %postun %clean rm -rf $RPM_BUILD_ROOT pushd common;make -s clean ;popd pushd tracker;make -s clean ;popd pushd storage;make -s clean ;popd pushd test;make -s clean ;popd pushd client ;make -s clean ;popd %files %defattr(-,root,root,-) %dir %{_sysconfdir}/fdfs %dir %attr(0755,fdfs,fdfs) %{_sharedstatedir}/fastdfs %files tracker %defattr(-,root,root,-) %{_bindir}/fdfs_trackerd %{_initrddir}/fdfs_trackerd %config(noreplace) %{_sysconfdir}/fdfs/tracker.conf %dir %attr(0755,fdfs,fdfs) %{_sharedstatedir}/fastdfs/tracker %files storage %defattr(-,root,root,-) %{_bindir}/fdfs_storaged %{_initrddir}/fdfs_storaged %config(noreplace) %{_sysconfdir}/fdfs/storage.conf %dir %attr(0755,fdfs,fdfs) %{_sharedstatedir}/fastdfs/storage %files -n libfdfsclient %{_libdir}/libfdfsclient* %config(noreplace) %{_sysconfdir}/fdfs/client.conf %config(noreplace) %{_sysconfdir}/fdfs/http.conf %config(noreplace) %{_sysconfdir}/fdfs/mime.types %config(noreplace) %{_sysconfdir}/fdfs/storage_ids.conf %dir %attr(0755,fdfs,fdfs) %{_sharedstatedir}/fastdfs/client %files -n libfdfsclient-devel %defattr(-,root,root,-) %{_includedir}/fastdfs/* %files tool %{_bindir}/fdfs_monitor %{_bindir}/fdfs_test %{_bindir}/fdfs_test1 %{_bindir}/fdfs_crc32 %{_bindir}/fdfs_upload_file %{_bindir}/fdfs_download_file %{_bindir}/fdfs_delete_file %{_bindir}/fdfs_file_info %{_bindir}/fdfs_appender_test %{_bindir}/fdfs_appender_test1 %{_bindir}/fdfs_append_file %{_bindir}/fdfs_upload_appender %changelog * Thu Nov 05 2015 Purple Grape <[email protected]> - new init scripts - run as user fdfs by default * Mon Jun 23 2014 Zaixue Liao <[email protected]> - first RPM release (1.0)
附件数量较多,移步百度网盘
http://pan.baidu.com/s/1eQmCMcy
如果将srpm包经过重新编译,也适用于CentOS 6