新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Centos内核安装中如何进行yum使用及配置,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
创新互联建站主要从事成都网站设计、成都网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务灌云,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108
因安全问题,要将Linux内核2.6.X的内核升级到最新的版本。
以centos6.5为例,考虑下列问题:
(1). 查看当前内核版本,网上搜索现提供的最新版本;
(2). 测试服务器可以连接网络的情况下,如何升级内核?yum仓库指向镜像网站上
(3). 测试服务器不允许连接网络的情况下,如何升级内核?下载升级包,配置私有仓库
问题1: 查看当前内核版本: [root@localhost ~]# uname -r 2.6.32-431.el6.x86_64 网络搜索:http://mirrors.aliyun.com/centos/6/updates/x86_64/Packages/ 内核最新版本:kernel-2.6.32-754.17.1.el6.x86_64.rpm
问题2:测试服务器可以连接网络的情况下,如何升级内核 2.1先对测试服务器测试连接互联网情况:
[root@localhost yum.repos.d]# ping mirrors.aliyun.com PING mirrors.aliyun.com.w.alikunlun.com (183.2.199.240) 56(84) bytes of data. 64 bytes from 183.2.199.240: icmp_seq=1 ttl=57 time=8.30 ms 64 bytes from 183.2.199.240: icmp_seq=2 ttl=57 time=8.54 ms 64 bytes from 183.2.199.240: icmp_seq=3 ttl=57 time=8.58 ms
若出现下列情况,则配置DNS
[root@status etc]# ping mirrors.aliyun.com ping: unknown host mirrors.aliyun.com [root@status etc]# ping 183.2.199.240 ---- ping IP通,但ping网址不同,DNS未设置 PING 183.2.199.240 (183.2.199.240) 56(84) bytes of data. 64 bytes from 183.2.199.240: icmp_seq=1 ttl=57 time=13.7 ms 64 bytes from 183.2.199.240: icmp_seq=2 ttl=57 time=7.46 ms [root@status etc]# vi /etc/resolv.conf ---- 设置DNS服务器就可以了 nameserver 8.8.8.8
若IP也ping不通,请核查gw和route。
2.2 Linux程序包管理知识 yum : yellowdog update Modifier; 一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器(CS架构的软件),基于RPM包管理, 能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包。 原理: yum程序包管理器是类似CS架构的软件: server和client Server端:先对程序包进行分类后存储到不同repository容器中; 再通过收集到大量的rpm的数据库文件中程序包之间的依赖关系数据, 生成对应的依赖关系和所需文件在本地的存放位置的说明文件(.xml格式), 存放在本地的repodata目录下供Client端取用 ; Cilent端:通过yum命令安装软件时发现缺少某些依赖性程序包, Client会根据本地的配置文件(/etc/yum.repos.d/*.repo)找到指定的Server端, 从Server端repo目录下获取说明文件xxx.xml后存储在本地/var/cache/yum中方便以后读取, 通过xxx.xml文件查找到需要安装的依赖性程序包在Server端的存放位置, 再进入Server端yum库中的指定repository容器中获取所需程序包, 下载完成后在本地实现安装. yum repository : yum repo 存储了众多的rpm包,以及包的相关元数据文件(放在特定目录下,repsdata) yum客户端 安装了yumrpm包的系统; 查看其配置文件 [root@localhost mydata]# rpm -qc yum /etc/logrotate.d/yum /etc/yum.conf ---为仓库提供公共配置 /etc/yum/version-groups.conf 还有一个 /etc/yum.repso.d/*.repo 为仓库的指向提供配置(通过读取/etc/yum.conf里面的内容) 仓库客服端的配置格式:/etc/yum.repso.d/*.repo [repositoryid] name = baseurl= url://server1/path/to/repsoitory (可以多个url,但必须是同一种仓库,作为冗余) enable=(0|1) gpgcheck=(0|1) gpgkey=url enablegroups={0|1} failovermethod={roundrobin|priority} 默认roundrobin,为随机挑选 cost 默认1000 仓库客服端的配置可用变量: $releasever : 当前os的发行版本号; &arch : 平台; $basearch : 基础平台 yum命令: [options] [command] [package ...] 显示仓库列表: repolist [all|enabled|disabled] 显示程序包: list # yum list [all | glob_exp1] [glob_exp2] [...] # yum list [availabel | installed | updates] [glob_exp1] 安装程序包: install package1 [package2] [...] 升级程序包: upgrade [package1] [package2] [...] upgrade-to [package1] [package2] [...] 降级程序包: downgrade package1 [package2] [...] 检查升级程序包: check-update 卸载程序包:remove | erase package1 [package2] [...] 查看程序包: info [...] 查看指定的特性(可以是某文件)是由哪个程序包提供: provides | whatprovides feature1 [feature2] [...] 清理本地缓存:clean [ packages | metadata | expire-cache | rpmdb | plugins | all ] 搜索: search string1 [string2] [...] 查看指定包依赖的capabilities: 查看yum的事物历史: history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats] 包组管理: grouplist groupinfo groupinstall group1 groupupdata group1 groupremove group1
2.3 安装步骤 升级内核: 内核可以多个存在,所有选择安装新内核保留原内核,不进行直接升级 (1)rpm --import https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 包来源合法性验证和完整性验证 来源合法性验证: 私钥 | 程序包--->校验码--->特征码---->加密特征码---客户(拿到公钥,要确保公钥来源可靠)--->解密--->对比特征码 获取并导入信息的包制作者的密钥 对于centos发行版: rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 验证: (1.1): 安装此组织签名的程序时,会自动执行; (1.2): 手动验证 rpm -k PACKAGE_FILE
[root@status tmp]# rpm -K kernel-2.6.32-754.15.3.el6.x86_64.rpm kernel-2.6.32-754.15.3.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
(2) 配置客户仓库项目:
[root@status yum.repos.d]# vi CentOS-Base.repo [updates] name=CentOS-$releasever - Update baseurl=https://mirrors.aliyun.com/centos/6/updates/x86_64/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[root@status yum.repos.d]# yum repolist Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile updates | 3.4 kB 00:00 repo id repo name status updates CentOS-6 - Updates 559 repolist: 559
安装:
[root@status /]# yum info kernel.x86_64 ----查看当前内核的信息及最新内核 Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Installed Packages Name : kernel Arch : x86_64 Version : 2.6.32 Release : 431.el6 Size : 121 M Repo : installed From repo : anaconda-CentOS-201311272149.x86_64 Summary : The Linux kernel URL : http://www.kernel.org/ License : GPLv2 Description : The kernel package contains the Linux kernel (vmlinuz), the core of any : Linux operating system. The kernel handles the basic functions : of the operating system: memory allocation, process allocation, device : input and output, etc. Available Packages Name : kernel Arch : x86_64 Version : 2.6.32 Release : 754.17.1.el6 Size : 32 M Repo : update Summary : The Linux kernel URL : http://www.kernel.org/ License : GPLv2 Description : The kernel package contains the Linux kernel (vmlinuz), the core of any : Linux operating system. The kernel handles the basic functions : of the operating system: memory allocation, process allocation, device : input and output, etc.
[root@status /]# yum deplist kernel.x86_64 -----查看内核安装的依赖包 package: kernel.x86_64 2.6.32-754.17.1.el6 dependency: dracut-kernel >= 004-408.el6 Unsatisfied dependency dependency: /sbin/new-kernel-pkg Unsatisfied dependency dependency: module-init-tools Unsatisfied dependency dependency: initscripts >= 8.11.1-1 Unsatisfied dependency dependency: fileutils Unsatisfied dependency dependency: kernel-firmware >= 2.6.32-754.17.1.el6 provider: kernel-firmware.noarch 2.6.32-754.17.1.el6 dependency: /bin/sh Unsatisfied dependency dependency: grubby >= 7.0.4-1 Unsatisfied dependency
[root@status /]# yum install -y kernel.x86_64 ----安装时报依赖包未安装!! Loaded plugins: fastestmirror, security Determining fastest mirrors base | 3.4 kB 00:00 base/primary_db | 5.2 MB 00:01 Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package kernel.x86_64 0:2.6.32-754.17.1.el6 will be installed --> Processing Dependency: kernel-firmware >= 2.6.32-754.17.1.el6 for package: kernel-2.6.32-754.17.1.el6.x86_64 --> Processing Dependency: dracut-kernel >= 004-408.el6 for package: kernel-2.6.32-754.17.1.el6.x86_64 --> Running transaction check ---> Package kernel.x86_64 0:2.6.32-754.17.1.el6 will be installed --> Processing Dependency: dracut-kernel >= 004-408.el6 for package: kernel-2.6.32-754.17.1.el6.x86_64 ---> Package kernel-firmware.noarch 0:2.6.32-431.el6 will be updated ---> Package kernel-firmware.noarch 0:2.6.32-754.17.1.el6 will be an update --> Finished Dependency Resolution Error: Package: kernel-2.6.32-754.17.1.el6.x86_64 (base) Requires: dracut-kernel >= 004-408.el6 -----需要这个依赖包!! Installed: dracut-kernel-004-335.el6.noarch (@anaconda-CentOS-201311272149.x86_64/6.5) dracut-kernel = 004-335.el6 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
依赖包在哪里呢,不在update的Packege里面,难道在系统安装的Package里面? 于是再次修改仓库配置, 加入base的指向为:https://mirrors.aliyun.com/centos/6/os/x86_64/
[root@status yum.repos.d]# vi CentOS-Base.repo ----增加base的配置项 [base] name=CentOS-$releasever - Base baseurl=https://mirrors.aliyun.com/centos/6/os/x86_64/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 [update] name=CentOS-$releasever - Update baseurl=https://mirrors.aliyun.com/centos/6/updates/x86_64/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[root@status /]# yum repolist ----查看仓库是否配置成功 Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile base | 3.7 kB 00:00 Not using downloaded repomd.xml because it is older than what we have: Current : Thu Jul 25 00:22:12 2019 Downloaded: Fri Jun 29 23:37:23 2018 update | 3.4 kB 00:00 repo id repo name status base CentOS-6 - Base 559 update CentOS-6 - Update 559 repolist: 1,118
再次执行yum install -y kernel.x86_64 依然报错!!?? 看看上面的yum repolist,base和update的Package包数目都是一样的,base没有更新仓库信息,晕死。
[root@status /]# yum clean all ----清空本地缓存 Loaded plugins: fastestmirror, security Cleaning repos: base update Cleaning up Everything Cleaning up list of fastest mirrors [root@status /]# yum repolist ----查看仓库是否配置成功,这次仓库信息同步了 Loaded plugins: fastestmirror, security Determining fastest mirrors base | 3.7 kB 00:00 base/primary_db | 4.7 MB 00:01 update | 3.4 kB 00:00 update/primary_db | 5.2 MB 00:00 repo id repo name status base CentOS-6 - Base 6,713 update CentOS-6 - Update 559 repolist: 7,272
[root@status /]# yum install -y kernel.x86_64 Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies ...... Dependencies Resolved ..... Installed: kernel.x86_64 0:2.6.32-754.17.1.el6 Dependency Updated: ----这几个依赖安装包被update了 dracut.noarch 0:004-411.el6 dracut-kernel.noarch 0:004-411.el6 kernel-firmware.noarch 0:2.6.32-754.17.1.el6 Complete!
查看引导内核项
[root@status etc]# cat grub.conf # grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root # initrd /initrd-[generic-]version.img #boot=/dev/sda default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title CentOS (2.6.32-754.17.1.el6.x86_64) ----新安装的内核,使用排头位的 root (hd0,0) kernel /vmlinuz-2.6.32-754.17.1.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-754.17.1.el6.x86_64.img title CentOS (2.6.32-431.el6.x86_64) ----原来的内核 root (hd0,0) kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-431.el6.x86_64.img
reboot系统就可以使用新的内核。
问题3:测试服务器不允许连接网络的情况下,如何升级内核 3.1 如何批量下载Packges。
[root@localhost tmp]#wget -nd -r -l1 -A.rpm --no-parent http://mirrors.aliyun.com/centos/6/updates/x86_64/Packages/ -e robots=off
-- 批量下载包,注意这里用用https会报错,要么根据提示修改参数,要么改成http
[root@localhost Pachages]# tar -zcf /mnt/data/update_pachages.tar.gz *.rpm ---打包updatePachages,用来上传到不能对外链接的服务器 [root@localhost data]# watch -n 5 "du -h update_pachages.tar.gz " ---观察打包进度 Every 5.0s: du -h update_pachages.tar.gz Mon Jul 22 08:03:49 2019 5.7G update_pachages.tar.gz
用同样的方法可以打包安装介质(或者挂载安装光盘拷贝也可以),最后拷贝文件到本地移动存储设备,转存到yum私有仓库服务器。
3.2 Linux程序包管理知识 创建yum仓库: createrepo [OPTION]
[root@localhost ~]# yum list installed |grep createrepo ---未安装 [root@localhost etc]# yum install -y createrepo ---安装rpm
建立一个目录用于存放安装包,然后使用createrepo来创建repository仓库; 命令执行成功后会在该目录下创建一个repodata目录,客户端配置指向此处。
[root@localhost updates]# createrepo ./ Spawning worker 0 with 1 pkgs Workers Finished Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete [root@localhost updates]# ls Packages repodata
关于Centos内核安装中如何进行yum使用及配置问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。