CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包

文章目录

  • 1. 下载zookeeper源码包
  • 2. 打tar包
  • 3. 打deb包
  • 4. 打rpm包
    • 4.1 修改build.xml配置文件
    • 4.2 修改zkpython.spec文件
    • 4.3 修改zkpython_build.xml文件
    • 4.4 修改zookeeper.spec文件
    • 4.5 修改配置文件.rpmmacros
    • 4.6 安装打包好的rpm包

1. 下载zookeeper源码包

  • zookeeper-release-HDP-2.6.5.148-3-tag.tar.gz:https://github.com/hortonworks/zookeeper-release/releases/tag/HDP-2.6.5.148-3-tag
# 安装打包环境
[root@worker2 tgm]# yum install ant -y
[root@worker2 tgm]# yum install cppunit-devel -y

2. 打tar包

[root@worker2 tgm]# cd zookeeper-release-HDP-2.6.5.148-3-tag/
[root@worker2 zookeeper-release-HDP-2.6.5.148-3-tag]# ant tar

# 在build文件下查看打包结果

CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第1张图片

3. 打deb包

[root@worker2 tgm]# cd zookeeper-release-HDP-2.6.5.148-3-tag/
[root@worker2 zookeeper-release-HDP-2.6.5.148-3-tag]# ant deb

# 在build文件下查看打包结果

CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第2张图片

4. 打rpm包

[root@worker2 tgm]# cd zookeeper-release-HDP-2.6.5.148-3-tag/
[root@worker2 zookeeper-release-HDP-2.6.5.148-3-tag]# ant rpm

# 直接使用ant rpm把zookeeper打包会报错

CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第3张图片

4.1 修改build.xml配置文件

注:以下修改文件中,-代表在配置文件中删除该行,+代表在配置文件中添加该行,修改配置文件,参考:http://zookeeper-user.578899.n2.nabble.com/Cannot-build-zookeeper-3-4-5-RPM-on-CentOS-6-3-td7578336.html

[root@worker2 tgm]# cd zookeeper-release-HDP-2.6.5.148-3-tag/
[root@worker2 zookeeper-release-HDP-2.6.5.148-3-tag]# vim ./build.xml

           
         
       
-      
       
         

CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第4张图片

4.2 修改zkpython.spec文件

[root@worker2 tgm]# cd zookeeper-release-HDP-2.6.5.148-3-tag/
[root@worker2 zookeeper-release-HDP-2.6.5.148-3-tag]# vim ./src/contrib/zkpython/src/packages/rpm/spec/zkpython.spec

 %install
+%{__mv} %{_build_dir}/* %{buildroot}
 
 %pre
 

CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第5张图片

4.3 修改zkpython_build.xml文件

[root@worker2 tgm]# cd zookeeper-release-HDP-2.6.5.148-3-tag/
[root@worker2 zookeeper-release-HDP-2.6.5.148-3-tag]# vim ./src/contrib/zkpython/build.xml

         
       
 
-      
+      
       
         
           

在这里插入图片描述

4.4 修改zookeeper.spec文件

[root@worker2 tgm]# cd zookeeper-release-HDP-2.6.5.148-3-tag/
[root@worker2 zookeeper-release-HDP-2.6.5.148-3-tag]# vim ./src/packages/rpm/spec/zookeeper.spec

Prefix: %{_log_dir}
 Prefix: %{_pid_dir}
 Prefix: %{_var_dir}
-Requires: sh-utils, textutils, /usr/sbin/useradd, /usr/sbin/usermod, /sbin/chkconfig, /sbin/service, jdk >= 1.6
+Requires: sh-utils, textutils, /usr/sbin/useradd, /usr/sbin/usermod, /sbin/chkconfig, /sbin/service, java >= 1.6
 AutoReqProv: no
 Provides: zookeeper
 
@@ -87,17 +87,14 @@
 ZooKeeper C client library for communicating with ZooKeeper Server.
 
 %prep
-%setup -D -b 1 -n %{_final_name}
-%setup -D -a 0 -n %{_final_name}
+%setup -q -D -b 1 -n %{_final_name}
+%setup -q -D -a 0 -n %{_final_name}
 
 %build
 mkdir -p ${RPM_BUILD_DIR}%{_prefix}
 mkdir -p ${RPM_BUILD_DIR}%{_bin_dir}
 mkdir -p ${RPM_BUILD_DIR}%{_include_dir}
 mkdir -p ${RPM_BUILD_DIR}%{_lib_dir}
-%ifarch amd64 x86_64
-mkdir -p ${RPM_BUILD_DIR}%{_lib64_dir}
-%endif
 mkdir -p ${RPM_BUILD_DIR}%{_libexec_dir}
 mkdir -p ${RPM_BUILD_DIR}%{_log_dir}
 mkdir -p ${RPM_BUILD_DIR}%{_conf_dir}
@@ -118,14 +115,15 @@
 #########################
 %install
 pushd ${RPM_BUILD_DIR}
-mv ${RPM_BUILD_DIR}/%{_final_name}/bin/* ${RPM_BUILD_DIR}%{_bin_dir}
-mv ${RPM_BUILD_DIR}/%{_final_name}/libexec/* ${RPM_BUILD_DIR}%{_libexec_dir}
-mv ${RPM_BUILD_DIR}/%{_final_name}/share/zookeeper/* ${RPM_BUILD_DIR}%{_share_dir}
-mv ${RPM_BUILD_DIR}/%{_final_name}/conf/* ${RPM_BUILD_DIR}%{_conf_dir}
-mv ${RPM_BUILD_DIR}/%{_final_name}/sbin/* ${RPM_BUILD_DIR}%{_sbin_dir}
-cp -f ${RPM_BUILD_DIR}%{_conf_dir}/zoo_sample.cfg ${RPM_BUILD_DIR}%{_conf_dir}/zoo.cfg
+cp -a ${RPM_BUILD_DIR}/%{_final_name}/bin/*.sh ${RPM_BUILD_DIR}%{_bin_dir}
+cp -a ${RPM_BUILD_DIR}/%{_final_name}/libexec/*.sh ${RPM_BUILD_DIR}%{_libexec_dir}
+cp -a ${RPM_BUILD_DIR}/%{_final_name}/share/zookeeper/* ${RPM_BUILD_DIR}%{_share_dir}
+cp -a ${RPM_BUILD_DIR}/%{_final_name}/conf/* ${RPM_BUILD_DIR}%{_conf_dir}
+cp -a ${RPM_BUILD_DIR}/%{_final_name}/sbin/*.sh ${RPM_BUILD_DIR}%{_sbin_dir}
+rm -r ${RPM_BUILD_DIR}/usr/include
+rm -r ${RPM_BUILD_DIR}/usr/man
+mv etc usr var %{buildroot}
 popd ${RPM_BUILD_DIR}
-rm -rf ${RPM_BUILD_DIR}/%{_final_name}
 
 %pre
 getent group hadoop 2>/dev/null >/dev/null || /usr/sbin/groupadd -r hadoop
@@ -153,9 +151,16 @@
 %defattr(-,root,root)
 %attr(0755,root,hadoop) %{_log_dir}
 %attr(0775,root,hadoop) %{_pid_dir}
+%attr(0775,root,hadoop) %{_var_dir}
 %attr(0775,root,hadoop) /etc/init.d/zookeeper
+%dir %{_conf_dir}/
 %config(noreplace) %{_conf_dir}/*
-%{_prefix}
+%{_libexec_dir}/*
+%{_sbin_dir}/*
+%{_share_dir}/*
+%{_log_dir}/
+%{_pid_dir}/
+%{_var_dir}/
 
 %post lib
 /sbin/ldconfig
@@ -163,4 +168,4 @@
 %files lib
 %defattr(-,root,root)
 %{_prefix}/lib/*
-%{_prefix}/bin
+%{_prefix}/bin/*

CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第6张图片

  • 以上配置文件修改完毕,使用ant rpm直接打包,还是会报错,报错信息如下
    CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第7张图片

4.5 修改配置文件.rpmmacros

[root@worker2 zookeeper-release-HDP-2.6.5.148-3-tag]# vim ~/.rpmmacros

# 注释 %__arch__install_post

CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第8张图片
CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第9张图片

  • 再执行ant rpm打包命令,成功
    CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第10张图片
  • 查看
    CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第11张图片

4.6 安装打包好的rpm包

  • [root@worker2 build]# rpm -ivh zookeeper-3.4.6-1.x86_64.rpm
    CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第12张图片
  • 启动:[root@worker2 build]# zkServer.sh start
    CentOS7环境下zookeeper-release-HDP-2.6.5.148-3-tag编译打RPM包_第13张图片

你可能感兴趣的:(Zookeeper)