概述
今天被一个 systemd 的问题缠住了,于是就去 Github 上提 issue,没想到人家上来就说版本太老,让我先升级了版本再说,没办法,为了证明是 systemd 确实如此,我决定升级 systemd。
2020-11-02
不甘心又重新来了一把,最终成功升级到当前的最新版本 246!以下步骤可用。为了防止其他因素影响,我重新安装了一个最小化安装的 CentOS 7,然后更新内核到最新的 5.9.1,然后后续的内容就都记录在下面了。
如果你也想更新内核,我也记录了另外一篇文章:升级 CentOS 内核
2019-11-21
注:这是一篇升级失败的文章记录,我试图在 CentOS 7.6 中升级最新的 Systemd,最终失败,原因在于无法将系统的 glibc 升级到 2.34,从而导致后续无法继续!
下载代码
直接再 Release 页面中下载就可以了:
我下载了 V246 版本
环境预处理
因为后面需要安装一些编译工具,然后可能需要 3.5 以上的 Python 版本,所以,如果你的系统中没有安装,可以按照我的另外一片引导先安装一个:
然后还要安装其他软件:
[[email protected]]# yum install http://repo.okay.com.mx/centos/7/x86_64/release/okay-release-1-1.noarch.rpm
[[email protected]]# yum groupinstall -y 'Development Tools'
[[email protected]]# pip3 install meson
[[email protected]]# yum install -y libcap-devel ninja-build
[[email protected]]# wget http://ftp.gnu.org/pub/gnu/gperf/gperf-3.1.tar.gz
[[email protected]]# tar zxf gperf-3.1.tar.gz && cd gperf-3.1 && ./configure && make && make install
[[email protected]]# wget https://github.com/Kitware/CMake/releases/download/v3.18.4/cmake-3.18.4-Linux-x86_64.tar.gz
[[email protected]]# tar zxf cmake-3.18.4-Linux-x86_64.tar.gz
[[email protected]]# export PATH=$PATH:`pwd`/cmake-3.18.4-Linux-x86_64/bin
[[email protected]]# wget https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.30/util-linux-2.30.2.tar.gz
[[email protected]]# tar zxf util-linux-2.30.2.tar.gz && cd util-linux-2.30.2 && ./configure \
--disable-all-programs --enable-mount --enable-libmount \
--enable-libblkid --enable-libuuid && make && make install
[[email protected]]# ln /usr/lib/libmount.so /usr/lib64/libmount.so
[[email protected]]# cp ./libmount/mount.pc /usr/lib64/pkgconfig/mount.pc
编译
[[email protected]]# wget https://github.com/systemd/systemd/archive/v246.tar.gz
[[email protected]]# tar zxf v246.tar.gz
[[email protected]]# cd systemd-246/
[[email protected]]# ./configure && make && make install
测试
到此如果没有出错,就算是成功了,那么接下来验证一下是否正常工作:
[[email protected]]# reboot # 这里为了保险期间,重启一个先
[[email protected]]# uname -a
Linux localhost.localdomain 5.9.3-1.el7.elrepo.x86_64 #1 SMP Sat Oct 31 09:41:18 EDT 2020 x86_64 x86_64 x86_64 GNU/Linux
[[email protected]]# systemctl --version
systemd 246 (246)
-PAM -AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP -LIBCRYPTSETUP -GCRYPT -GNUTLS -ACL -XZ -LZ4 -ZSTD -SECCOMP +BLKID -ELFUTILS -KMOD -IDN2 -IDN -PCRE2 default-hierarchy=unified
图 1:升级 Systemd 成功 |
---|
OK,毫无疑问,升级成功。
遇到过的问题
1. meson: not found
看上去是有个构建工具没装,那就装一个,因为 meson 依赖于 Python3,所以很不幸,还得装个 Python3 先,还好我以前有教程:CentOS 安装 Python3.8,装完之后就简单了:
[[email protected]]# pip3 install meson
2. gperf not found
gperf not found or not executable
看上去又缺少工具:
[[email protected]]# wget http://ftp.gnu.org/pub/gnu/gperf/gperf-3.1.tar.gz
[[email protected]]# tar zxf gperf-3.1.tar.gz
[[email protected]]# cd gperf-3.1
[[email protected]]# ./configure
[[email protected]]# make && make install
3. 升级 Make
[[email protected]]# cd /tmp
[[email protected]]# wget http://ftp.gnu.org/gnu/make/make-4.1.tar.gz
[[email protected]]# tar xvf make-4.1.tar.gz
[[email protected]]# cd make-4.1/
[[email protected]]# ./configure
[[email protected]]# make
[[email protected]]# sudo make install
[[email protected]]# cp /usr/bin/make /usr/bin/make3
[[email protected]]# cp /usr/local/bin/make /usr/bin/make
[[email protected]]# make -v
4. 升级 glibc
[[email protected]]# wget wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
[[email protected]]# tar zxf glibc-2.28.tar.gz
[[email protected]]# cd glibc-2.28
[[email protected]]# mkdir build
[[email protected]]# cd build
[[email protected]]# ../configure --prefix=/opt/glibc-2.28 --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
[[email protected]]# make
[[email protected]]# make install
[[email protected]]# ldd --version
ldd (GNU libc) 2.28
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
这个在最后阶段遇到了点问题:
/root/systemd/glibc-2.28/build/elf/ldconfig: Warning: ignoring configuration file that cannot be opened: /opt/glibc-2.28/etc/ld.so.conf: No such file or directory
解决方式为:
cp /etc/ld.so.c* /opt/glibc-2.28/etc/
!!! 温馨提示,如果升级崩了怎么办?
这条命令救了我:
[[email protected]]# ldconfig
5. cannot find -lnss_test2
在 install 的时候遇到了问题:
... ...
LD_SO=ld-linux-x86-64.so.2 CC="gcc -B/usr/bin/" /usr/bin/perl scripts/test-installation.pl /root/systemd/glibc-2.28/build/
/usr/bin/ld: cannot find -lnss_test2
collect2: error: ld returned 1 exit status
... ...
可以忽略
6. headers not found
Problem encountered: POSIX caps headers not found
通过 yum provides 查看依赖的包,然后安装即可:
[[email protected]]# yum provides '*sys/capability.h'
libcap-devel-2.22-11.el7.x86_64 : Development files for libcap
Repo : @base
Matched from:
Filename : /usr/include/sys/capability.h
[[email protected]]# yum install -y libcap-devel
7. mount not found
Dependency "mount" not found, tried pkgconfig and cmake
直接通过编译安装 util-linux 解决,但是直接 make install
还不行,所以我还特地看了一下 libmount-devel
有哪些文件,然后一个个地去看什么没有:
[[email protected]]# repoquery -ql libmount-devel
[[email protected]]# ls -al /usr/include/libmount
[[email protected]]# ls -al /usr/lib/libmount.so
[[email protected]]# ls -al /usr/lib/pkgconfig/mount.pc
[[email protected]]# ls -al /usr/include/libmount
[[email protected]]# ls -al /usr/lib64/libmount.so
[[email protected]]# ls -al /usr/lib64/libmount.so
[[email protected]]# ls -al /usr/lib64/pkgconfig/mount.pc
然后将没有的补上:
[[email protected]]# ln /usr/lib/libmount.so /usr/lib64/libmount.so
[[email protected]]# cp ./libmount/mount.pc /usr/lib64/pkgconfig/mount.pc