源码下载地址:
https://www.openssl.org/source/openssl-3.0.10.tar.gz
编写spec文件:
cat << 'EOF' > openssl.spec
Summary: OpenSSL 3.0.10 for Centos
Name: openssl
Version: %{?version}%{!?version:3.0.10}
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
OpenSSL RPM for version 3.0.10 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 3.0.10 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.3 %{buildroot}%{_libdir}
ln -sf %{openssldir}/lib/libcrypto.so.3 %{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.3
/usr/lib64/libssl.so.3
%files devel
%{openssldir}/include/*
%defattr(-,root,root)
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
EOF
安装依赖包:
yum install curl which make gcc perl perl-WWW-Curl perl-CPAN perl-IPC-Cmd perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker -y
制作rpm包:
cd rpmbuild/SPEC/
rpmbuild -ba openssl.spec
安装:
#卸载旧版openssl, 切记不要删除openssl-libs
rpm -qa | grep openssl
rpm -e --justdb --nodeps <yourpackage>
#安装新版
rpm -ivh openssl-xxx.rpm --nodeps
#检查验证
openssl version
rpm -qa | grep openssl
# 找不到库文件,建立软链接解决
ln -s /usr/openssl/lib64/libssl.so.3 /usr/lib64/libssl.so.3
ln -s /usr/openssl/lib64/libcrypto.so.3 /usr/lib64/libcrypto.so.3