Centos核心安裝 ----yum使用及配置
因安全問題,要將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] <DIRECTORY>
[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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69934036/viewspace-2652644/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- CentOS配置Nginx官方的Yum源及yum安裝phpCentOSNginxPHP
- CentOS安裝配置yumCentOS
- CentOS 7 yum 安裝與配置 JDKCentOSJDK
- CentOS 7 yum 安裝與配置 RedisCentOSRedis
- CentOS 配置yum源CentOS
- CentOS 7 yum安裝與配置 TomcatCentOSTomcat
- redhat6.5 配置使用centos的yum源RedhatCentOS
- CentOS 7.0下使用yum安裝MySQLCentOSMySql
- VMware使用及CentOS 7安裝配置MXCentOS
- yum安裝及使用全集
- postgresql的yum安裝及配置方法SQL
- CentOS 7 安裝、配置、使用 PostgreSQL 10 安裝及基礎配置CentOSSQL
- CentOS使用iso映象檔案配置本地yum源CentOS
- Centos系統配置yum源CentOS
- CentOS6.9配置yum源CentOS
- centos7.5配置yum源CentOS
- CentOS yum安裝mcryptCentOS
- Linux下安裝java及配置(yum安裝)LinuxJava
- centos7使用yum安裝lnmp環境CentOSLNMP
- centos7安裝mysql5.7 使用yumCentOSMySql
- Centos6下使用yum安裝MariaDBCentOS
- 在CentOS7中,使用yum安裝NginxCentOSNginx
- centos7中使用yum安裝OpenJDKCentOSJDK
- CentOS7下MySQL5.7安裝與配置(YUM)CentOSMySql
- centos7中使用yum安裝NGINX安裝CentOSNginx
- CentOS 6 網路yum源配置CentOS
- 配置本地yum源及安裝必要的包
- 12C安裝及本地YUM源配置
- CentOS 7.0最小安裝及配置CentOS
- CentOS 7 yum 安裝 MySQLCentOSMySql
- CentOS 7 yum 安裝 NGINXCentOSNginx
- CentOS下yum安裝MySQLCentOSMySql
- Centos 7 yum 安裝nginxCentOSNginx
- Centos-Stream 配置本地yum源和配置阿里雲yum源CentOS阿里
- Centos 安裝yum,安裝ansibleCentOS
- (轉)使用yum來安裝CentOS圖形介面包CentOS
- Centos7系統中找不到yum及安裝方法。CentOS
- yum方式安裝及配置最新的mysql5.7MySql