概述 自2006年OracleLinux推出以来,OracleLinux一直完全免费下载和使用,无需任何许可费用。Oracle为完整的操作环境提供支持,该环境提供集成的虚拟化、管理和云原生计算工具套件,以及Linx操作系统。我们知道自从CENTOS断更之后,OracleLinux,是一个可选项,那么对于目前存量系统,如何从CENTOS一键迁移到OracleLinux呢?今天分享一键迁移脚本,让你轻松过渡至OracleLinux一键迁移脚本!binbashCopyright(c)2020,2021Oracleandoritsaffiliates。LicensedundertheUniversalPermissiveLicensev1。0asshownathttps:oss。oracle。comlicensesupl。ScripttoswitchCentOS(orothersimilardistribution)totheOracleLinuxyumrepository。seteunsetCDPATHyumurlhttps:yum。oracle。comgithuburlhttps:github。comoraclecentos2olarch(unamem)badpackages(centosbackgroundscentosgpgkeyscentoslogoscentosreleasecentosreleasecrdesktopbackgroundsbasiccentosreleaseadvancedvirtualizationcentosreleaseansible26centosreleaseansible27centosreleaseansible28centosreleaseansible29centosreleaseazurecentosreleasecephjewelcentosreleasecephluminouscentosreleasecephnautiluscentosreleasecephoctopuscentosreleaseconfigmanagementcentosreleasedotnetcentosreleasefdiocentosreleasegluster40centosreleasegluster41centosreleasegluster5centosreleasegluster6centosreleasegluster7centosreleasegluster8centosreleaseglusterlegacycentosreleasemessagingcentosreleasenfsganesha28centosreleasenfsganesha30centosreleasenfvcommoncentosreleasenfvopenvswitchcentosreleaseopenshiftorigincentosreleaseopenstackqueenscentosreleaseopenstackrockycentosreleaseopenstacksteincentosreleaseopenstacktraincentosreleaseopenstackussuricentosreleaseopstoolscentosreleaseovirt42centosreleaseovirt43centosreleaseovirt44centosreleasepaascommoncentosreleaseqemuevcentosreleaseqpidprotoncentosreleaserabbitmq38centosreleasesamba411centosreleasesamba412centosreleasesclcentosreleasesclrhcentosreleasestoragecommoncentosreleasevirtcommoncentosreleasexencentosreleasexen410centosreleasexen412centosreleasexen46centosreleasexen48centosreleasexencommonlibreportcentoslibreportpluginmantisbtlibreportpluginrhtsupportpython3syspurposepythonoauthrockybackgroundsrockygpgkeysrockylogosrockyreleasesllogosyumrhnplugin)usage(){echoUsage:{0}〔OPTIONS〕echoechoOPTIONSechohechoDisplaythishelpandexitechokechoDonotinstalltheUEKkernelanddisableUEKreposechorechoReinstallallCentOSRPMswithOracleLinuxRPMsechoNote:ThisisnotnecessaryforsupportechoVechoVerifyRPMinformationbeforeandaftertheswitchexit1}2haveprogram(){hash1devnull21}depcheck(){if!haveprogram1;thenexitmessage{1}commandnotfound。PleaseinstalloraddittoyourPATHandtryagain。fi}exitmessage(){echo1echoForassistance,pleaseopenanissueviaGitHub:{githuburl}。exit1}2finalfailure(){echoAnerroroccurredwhileattemptingtoswitchthissystemtoOracleLinuxanditmaybeinanunstableunbootablestate。Toavoidfurtherissues,thescripthasterminated。}generaterpmsinfo(){echoCreatingalistofRPMsinstalled1theswitchrpmqaqf{NAME}{EPOCH}:{VERSION}{RELEASE}。{ARCH}{INSTALLTIME}{VENDOR}{BUILDTIME}{BUILDHOST}{SOURCERPM}{LICENSE}{PACKAGER}seds(none):gsortvartmp(hostname)rpmslist1。logechoVerifyingRPMsinstalled1theswitchagainstRPMdatabaserpmVasortk3vartmp(hostname)rpmsverified1。log}StartofscriptreinstallallrpmsfalseverifyallrpmsfalseinstalluekkerneltruewhilegetoptshrkVdocaseoptioninh);r);k);V););esacdoneForcetheUEKonArmhostsif〔archaarch64〕;theninstalluekkerneltruefiif〔(idu)ne0〕;thenexitmessageYoumustrunthisscriptasroot。Tryrunningsuc{0}。fiechoCheckingforrequiredpackages。。。dodepcheck{pkg}doneechoCheckingyourdistribution。。。if!oldrelease(rpmqwhatprovidesetcredhatrelease);thenexitmessageYouappeartoberunninganunsupporteddistribution。fiif〔(echo{oldrelease}wcl)ne1〕;thenexitmessageCouldnotdetermineyourdistributionbecausemultiplepackagesareprovidingredhatrelease:oldreleasefiCollectinformationaboutRPMsbeforetheswitchif{verifyallrpms};thengeneraterpmsinfobeforeficase{oldrelease}inredhatrelease);;centosreleasecentoslinuxrelease);;rockyrelease);;slrelease);;oraclelinuxreleaseenterpriserelease)exitmessageYouappeartobealreadyrunningOracleLinux。;;)exitmessageYouappeartoberunninganunsupporteddistribution。;;esacosversion(rpmq{oldrelease}qf{version})majorosversion{osversion:0:1}if{installuekkernel};thenbasepackages(basesysteminitscriptsoraclelogoskerneluek)elsebasepackages(basesysteminitscriptsoraclelogos)ficaseosversionin8)repofilepublicyumol8。reponewreleases(oraclelinuxreleaseoraclelinuxreleaseel8redhatrelease)basepackages({basepackages〔〕}plymouthgrub2grubby);;7)repofilepublicyumol7。reponewreleases(oraclelinuxreleaseoraclelinuxreleaseel7redhatreleaseserver)basepackages({basepackages〔〕}plymouthgrub2grubby);;6)repofilepublicyumol6。reponewreleases(oraclelinuxreleaseoraclelinuxreleaseel6redhatreleaseserver)basepackages({basepackages〔〕}oraclelinuxreleasenotesplymouthgrubgrubby);;)exitmessageYouappeartoberunninganunsupporteddistribution。;;esacSomepackagesneedtobereplacedaspartofswitchStoreaskeyvalue,ifthefirstRPMisfoundthenitsremovedandtheassociatedRPMinstalleddeclareApackagestoreplace(〔epelrelease〕oracleepelreleaseel{majorosversion})SwitchRPMsiftheyreinstalledforpackagenamein{!packagestoreplace〔〕};doifrpmq{packagename};thenbadpackages({packagename})basepackages({packagestoreplace〔{packagename}〕})fidoneechoCheckingforyumlock。。。if〔fvarrunyum。pid〕;thenyumlockpid(catvarrunyum。pid)yumlockcomm(catproc{yumlockpid}comm)exitmessageAnotherappiscurrentlyholdingtheyumlock。Theotherapplicationis:yumlockcommRunningaspid:yumlockpidRunkillyumlockpidtostopit,thenrunthisscriptagain。fiechoCheckingforrequiredpythonpackages。。。caseosversionin8);)depcheckpython2;;esacif〔〔osversion8。〕〕;thenechoIdentifyingdnfmodulesthatareenabledThereareafewdnfmodulesthatarenamedafterthedistributionforeachsteamnamedrhelorrhel8weneedtomakealterationstoolorol8Beforewestarttheswitch,identifyifthereareanypresentwedontknowhowtohandlemapfiletmodulesenabled(dnfmodulelistenabledgreprhelawk{print1})if〔〔{modulesenabled〔〕}〕〕;thenCreateanarrayofmoduleswedontknowhowtomanageunknownmodules()formodulein{modulesenabled〔〕};docase{module}incontainertoolsgotoolsetjmcllvmtoolsetrusttoolsetvirt);;)Addthismodulenametoourarrayofmoduleswedontknowhowtomanageunknownmodules({module});;esacdoneIfwehaveanymoduleswedontknowhowtomanage,asktheuserhowtoproceedif〔{unknownmodules〔〕}gt0〕;thenechoThistoolisunabletoautomaticallyswitchmodule(s){unknownmodules〔〕}fromaCentOSrhelstreamtoanOracleLinuxequivalent。Doyouwanttocontinueandresolveitmanually?YoumaywantselectNotostopandraiseanissueon{githuburl}foradvice。selectyninYesNo;docaseyninYes);No)echoUnsurehowtoswitchmodule(s){unknownmodules〔〕}。Exitingasrequestedexit1;;esacdonefififiechoFindingyourrepositorydirectory。。。caseosversionin8)reposdir(usrlibexecplatformpythoncimportdnfimportosdirdnf。Base()。conf。getreposdirifos。path。isdir(dir):print(dir));;)reposdir(python2cimportyumimportosfordirinyum。YumBase()。doConfigSetup(initpluginsFalse)。reposdir:ifos。path。isdir(dir):printdirbreak);;esacechoLearningwhichrepositoriesareenabled。。。caseosversionin8)enabledrepos(usrlibexecplatformpythoncimportdnfbasednf。Base()base。readallrepos()forrepoinbase。repos。iterenabled():print(repo。id));;)enabledrepos(python2cimportyumbaseyum。YumBase()base。doConfigSetup(initpluginsFalse)forrepoinbase。repos。listEnabled():printrepo);;esacechoeRepositoriesenabledbeforeupdateinclude:{enabledrepos}if〔z{reposdir}〕;thenexitmessageCouldnotlocateyourrepositorydirectory。ficdreposdirNohttps:yum。oracle。compublicyumol8。repofileexistsDownloadthecontentfor6and7basedsystemsanddirectlyenterthecontentfor8basedsystemscaseosversionin8)catswitchtooraclelinux。repoEOF〔ol8baseoslatest〕nameOracleLinux8BaseOSLatest(basearch)baseurlhttps:yum。oracle。comrepoOracleLinuxOL8baseoslatestbasearchgpgkeyfile:etcpkirpmgpgRPMGPGKEYoraclegpgcheck1enabled1〔ol8appstream〕nameOracleLinux8ApplicationStream(basearch)baseurlhttps:yum。oracle。comrepoOracleLinuxOL8appstreambasearchgpgkeyfile:etcpkirpmgpgRPMGPGKEYoraclegpgcheck1enabled1EOFif〔archx8664〕;thencatswitchtooraclelinux。repoEOF〔ol8UEKR6〕nameLatestUnbreakableEnterpriseKernelRelease6forOracleLinuxreleasever(basearch)baseurlhttps:yum。oracle。comrepoOracleLinuxOL8UEKR6basearchgpgkeyfile:etcpkirpmgpgRPMGPGKEYoraclegpgcheck1enabled1EOF;)echoDownloadingOracleLinuxyumrepositoryfile。。。if!curloswitchtooraclelinux。repo{yumurl}{repofile};thenexitmessageCouldnotdownloadrepofilefromyumurl。Areyoubehindaproxy?Ifso,makesurethehttpproxyenvironmentvariableissetwithyourproxyaddress。;esacechoLookingforyumdownloader。。。if!thenCentOS6mirrorsarenowoffline,ifyumdownloadertoolisnotpresentthenuseOL6assourceforyumutilsanddisableallotherrepos。Usetheexistingdistributionscopyforotherplatformscaseosversionin6)curloetcpkirpmgpgRPMGPGKEYoraclehttps:yum。oracle。comRPMGPGKEYoracleol6yumyinstallyumutilsdisablerepoenablerepool6;);esacdepcheckyumdownloaderficd(mktempd)trapfinalfailureERRMostdistroskeeptheiretcyum。repos。dcontentinthereleaserpm。CentOS88。0usescentosreposwhile8。3usescentoslinuxrepos,globforsimplicity。if〔〔oldreleasecentosrelease8。〕〕〔〔oldreleasecentoslinuxrelease8。〕〕;thenoldrelease(rpmqacentosrepos)fiMostdistroskeeptheiretcyum。repos。dcontentinthereleaserpm。RockyLinux8doesnot。if〔〔oldreleaserockyrelease8。〕〕;thenoldrelease(rpmqarockyrepos)fiechoBackingupandremovingoldrepositoryfiles。。。IdentifyrepofilesfromthebaseOSrpmqloldreleasegrep。repo39;repofilesIdentifyrepofilesfromCentOSextrasif〔(rpmqacentosreleasewcl)gt0〕;thenrpmqlacentosreleasegrep。repo39;doif〔frepo〕;thencatreporepo。disabledEOFThisisayumrepositoryfilethatwasdisabledby{0},ascripttoconvertCentOStoOracleLinux。Pleaseseeyumurlformoreinformation。EOFtmpfile(mktemprepo。XXXXX)echorepocatrepotmpfilermrepofidonerepofilesDisabletheexplicitdistroverpkgascentosreleaseprovidesthecorrectvalueforsystemrelease(releasever)。Seehttps:github。comoraclecentos2olissues53echoRemovingCentOSspecificyumconfigurationfrometcyum。confsedi。bakesdistroverpkggesbugtrackerurlgetcyum。confechoDownloadingOracleLinuxreleasepackage。。。if!yumdownloader{newreleases〔〕};then{echoCouldnotdownloadthefollowingpackagesfromyumurl:echo{newreleases〔〕}echoechoAreyoubehindaproxy?Ifso,makesurethehttpproxyenvironmentechovariableissetwithyourproxyaddress。}2finalfailurefiechoSwitchingoldreleasepackagewithOracleLinux。。。rpmiforce{newreleases〔〕。rpm}rpmenodepsoldreleasermf{reposdir}switchtooraclelinux。repoDisableUEKreposifUEKkernelisnotbeinginstalledif!{installuekkernel};thenechoDisablingUEKrepositoriessincewearenotinstallingtheUEKkernelyumconfigmanagerdisableUEKfiAtthispoint,theswitchiscompleted。trapERRWhenanadditionalenabledCentOSrepositoryhasamatchwithOracleLinuxthenautomaticallyenabletheOLrepositorytoensuretheRPMismaintainedCreateanassociatearraywherethekeyistheCentOSreponameandthevaluecontainsthemethodofgettingthecontent(EnablearepoorinstallanRPM)andthedetailsoftherepoorRPMcaseosversionin6)declareArepositories(〔basedebuginfo〕REPOhttps:oss。oracle。comol6debuginfo〔updates〕REPOol6latest);;7)declareArepositories(〔basedebuginfo〕REPOhttps:oss。oracle。comol7debuginfo〔updates〕REPOol7latest,ol7optionallatest〔centoscephjewel〕RPMoraclecephreleaseel7〔centosgluster41〕RPMoracleglusterreleaseel7〔centosgluster5〕RPMoracleglusterreleaseel7〔centosgluster46〕RPMoracleglusterreleaseel7〔centosnfsganesha30〕RPMoracleglusterreleaseel7〔centosovirt42〕RPMoracleovirtreleaseel7〔centosovirt43〕RPMoracleovirtreleaseel7〔centossclosclo〕RPMoraclesoftwarecollectionreleaseel7〔centossclorh〕RPMoraclesoftwarecollectionreleaseel7);;8)declareArepositories(〔AppStream〕REPOol8appstream〔appstream〕REPOol8appstream〔BaseOS〕REPOol8baseoslatest〔baseos〕REPOol8baseoslatest〔HighAvailability〕REPOol8addons〔ha〕REPOol8addons〔PowerTools〕REPOol8codereadybuilder〔powertools〕REPOol8codereadybuilder〔centosreleasenfsganesha28〕RPMoracleglusterreleaseel8〔centosgluster6test〕RPMoracleglusterreleaseel8〔centosgluster7〕RPMoracleglusterreleaseel8〔centosgluster8〕RPMoracleglusterreleaseel8);;esacForeachentryinthelist,enableitforreponamein{enabledrepos};doaction〔0〕willbeREPOorRPMaction〔1〕willbethereposdetailsortheRPMsnameIFSreadraaction{repositories〔{reponame}〕}if〔〔n{action〔0〕}〕〕;thenif〔{action〔0〕}REPO〕;thenmatchingrepo{action〔1〕}echoEnabling{matchingrepo}whichreplaces{reponame}AnRPMthatdescribesdebuginforepositorydoesnotexistchecktoseeiftherepoidstartswithhttps,ifitdoesthencreateanewrepopointingtotherepositoryif〔〔{matchingrepo}https。〕〕;thenyumconfigmanageraddrepo{matchingrepo}elseyumconfigmanagerenable{matchingrepo}fielif〔{action〔0〕}RPM〕;thenmatchingrpm{action〔1〕}echoInstalling{matchingrpm}togetcontentthatreplaces{reponame}yumassumeyesdisablerepoenablerepoollatestinstall{matchingrpm}fifidoneechoInstallingbasepackagesforOracleLinux。。。if!yumshellyEOFremove{badpackages〔〕}install{basepackages〔〕}runEOFthenexitmessageCouldnotinstallbasepackages。Runyumdistrosynctomanuallyinstallthem。fiif〔xusrlibexecplymouthplymouthupdateinitrd〕;thenechoUpdatinginitrd。。。usrlibexecplymouthplymouthupdateinitrdfiechoSwitchsuccessful。SyncingwithOracleLinuxrepositories。if!thenexitmessageCouldnotautomaticallysyncwithOracleLinuxrepositories。Checktheoutputofyumdistrosynctomanuallyresolvetheissue。fiCentOSspecificreplacementscaseosversionin7)Priortoswitchthisisadependancyoftheyumrpm,;8)Thereareafewdnfmodulesthatarenamedafterthedistributionforeachsteamnamedrhelorrhel8performamoduleresetandenableif〔〔{modulesenabled〔〕}〕〕;thenformodulein{modulesenabled〔〕};dodnfmoduleresety{module}case{module}incontainertoolsgotoolsetjmcllvmtoolsetrusttoolset)dnfmoduleenabley{module}:ol8;;virt)dnfmoduleenabley{module}:;)echoUnsurehowtotransformmodule{module};;esacdonednfassumeyesdisablerepoenablerepool8appstreamupdatefiTwologoRPMsarentcurrentlycoveredbyreplacesmetadata,replacebyhand。;esacif{reinstallallrpms};thenechoTestingforremainingCentOSRPMsIfCentOSandOracleLinuxhaveidenticallyversionedRPMsthenthoseRPMsareleftunchanged。Thisshouldhavenotechnicalimpactbutforcompleteness,reinstalltheseRPMssothereisnoaccidentalcrosspollination。casearchinx8664)mapfiletlistofcentosrpms(rpmqaqf{NAME}{VERSION}{RELEASE}{VENDOR}grepCentOSawk{print1});;aarch64)mapfiletlistofcentosrpms(rpmqaqf{NAME}{VERSION}{RELEASE}{VENDOR}grepCentOSgrepvkernelawk{print1});;esacif〔〔n{listofcentosrpms〔〕}〕〕〔〔{listofcentosrpms〔〕}ne0〕〕;thenechoReinstallingRPMs:{listofcentosrpms〔〕}yumassumeyesdisablerepoenablerepoolreinstall{listofcentosrpms〔〕}fiSeeifnonOracleRPMsarepresentandprintthemmapfiletnonoraclerpms(rpmqaqf{NAME}{VERSION}{RELEASE}{VENDOR}{PACKAGER}grepvOracle)if〔〔n{nonoraclerpms〔〕}〕〕;thenechoThefollowingnonOracleRPMsareinstalledonthesystem:printfs{nonoraclerpms〔〕}echoThismaybeexpectedofyourenvironmentanddoesnotnecessarilyindicateaproblem。echoIfalargenumberofCentOSRPMsareincludedandyoureunsurewhypleaseopenanissueon{githuburl}fifiechoSyncsuccessful。if〔archaarch64〕;thenechoHostisrunninganArmCPU:removingRHCK。echoImportant:youMUSTrebootthisinstanceassoonaspossible。dnfconfigmanagersetoptprotectrunningkernel0savednfyremovekernelkernelcorekernelmodulesdnfconfigmanagersetoptprotectrunningkernel1saveficaseosversionin78)echoUpdatingtheGRUB2bootloader。if〔dsysfirmwareefi〕;thengrub2mkconfigobootefiEFIredhatgrub。cfgelsegrub2mkconfigobootgrub2grub。;esacif{installuekkernel};thenechoSwitchingdefaultbootkerneltotheUEK。uekpath(findbootnamevmlinuz。el{osversion}uek。{arch})grubbysetdefault{uekpath}fiechoRemovingyumcachermrfvarcache{yum,dnf}CollectinformationaboutRPMsaftertheswitchif{verifyallrpms};thengeneraterpmsinfoafterechoReviewtheoutputoffollowingfiles:findvartmptypefname(hostname)rpms。logfiechoSwitchcomplete。casearchinx8664)echoOraclerecommendsrebootingthissystem。;;aarch64)echoThisinstancemustberebootedassoonaspossible。;;esac小结 后面会分享更多Linux和DBA方面内容,感兴趣的朋友可以关注下!