centos7 build openssl1.1.1l rpm


1.下载openssl-1.1.1l.tar.gz

wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz

2.安装工具包

yum -y install which make gcc perl perl-WWW-Curl rpm-build

3.创建相关目录

mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

4.移动openssl-1.1.1l.tar.gz到/root/rpmbuild/SOURCES

mv openssl-1.1.1l.tar.gz /root/rpmbuild/SOURCES

5.编写openssl软件库包的spec文件

cat << 'EOF' > /root/rpmbuild/SPECS/openssl.spec
Summary: OpenSSL 1.1.1 for Centos
Name: openssl
Version: %{?version}%{!?version:1.1.1l}
Release: 1%{?dist}
Obsoletes: %{name} <= %{version}
Provides: %{name} = %{version}
URL: https://www.openssl.org/
License: GPLv2+
Source: https://www.openssl.org/source/%{name}-%{version}.tar.gz
BuildRequires: make gcc perl perl-WWW-Curl
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
%global openssldir /usr/openssl
%description
https://github.com/philyuchkoff/openssl-RPM-Builder
OpenSSL RPM for version 1.1.1l on Centos
%package devel
Summary: Development files for programs which will use the openssl library
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
%description devel
OpenSSL RPM for version 1.1.1l on Centos (development package)
%prep
%setup -q
%build
./config --prefix=%{openssldir} --openssldir=%{openssldir}
make
%install
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%make_install
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_libdir}
ln -sf %{openssldir}/lib/libssl.so.1.1 %{buildroot}%{_libdir}
ln -sf %{openssldir}/lib/libcrypto.so.1.1 %{buildroot}%{_libdir}
ln -sf %{openssldir}/bin/openssl %{buildroot}%{_bindir}
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%files
%{openssldir}
%defattr(-,root,root)
/usr/bin/openssl
/usr/lib64/libcrypto.so.1.1
/usr/lib64/libssl.so.1.1
%files devel
%{openssldir}/include/*
%defattr(-,root,root)
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
EOF

6.构建rpm包

cd /root/rpmbuild/SPECS
rpmbuild -D "version 1.1.1l" -ba openssl.spec

7.构建成功后/root/rpmbuild/RPMS/x86_64/目录下面会有对应的rpm包

卸载原有openssl

rpm -qa|grep openssl|awk '{print $1}'|rpm -e

安装构建的rpm包

rpm -ivh /root/rpmbuild/RPMS/x86_64/openssl-1.1.1l-1.el7.x86_64.rpm --nodeps

验证

openssl version


Whatever is worth doing is worth doing well.