美文网首页自动化运维AlmaLinux
20230110-从修改yum.conf禁用内核更新不生效,到s

20230110-从修改yum.conf禁用内核更新不生效,到s

作者: 負笈在线 | 来源:发表于2023-01-10 17:33 被阅读0次

    1.修改/etc/yum.conf禁用内核更新不生效

    在进行系统补丁升级之前,通过自动化的脚本下的命令「sed -i 's#[main]#[main]\nexclude=kde* kmod-kvdo* kernel*#' /etc/yum.conf」屏蔽内核升级,但是执行「# yum check-update」发现没有屏蔽内核升级。

    修改/etc/yum.conf配置文件,禁止内核更新
    # sed -i 's#\[main\]#\[main\]\nexclude=kde* kmod-kvdo* kernel*#' /etc/yum.conf
    
    查看/etc/yum.conf修改结果
    # cat /etc/yum.conf
    [main]
    exclude=kde* kmod-kvdo* kernel*
    gpgcheck=1
    installonly_limit=3
    clean_requirements_on_remove=True
    best=True
    skip_if_unavailable=False
    
    检查yum更新包发现kernel相关包仍然要更新
    # yum check-update
    kernel.x86_64             4.18.0-425.3.1.el8    baseos
    kernel-core.x86_64        4.18.0-425.3.1.el8    baseos
    kernel-headers.x86_64     4.18.0-425.3.1.el8    baseos
    kernel-modules.x86_64     4.18.0-425.3.1.el8    baseos
    kernel-tools.x86_64       4.18.0-425.3.1.el8    baseos
    kernel-tools-libs.x86_64  4.18.0-425.3.1.el8    baseos
    kmod-kvdo.x86_64          6.2.7.17-87.el8       baseos
    

    2.修改/etc/yum.conf不生效的调查

    查看由于操作系统为Almalinux 8,虽然现在仍然用yum命令,但实际上都是跳转到dnf相关命令执行,查看/etc/yum.conf文件属性

    # ll /etc/yum.conf
    -rw-r--r-- 1 root root 140 Jan 11 00:42 /etc/yum.conf
    

    AlmaLinux/CentOS 8该配置文件应该软件至dnf.conf,对比正常服务器查看

    # ll /etc/yum.conf
    lrwxrwxrwx. 1 root root 12 Nov 15 05:27 /etc/yum.conf -> dnf/dnf.conf
    

    查看dnf.conf文件为修改配置文件

    # cat /etc/dnf/dnf.conf
    [main]
    gpgcheck=1
    installonly_limit=3
    clean_requirements_on_remove=True
    best=True
    skip_if_unavailable=False
    
    # cat /etc/yum.conf 
    [main]
    exclude=kde* kmod-kvdo* kernel*
    gpgcheck=1
    installonly_limit=3
    clean_requirements_on_remove=True
    best=True
    skip_if_unavailable=False
    

    修改/etc/dnf/dnf.conf文件配置后,执行「# yum check-update」确认不会升级内核了。

    根本原因调查
    尝试用vi命令修改/etc/yum.conf文件,修改后,文件/etc/yum.conf和/etc/dnf/dnf.conf均修改成功,且软链接仍然保持。
    怀疑是sed命令的导致软链接失效。

    3.sed修改link文件的问题

    查看sed帮助文件

    # sed -h
    ...
    --follow-symlinks
    follow symlinks when processing in place
    -i[SUFFIX], --in-place[=SUFFIX]
    edit files in place (makes backup if SUFFIX supplied)
    -c, --copy
    use copy instead of rename when shuffling files in -i mode
    ...
    If no -e, --expression, -f, or --file option is given, then the first
    non-option argument is taken as the sed script to interpret.     All
    remaining arguments are names of input files;    if no input files are
    specified, then the standard input is read.
    

    -i 直接修改文件,如果没有--follow-symlinks参数,软链接将失效。

    测试添加--follow-symlinks参数效果

    # sed -i --follow-symlinks 's#\[main\]#\[main\]\nexclude=kde* kmod-kvdo* kernel*#' /etc/yum.conf
    软链接未失效
    # ll  /etc/yum.conf
    lrwxrwxrwx 1 root root 12 Jan 11 01:14 /etc/yum.conf -> dnf/dnf.conf
    diff文件/etc/yum.conf和/etc/dnf/dnf.conf没有差分
    # diff /etc/yum.conf  /etc/dnf/dnf.conf
    # cat /etc/dnf/dnf.conf 
    [main]
    exclude=kde* kmod-kvdo* kernel*
    gpgcheck=1
    installonly_limit=3
    clean_requirements_on_remove=True
    best=True
    skip_if_unavailable=False
    

    4.后续

    1.考虑自动化脚本的向RHEL(CentOS/Rocky/AlmaLinux)7、8、9的兼容性,依然采用修改yum命令,以及修改yum.conf文件;随着RHEL 7 EOL(End of Life),应该转移到dnf工具和命令的应用中。

    2.dnf是对yum的继承和发展(DNF是“Dandified YUM”的缩写,DNF是对YUM的改写; YUM是“Yellowdog Updater, Modified”的缩写,YUM 本身是对最初为 Yellow Dog Linux 开发的“Yellowdog UPdater”或 YUP 的重写),在手动的操作中还是要快速的转移到dnf命令的应用中。

    相关文章

      网友评论

        本文标题:20230110-从修改yum.conf禁用内核更新不生效,到s

        本文链接:https://www.haomeiwen.com/subject/weqmcdtx.html