定制activemq_RPM包,注册系统服务并开机自启

rpmbuild命令用于创建软件的二进制包和源代码包。

1.准备环境

系统:Centos7

安装所需编译环境:

# yum install epel-release -y

# yum install rpmdevtools rpm-build gcc make tcl jemalloc -y 

2.提前编译安装redis,此处以activemq-5.16.5-版本为例

activemq源码包下载地址:http://archive.apache.org/dist/activemq/5.16.5/apache-activemq-5.16.5-bin.tar.gz

#  mv apache-activemq-5.16.5-bin.tar.gz   apache-activemq-5.16.5.tar.gz

3.生成rpm包

执行如下命令来生成rpmbuild的工作目录

# rpmdev-setuptree

# vim activemq.spec

​
Name:           apache-activemq
Version:        5.16.5
Release:        1%{?dist}
Summary:        apache-activemq

License:        GPLv3
Source0:        apache-activemq-5.16.5.tar.gz

BuildRequires:  bash

%global         app_bin_dir             /opt/%{name}-%{version}
%global         debug_package           %{nil}

%description
apache-activemq

%prep
%setup -q -n %{name}-%{version}

%install
mkdir -p %{buildroot}/%{app_bin_dir}/
cp -r ./* %{buildroot}/%{app_bin_dir}/


%files
%defattr(-,root,root,500)
%{app_bin_dir}/*

%post
# 生成activemq.service文件
cat > /etc/systemd/system/activemq.service <<EOF
[Unit]
Description=Apache ActiveMQ Message Broker
After=network-online.target
[Service]
Type=forking

User=root
Group=root
WorkingDirectory=%{app_bin_dir}/bin
ExecStart=%{app_bin_dir}/bin/activemq start
ExecStop=%{app_bin_dir}/bin/activemq stop
Restart=on-abort
[Install]
WantedBy=multi-user.target

EOF
systemctl enable activemq.service

# 启动
#systemctl start activemq

#%preun
#systemctl stop activemq

%postun
rm -fr %{app_bin_dir}

​

将上步打包好的文件放到此目录下/root/rpmbuild/SOURCES/

# cp -rf  /usr/local/apache-activemq-5.16.5.tar.gz/root/rpmbuild/SOURCES/

编译打包

# rpmbuild -ba activemq.spec

 会在此目录下生成rpm包

# ls /root/rpmbuild/RPMS/x86_64/

apache-activemq-5.16.5-1.el7.x86_64.rpm

4.在新的环境上安装redis的rpm包,测试是否可以正常启停

# rpm -ivh apache-activemq-5.16.5-1.el7.x86_64.rpm

配置文件中添加以下内容,否则会启动报错

# vim /opt/apache-activemq-5.16.5/bin/env

JAVA_HOME=/usr/local/jdk

 # systemctl status activemq

猜你喜欢

转载自blog.csdn.net/weixin_42272246/article/details/127927169