安装问题是典型的无意义的重复劳动,理应简单,一个软件应该让使用者更专注于软件的用法和配置文件,而不是安装过程。
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: fastdfsVersion: 5.0.5Release: 7%{?dist}Summary: FastDFS server and clientLicense: GPLGroup: Arch/TechURL: https://github.com/happyfish100/fastdfsBuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Source0: %{name}-%{version}.tar.gzSource1: fdfs_trackerd.initSource2: fdfs_storaged.initSource10: fdfs_trackerd.serviceSource20: fdfs_storaged.serviceSource3: tracker.confSource4: storage.confSource5: client.confSource6: http.confRequires: %__cp %__mv %__chmod %__grep %__mkdir %__install %__idBuildRequires: gccBuildRequires: glibc-develBuildRequires: libtoolBuildRequires: makeBuildRequires: libfastcommon-develRequires(post): chkconfig%descriptionThis package provides tracker & storage of fastdfs%package trackerSummary: fastdfs trackerRequires: fastdfsRequires: libfastcommon%package storageSummary: fastdfs storageRequires: fastdfsRequires: libfastcommon%package toolSummary: fastdfs toolsRequires: libfastcommon%package -n libfdfsclientSummary: The client dynamic library of fastdfsRequires: libfastcommon%package -n libfdfsclient-develSummary: The client header of fastdfsRequires: libfdfsclient%description trackerThis package provides tracker of fastdfs%description storageThis package provides storage of fastdfs%description -n libfdfsclientThis package is client dynamic library of fastdfs%description -n libfdfsclient-develThis package is client header of fastdfs client%description toolThis 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%installrm -rf %{buildroot}DESTDIR=$RPM_BUILD_ROOT ./make.sh installmkdir -p $RPM_BUILD_ROOT%{_bindir}mkdir -p $RPM_BUILD_ROOT%{_initrddir}mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/fdfsmkdir -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_trackerdrm -rf $RPM_BUILD_ROOT%{_bindir}/restart.shrm -rf $RPM_BUILD_ROOT%{_bindir}/stop.shrm -rf $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/tracker.conf.samplerm -rf $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/storage.conf.samplerm -rf $RPM_BUILD_ROOT%{_sysconfdir}/fdfs/client.conf.samplerm -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" usergetent group fdfs >/dev/null || groupadd -r fdfsgetent passwd fdfs >/dev/null || \ useradd -r -g fdfs -s /sbin/nologin \ -d /var/lib/fastdfs -c "fastdfs user" fdfsexit 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%cleanrm -rf $RPM_BUILD_ROOTpushd common;make -s clean ;popdpushd tracker;make -s clean ;popdpushd storage;make -s clean ;popdpushd test;make -s clean ;popdpushd 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- new init scripts- run as user fdfs by default* Mon Jun 23 2014 Zaixue Liao - first RPM release (1.0)
附件数量较多,移步百度网盘
如果将srpm包经过重新编译,也适用于CentOS 6