
- 最新版本
- CentOS 8.1.1911
- 类 型
- 操作系统;Linux的一种;基于RHEL
- 发布日期
- 2020年01月13日
- 中文名
- 社区企业操作系统
- 价 格
- 免费
- 外文名
- CentOS
-
2022-04-08 15:44:36
Oh My CentOS Stream 9
获取文章中提到的脚本,请访问文章原文https://ohmycs9.smlk.org/
CentOS 8 / CentOS Stream 8 升级 CentOS Stream 9 简明教程
中文 | English(WIP)
哦,我的老伙计!你知道吗?
CentOS 8
在2021年12月31日完蛋啦!🎉🎉🎉
还在用CentOS 8
吗?为什么不换成CentOS Stream 8
、Rocky Linux 8
或者AlmaLinux
呢?等等!
CentOS Stream 9
已经发布了?官方源里面居然还有Nodejs16
和Golang1.17.5
?还有kernel5.14
和glic 2.34
?如果你追求新功能和
dnf
包管理器,CentOS Stream 9
可能是你第二好的选择!(第一依旧是Fedora
)可是我的VPS服务商不提供
CentOS Stream 9
的镜像,甚至也不提供CentOS Stream 8
的镜像,我只能用过时的CentOS 8
的镜像,这岂不是很糟糕?别担心,通过这篇文章提供的方法,您也能在
CentOS 8
上升级到CentOS Stream 9
,保留所有数据,并且不用重装系统!食用指南
Warning:升级大版本有可能会导致软件甚至系统无法正常运行,请谨慎操作!
Tips: 开始操作前请您阅读全文。遇到问题您可以开issue
,提交更好的解决方案请提交pull request
。准备工作
使用您熟悉的备份工具备份您的数据,如果您的服务商支持快照功能,强烈建议您创建快照后再进行操作。
从
CentOS 8
升级到CentOS Stream 8
CentOS 8
生命周期已结束,您可以通过以下方法升级到CentOS Stream 8
:切换到
vault
源,这里使用清华源做演示,您可以更换为其他源。minorver=8.5.2111 sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \ -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$minorver|g" \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo
更新
CentOS Stream 8
sudo dnf install \ http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages/centos-stream-repos-8-4.el8.noarch.rpm \ http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages/centos-stream-release-8.6-1.el8.noarch.rpm \ http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages/centos-gpg-keys-8-4.el8.noarch.rpm \ -y sudo dnf distro-sync --allowerasing -y
从
CentOS Stream 8
升级到CentOS Stream 9
1. 准备RPMs
echo "Preparing to download RPMs" echo "Setting up wget..." sudo dnf install wget -y echo "Creating directory ~/cs8to9/el9" mkdir -p ~/cs8to9/el9 echo "Creating directory ~/cs8to9/epel9" mkdir -p ~/cs8to9/epel9 echo "Downloading RPMs..." cd ~/cs8to9/epel9 wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm wget https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-9.noarch.rpm cd ~/cs8to9/el9 wget http://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/Packages/centos-stream-release-9.0-9.el9.noarch.rpm wget http://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/Packages/centos-stream-repos-9.0-9.el9.noarch.rpm wget http://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/Packages/centos-gpg-keys-9.0-9.el9.noarch.rpm cd
你可以在
scripts
目录下找到cs9rpmdownload.sh
,运行它,它会执行上述指令,自动下载所有的RPMs。2. 移除非必要RPM包和旧内核
echo "Removing old packages..." sudo dnf autoremove -y echo "Removing old kernels..." echo "The following packages will be removed:" rpm -q kernel && rpm -q kernel-devel && rpm -q kernel-core && rpm -q kernel-modules read -p "Are you sure(y/N)? " -n 1 -r if [[ $REPLY =~ ^[Yy]$ ]] then echo "yes" sudo rpm -e `rpm -q kernel` `rpm -q kernel-devel` `rpm -q kernel-core` `rpm -q kernel-modules` --nodeps fi
你可以在
scripts
目录下找到removekernel.sh
,运行它,它会执行上述指令,自动移除非必要RPM包和旧内核。3. 升级
CentOS Stream 9
echo "Installing CentOS Stream 9 RPMs..." cd ~/cs8to9/el9 sudo dnf install centos-stream-release-9.0-9.el9.noarch.rpm centos-stream-repos-9.0-9.el9.noarch.rpm centos-gpg-keys-9.0-9.el9.noarch.rpm -y echo "Installing EPEL 9 RPMs..." cd ~/cs8to9/epel9 sudo dnf install epel-release-latest-9.noarch.rpm epel-next-release-latest-9.noarch.rpm -y echo "Upgrade to CentOS Stream 9..." sudo dnf distro-sync --allowerasing -y echo "cat /etc/redhat-release" cat /etc/redhat-release
你可以在
scripts
目录下找到cs8to9.sh
,运行它,它会执行上述指令,自动升级CentOS Stream 9
。4. 安装新内核
echo "Rebuilding rpm database..." sudo rpm --rebuilddb echo "Reset dnf module cache..." mkdir -p ~/cs8to9/empty && cd ~/cs8to9/empty sudo dnf module reset * -y echo "Installing new kernel..." sudo dnf install kernel kernel-core kernel-devel kernel-modules -y sudo dnf groupupdate "Core" "Minimal Install" -y
你可以在
scripts
目录下找到installkernel.sh
,运行它,它会执行上述指令,自动安装新内核。5. 重启系统
检查内核是否安装成功,如果安装成功,请重启系统。
dnf list --installed | grep -i "kernel" sudo reboot
重启后,检查内核版本
uname -a
内核版本为应为
5.14
5. 重建rescue镜像
echo "Rebuilding rescue image..." sudo dnf reinstall dracut -y mkdir -p ~/cs8to9/backup sudo mv /boot/vmlinuz-0-rescue-* ~/cs8to9/backup sudo mv /boot/initramfs-0-rescue-*.img ~/cs8to9/backup sudo /usr/lib/kernel/install.d/51-dracut-rescue.install add $(uname -r) "" /lib/modules/$(uname -r)/vmlinuz
你可以在
scripts
目录下找到rebuildrescue.sh
,运行它,它会执行上述指令,自动重建rescue镜像。6. (可选)重新安装所有RPM包
cd ~/cs8to9/empty sudo dnf reinstall -y *
享受你的新系统!
License
OhMyStream9 由 Ink33 采用 知识共享 署名-相同方式共享 4.0 国际 许可协议进行许可。OhMyStream9 by Ink33 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
更多相关内容 -
centos 7.6版本 ISO镜像下载
2020-12-03 17:08:21关于centos7.6版本的镜像文件,适用于练习docker、k8s等容器技术。 亲和性较好,本资源是网盘下载,非网盘会员慎点。 -
CentOS 7.5 ISO文件百度网盘下载地址
2018-10-08 11:28:24CentOS 7.5 ISO文件,text文件中为永久有效分享的百度网盘下载链接地址,若是由于某些原因导致失效,还烦请私信 -
Centos 6.9 64位镜像文件
2018-06-06 14:16:24Centos 6.9版本64位镜像文件,虚拟机装机必备,方便好用,亲测文件真实可用! -
CentOS-7-x86_64-DVD-1611 ISO镜像
2018-02-02 11:08:46CentOS-7-x86_64-DVD-1611 ISO镜像,附件为百度云链接 -
CentOS6.8-64位系统-百度云盘链接
2017-05-19 16:39:41CentOS6.8-64-百度云盘链接 -
linux之Centos6升级至centos7
2021-03-24 14:19:20centos官方于2020年12月2号停止了所有centos6更新维护,为了继续享受更新服务,redhat提供了一个redhat-upgrade-tool的升级工具,支持将centos6升级到centos7。centos8停止维护更新时间2021年12月31号,centos7...一、需求说明
centos官方于2020年12月2号停止了所有centos6更新维护,为了继续享受更新服务,redhat提供了一个redhat-upgrade-tool的升级工具,支持将centos6升级到centos7。centos8停止维护更新时间2021年12月31号,centos7停止更新维护时间为2024年6月30号。centos停止更新后取而代之的是CentOS Stream。
示例环境说明:- 升级前版本:centos6.5
- 升级后版本:centos7.0
二、升级步骤
0、查看操作系统版本
[root@localhost ~]# cat /etc/centos-release
CentOS release 6.5 (Final)1、更换YUM源
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://files.tttidc.com/centos6/Centos-6.repo
2、安装升级软件工具
官方下载地址,一般网络从官方下载速度实在是慢得无法忍受。
下载地址一:官网下载地址
下载地址二:>CSDN下载地址
下载rpm包后上传到服务器解压后安装
[root@localhost opt]# yum localinstall preupgrade-assistant-* -y
[root@localhost opt]# yum localinstall redhat-upgrade-tool* -y3、检测系统可否升级
[root@localhost opt]# preupg -l
CentOS6_74、运行模拟升级工具
[root@localhost opt]# preupg -s CentOS6_7
Preupg tool doesn’t do the actual upgrade.
Please ensure you have backed up your system and/or data in the event of a failed upgrade
that would require a full re-install of the system from installation media.
Do you want to continue? y/n
y #此处输入y
Gathering logs used by preupgrade assistant:
All installed packages : 01/11 …finished (time 00:00s)
All changed files : 02/11 …finished (time 02:44s)
Changed config files : 03/11 …finished (time 00:00s)
All users : 04/11 …finished (time 00:00s)
All groups : 05/11 …finished (time 00:00s)
Service statuses : 06/11 …finished (time 00:00s)
All installed files : 07/11 …finished (time 00:02s)
…
Tarball with results is stored here /root/preupgrade-results/preupg_results-210324171443.tar.gz .
The latest assessment is stored in directory /root/preupgrade .
Summary information:
We found some critical issues. In-place upgrade is not advised.
Read the file /root/preupgrade/result.html for more details.
Upload results to UI by command:
e.g. preupg -u http://127.0.0.1:8099/submit/ -r /root/preupgrade-results/preupg_results-*.tar.gz .5、根据模拟升级的检测结果进行确认和评估
[root@localhost ~]# preupg --riskcheck --verbose
…
INPLACERISK: MEDIUM: We detected some packages installed on the system were removed (obsoleted) between CentOS 6 and CentOS 7. This may break the functionality of the packages depending on them.
INPLACERISK: MEDIUM: We detected some packages installed on the system were removed between CentOS 6 and CentOS 7. This may break the functionality of the packages depending on them.
INPLACERISK: MEDIUM: Package ql2200-firmware not provided by its replacement linux-firmware. In-place upgrade might not work properly, will be finished by postupgrade script!
INPLACERISK: MEDIUM: Package libudev not provided by its replacement systemd-libs. In-place upgrade might not work properly, will be finished by postupgrade script!
INPLACERISK: MEDIUM: Package coreutils-libs not provided by its replacement coreutils. In-place upgrade might not work properly, will be finished by postupgrade script!
INPLACERISK: MEDIUM: Package ql2500-firmware not provided by its replacement linux-firmware. In-place upgrade might not work properly, will be finished by postupgrade script!
INPLACERISK: MEDIUM: Package ql2100-firmware not provided by its replacement linux-firmware. In-place upgrade might not work properly, will be finished by postupgrade script!
INPLACERISK: MEDIUM: Package rt61pci-firmware not provided by its replacement linux-firmware. In-place upgrade might not work properly, will be finished by postupgrade script!
INPLACERISK: MEDIUM: Package ql23xx-firmware not provided by its replacement linux-firmware. In-place upgrade might not work properly, will be finished by postupgrade script!
INPLACERISK: MEDIUM: Package bfa-firmware not provided by its replacement linux-firmware. In-place upgrade might not work properly, will be finished by postupgrade script!
INPLACERISK: MEDIUM: Package ql2400-firmware not provided by its replacement linux-firmware. In-place upgrade might not work properly, will be finished by postupgrade script!
INPLACERISK: MEDIUM: Package rt73usb-firmware not provided by its replacement linux-firmware. In-place upgrade might not work properly, will be finished by postupgrade script!
INPLACERISK: MEDIUM: Package sane-backends-libs-gphoto2 not provided by its replacement sane-backends-drivers-cameras. In-place upgrade might not work properly, will be finished by postupgrade script!
INPLACERISK: MEDIUM: having one of [openscap tzdata redhat-menus kpartx mesa-libGLU] package installed breaks upgrade
INPLACERISK: MEDIUM: We detected some soname bumps in the libraries installed on the system. This may break the functionality of some of your 3rd party applications. They may need rebuild. Please check their requirements.
INPLACERISK: MEDIUM: We detected some .so libraries installed on the system were removed between CentOS 6 and CentOS 7. This may break the functionality of some of your 3rd party applications.
INPLACERISK: SLIGHT: We detected some files where modifications are not tracked in the rpms. You may need to check their functionality after successful upgrade.
INPLACERISK: SLIGHT: We detected some files untracked by rpms. Some of these may need manual check/migration after redhat-upgrade-tool and/or can cause conflicts or troubles during the installation. Try to reduce unnecessary untracked files before running redhat-upgrade-tool.
INPLACERISK: SLIGHT: We detected some packages installed on the system changed their name between CentOS 6 and CentOS 7. Altho h they should be compatible, monitoring after the update is recommended.
INPLACERISK: SLIGHT: export shell commands will be deleted from /etc/sysconfig/sshd
INPLACERISK: SLIGHT: Some binaries untracked by RPM were discovered on the system and may need rebuild after upgrade.
INPLACERISK: SLIGHT: Some scripts untracked by RPM were discovered on the system and may not work properly after upgrade.
INPLACERISK: SLIGHT: /usr/lib64/python2.6/site-packages/gtk-2.0 is owned by an RPM package that was not signed by CentOS.
INPLACERISK: SLIGHT: /usr/lib64/python2.6/site-packages/report is not owned by any RPM package.
INPLACERISK: SLIGHT: /usr/lib64/python2.6/site-packages/reportclient is not owned by any RPM package.检测评估结果提示风险项,我这是初始化的centos6.5操作系统,风险提示内容都有不少。存在EXTREME错误则无法进行下一步升级操作。
7、安装升级用的centos7 rpm key
[root@localhost ~]# rpm --import http://vault.centos.org/centos/7.0.1406/os/x86_64/RPM-GPG-KEY-CentOS-7
[root@localhost ~]# centos-upgrade-tool-cli --network 7 --instrepo=http://vault.centos.org/centos/7.0.1406/os/x86_64/
setting up repos…
base | 3.7 kB 00:00
base/primary_db | 4.7 MB 00:018、运行升级工具
只支持6.5及以上系统升级到不高于7.2系统;
[root@localhost ~]# centos-upgrade-tool-cli --network 7 --instrepo=http://vault.centos.org/centos/7.0.1406/os/x86_64/
setting up repos…
upgradedevice | 3.6 kB 00:00 …
upgradedevice/primary_db | 2.7 MB 00:00 …
Preupgrade assistant risk check found risks for this upgrade.
You can run preupg --riskcheck --verbose to view these risks.
Addressing high risk issues is required before the in-place upgrade
and ignoring these risks may result in a broken upgrade and unsupported upgrade.
Please backup your data.
…
Continue with the upgrade [Y/N]? y
…
rpm install 100% [============================================================================================]
setting up system for upgrade
Finished. Reboot to start upgrade.-
2)、从本地源进行更新
- 下载centos7.0.1406镜像iso文件
[root@localhost home]# wget https://vault.centos.org/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
- 挂载镜像
[root@localhost home]# mout -o -loop -t iso9660 /home/CentOS-7.0-1406-x86_64-DVD.iso /mnt/cdrom
- 执行更新
[root@localhost home]# centos-upgrade-tool-cli --device=/dev/cdrom
9、重启操作系统
[root@localhost home]# reboot
10、查验系统版本
[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.0.1406 (Core)三、FAQ
1、安装redhat-upgrade-tool时报错File contains no section headers.
- 报错信息:
- 问题原因:
repo配置文件错误,缺少配置头信息 - 解决方案:
-将缺少的yum头信息添加上 [centos6-upgrade]
[root@localhost yum.repos.d]# cat upgradtool.repo.bak
[centos6-upgrade]
name=CentOS-$releasever - Upgrade Tool
baseurl=http://dev.centos.org/centos/6/upg/x86_64/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-62、安装redhat-upgrade-tool时报错Couldn’t resolve host ‘dev.centos.org’
-
报错信息:
-
问题原因:
centos官网已经停止centos6相关服务,网站dev.centos.org已经停止服务。 -
解决方案:
按照博文步骤,手动安装redhat-upgrade-tool等rpm包。
3、模拟升级时报错
-
报错信息:
-
问题原因:
openscap版本太高,需要降级 -
解决方案:
卸载当前安装的openscap版本,下载并安装openscap-1.0.8-1.0.1.el6.centos.x86_64.rpm
[root@localhost opt]# rpm -qa |grep openscap
openscap-1.2.13-2.el6.x86_64
[root@localhost opt]# rpm -e --nodeps openscap-1.2.13-2.el6.x86_64
[root@localhost opt]# yum localinstall openscap-1.0.8-1.0.1.el6.centos.x86_64.rpm -y4、模拟升级的检测结果存在关于X11的EXTREME问题
-
报错信息:
-
问题原因:
centos7对X11桌面环境进行了重新设计 -
解决方案:
因centos6作为服务器,当前安装软件没有桌面要求,选择卸载X11桌面环境。
#yum groupremove -y “Desktop” “X Window System”
5、模拟升级的检测结果存在关于pcnet32的EXTREME问题
- 报错信息:
INPLACERISK: EXTREME: The kernel driver ‘pcnet32’ required to service hardware present in your system is not available in CentOS 7. This suggests that your system contains hardware that is not supported in CentOS 7 release. - 问题原因:
vmware 提供的默认网卡类型是pcnet32,el7默认没有提供pcnet32的网卡驱动。 - 解决方案:
在vmware指定的虚拟机存储位置找到.vmx的文件,
ethernet0.virtualDev = “pcnet32” 或是别的。将其修改为:
ethernet0.virtualDev = “e1000”’ (如果没有添加)
四、写着最后
centos6升级centos7跨越大版本,可能的报错实在是太多,成功的几率也不高,花费的时间成本远远大于新装机centos7的成本。实际中建议新搭建centos7环境测试部署的应用是否兼容,测试通过直接通过新装系统重新部署应用的方式升级。本人仅供学习参考,无法保证升级成功。
-
MacBook M1芯片 安装Centos8 教程(无界面安装)
2021-12-02 02:16:05M1 安装Centos8 教程MacBook Pro M1芯片 安装Centos8 教程(无界面安装)Centos8 支持M1芯片下载地址0、Linux关机命令1、安装截图2、安装完成重启后提示如下警告⚠️:解决办法:其他两项,创建用户 和 网络配置 ,...M1 安装Centos8 教程
MacBook Pro M1芯片 安装Centos8 教程(无界面安装)
Centos8 支持M1芯片下载地址
链接: https://pan.baidu.com/s/17TF3Ah3fXqf8SZshVJMvFg 提取码:
0d8v
0、Linux关机命令
CentOS使用halt关机出现system halting卡死
使用如下命令解决方法:使用 halt -p 正常关机不会出现 system halting 使用 shutdown -h now 正常关机不会出现 system halting 使用 systemctl poweroff 正常关机不会出现 system halting
1、安装截图
安装环境:2021款M1MacBookPro,macOS Monterey 12系统 Apple M1芯片 安装时间:2021年12月02日
-
选择安装
-
第一次输入
r
,刷新配置,可以看到有几个带感叹号⚠️的警告,接下来就一一设置
-
磁盘选择设置
,先选数字5
再按提示c c c
,完成磁盘的选择,如下图:
-
设置root密码,先选数字
8
再按提示6688...
,完成密码设置,如下图:
-
输入
b
后可以看到已经开始安装了,等着就好…
-
安装完成!
2、安装完成重启后提示如下警告⚠️:
解决办法:
若出现license information(license not accepted),即说明需要同意许可信息, 输入1-回车-2-回车-c-回车-c回车,即可解决。
其他两项,创建用户 和 网络配置 ,可以后面操作,无关紧要
上面选择
q
退出,yes
确认后进入登录界面,输入用户:root、密码:6688…(密码是在安装过程已经设置好的)3、配置网络(由于在安装过程中没有配置网络,默认是关闭)
3.1 编辑网络配置文件
cd /etc/sysconfig/network-scripts/ ls
- 如下图,
ifcfg-
开头的就是我们要编辑的配置文件,每个人的文件名可能不同
- 修改
ONBOOT=yes
#开机自启
TYPE=Ethernet #网卡类型 PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=dhcp #动态获取 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no NAME=enp0s5 UUID=cd9c7deb-5cf8-4474-abf2-b06cf1bafc07 DEVICE=enp0s5 #设备名 ONBOOT=yes
- 保存退出后,重启网络或者重启CentOS 命令:
shutdown -h now
:
systemctl restart network.service
- 查询IP地址
ip addr
,可以看到我们已经成功了
- 进一步验证网络,测试百度
curl www.baidu.com
, 测试通过!
3.2 配置静态IP,并能够通过 SSH 连接
选择共享网络–再点开配置–网络–高级设置–打开网络首选项
- 修改配置文件:
vi /etc/sysconfig/network-scripts/ifcfg-enp0s5
- 这一步和上面一样,注意
ifcfg-
开头的文件可能名字不同
# 修改为静态IP dhcp为动态ip none为无 BOOTPROTO=static # IP地址 IPADDR=10.211.55.3 # 网关 GATEWAY=10.211.55.1 # 子网掩码 NETMASK=255.255.255.0 # 从no改成yes。系统将在启动时自动开启该接口 ONBOOT=yes # DNS服务器1、2 DNS1=10.211.55.1 DNS2=8.8.8.8
- 修改完后重启网络
systemctl restart network
或service network restart
- 显示
OK
表示成功,如果重启失败,如下图报错,可以尝试重启虚拟机reboot
再尝试ping一下电脑ip - 关于这个报错具体解决办法可以参考:https://www.codeleading.com/article/34552269276/
- 这里简单说下我的解决办法:
- centos8 不能重启网络报错原因
Failed to restart network.service: Unit network.service not found
- 由于 centos8 已经替换了原来的
network
, 新版的叫:NetworkManager
- 所以用这个命令就可以重启了
systemctl restart NetworkManager
- 重启后查询运行状态:
systemctl status NetworkManager
● NetworkManager.service - Network Manager Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2021-12-01 10:24:49 EST; 30s ago Docs: man:NetworkManager(8) Main PID: 1585 (NetworkManager) Tasks: 3 (limit: 8530) Memory: 3.0M CGroup: /system.slice/NetworkManager.service └─1585 /usr/sbin/NetworkManager --no-daemon Dec 01 10:24:49 localdomain NetworkManager[1585]: <info> [1638372289.0732] device (enp0s5): state change: config -> ip-config (reason 'none', sys-iface-state: 'assume') Dec 01 10:24:49 localdomain NetworkManager[1585]: <info> [1638372289.0735] device (enp0s5): state change: ip-config -> ip-check (reason 'none', sys-iface-state: 'assume') Dec 01 10:24:49 localdomain NetworkManager[1585]: <info> [1638372289.0754] device (enp0s5): state change: ip-check -> secondaries (reason 'none', sys-iface-state: 'assume') Dec 01 10:24:49 localdomain NetworkManager[1585]: <info> [1638372289.0755] device (enp0s5): state change: secondaries -> activated (reason 'none', sys-iface-state: 'assume') Dec 01 10:24:49 localdomain NetworkManager[1585]: <info> [1638372289.0756] manager: NetworkManager state is now CONNECTED_LOCAL Dec 01 10:24:49 localdomain NetworkManager[1585]: <info> [1638372289.0758] manager: NetworkManager state is now CONNECTED_SITE Dec 01 10:24:49 localdomain NetworkManager[1585]: <info> [1638372289.0759] policy: set 'enp0s5' (enp0s5) as default for IPv4 routing and DNS Dec 01 10:24:49 localdomain NetworkManager[1585]: <info> [1638372289.0774] device (enp0s5): Activation: successful, device activated. Dec 01 10:24:49 localdomain NetworkManager[1585]: <info> [1638372289.0776] manager: NetworkManager state is now CONNECTED_GLOBAL Dec 01 10:24:49 localdomain NetworkManager[1585]: <info> [1638372289.0777] manager: startup complete
ping 10.211.55.3
- 成功效果图:
ssh root@10.211.55.3
4、关闭防火墙
查看防火墙状态:
firewall-cmd --state
或systemctl status firewalld.service
关闭:
systemctl stop firewalld.service
永久关闭:
systemctl disable firewalld.service
永久关闭效果图
5、在M1芯片的MacBook上centos8安装
Parallels Tools
- 首先配置网络,后面需要用到
- Parallels安装好CentOS,需要共享Mac文件夹同样需要安装Parallels Tools。
跟Windows不同的,CentOS不会自动弹出安装界面,需要你手动安装。
5.1、加载
Parallels Tools
安装文件5.2、回到虚拟机里,执行挂载光盘:
[root@localdomain ~]# mount /dev/cdrom /mnt mount: /mnt: WARNING: device write-protected, mounted read-only. [root@localdomain ~]# df -h /mnt/ Filesystem Size Used Avail Use% Mounted on /dev/sr0 60M 60M 0 100% /mnt [root@localdomain ~]# cp -ra /mnt /opt/ [root@localdomain ~]# umount /mnt [root@localdomain ~]#
5.3、选择光盘
修改源文件
一般我都是保留必须的,其它的先弄其它地方放着[root@localdomain ~]# mv /etc/yum.repos.d/CentOS-* /opt/ [root@localdomain ~]# mv /opt/CentOS-Linux-Media.repo /etc/yum.repos.d/ [root@localdomain ~]# mkdir /media/CentOS/ -p [root@localdomain ~]# mount /dev/cdrom /media/CentOS/ mount: /media/CentOS: WARNING: device write-protected, mounted read-only. [root@localdomain ~]# df -h|grep /media/CentOS /dev/sr0 6.8G 6.8G 0 100% /media/CentOS
上面的注意检查下,是这个
6.8G
的,之前的那个tool的要umount掉,然后再操作上面的iso加载,不行就多操作或者重启机器了修改
vim /etc/yum.repos.d/CentOS-Linux-Media.repo
文件如下,centos7的是一个,注意这里centos8已经拆分成两个了CentOS-Linux-Media.repo
原始文件如下# CentOS-Linux-Media.repo # # You can use this repo to install items directly off the installation media. # Verify your mount point matches one of the below file:// paths. [media-baseos] name=CentOS Linux $releasever - Media - BaseOS baseurl=file:///media/CentOS/BaseOS file:///media/cdrom/BaseOS file:///media/cdrecorder/BaseOS gpgcheck=0 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial [media-appstream] name=CentOS Linux $releasever - Media - AppStream baseurl=file:///media/CentOS/AppStream file:///media/cdrom/AppStream file:///media/cdrecorder/AppStream gpgcheck=0 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- 添加epel源
这个是因为dkms的包是在epel里面的,而tool是需要这个dkms的包的,所以添加源
而gcc的默认的版本已经足够高了,不需要之前centos7的那些处理
修改后整个文件/etc/yum.repos.d/CentOS-Media.repo内容如下:
# CentOS-Linux-Media.repo # # You can use this repo to install items directly off the installation media. # Verify your mount point matches one of the below file:// paths. [media-baseos] name=CentOS Linux $releasever - Media - BaseOS baseurl=file:///media/CentOS/BaseOS # file:///media/cdrom/BaseOS # file:///media/cdrecorder/BaseOS gpgcheck=0 enabled=1 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial [media-appstream] name=CentOS Linux $releasever - Media - AppStream baseurl=file:///media/CentOS/AppStream # file:///media/cdrom/AppStream # file:///media/cdrecorder/AppStream gpgcheck=0 enabled=1 # gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial [epel] name=epel baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/8/Everything/aarch64/ gpgcheck=0 enabled=1
5.4、更新yum缓存
yum makecache
[root@localdomain ~]# yum makecache Failed to set locale, defaulting to C.UTF-8 CentOS Linux 8 - Media - BaseOS 317 MB/s | 1.5 MB 00:00 CentOS Linux 8 - Media - AppStream 561 MB/s | 6.0 MB 00:00 epel 7.2 MB/s | 11 MB 00:01 Metadata cache created.
5.5、开始安装
Parallels Tools
[root@localdomain ~]# cd /opt/mnt/ [root@localdomain mnt]# ll total 536 -r-xr-xr-x. 1 root root 1043 Nov 24 14:24 install -r-xr-xr-x. 1 root root 533104 Nov 24 14:25 install-gui dr-xr-xr-x. 3 root root 4096 Nov 24 14:25 installer dr-xr-xr-x. 2 root root 28 Nov 24 14:24 kmods dr-xr-xr-x. 4 root root 185 Nov 24 14:25 tools -r--r--r--. 1 root root 13 Nov 24 14:25 version [root@localdomain mnt]# ./install
说明一下,我这里是用iTerm连接的虚拟机,所以安装界面没有颜色
因为我上面IP
已经配置为静态,命令:ssh root@10.211.55.3
一路下一步,直到弹出成功的提示,然后重启机器!
-
检查是否真的安装好了,安装好了有共享文件夹功能,可以在linux里面直接访问Mac的文件
-
添加共享文件夹
- 查看共享文件夹的文件
- 可以看到上面我共享的目录直接就可以在虚拟机里面访问了,到这里全部就安装好了
[root@localdomain ~]# ls /media/psf/Downloads/
安装总结
- 主要的步骤
- 准备好iso的源,添加一个epel源即可
6、通过 yum 安装一些基本软件
- net-tools 提供dig, nslookup, ifconfig等,用于配置网络:
yum install net-tools
- 添加 wget 下载文件:
yum install wget
7、更换 yum 源
repo文件下载地址:
网易:http://mirrors.163.com/.help/…
阿里:http://mirrors.aliyun.com/- 备份:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
- 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
CentOS 8
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
- 清除文件 并 重建元数据缓存
yum clean all yum makecache
- 最后更新软件包
yum update -y
- 其他
非阿里云ECS用户会出现 Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’ 信息,不影响使用。用户也可自行修改相关配置: eg:
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
yum 源配置完成
相关链接:阿里云CentOS 镜像
yum makecache
出现报错
- 报错:
Errors during downloading metadata for repository 'media-baseos':
…
[root@localdomain ~]# yum makecache Failed to set locale, defaulting to C.UTF-8 CentOS-8 - Base - mirrors.aliyun.com 3.9 MB/s | 2.9 MB 00:00 CentOS-8 - Extras - mirrors.aliyun.com 38 kB/s | 10 kB 00:00 CentOS-8 - AppStream - mirrors.aliyun.com 1.2 MB/s | 6.9 MB 00:05 CentOS Linux 8 - Media - BaseOS 0.0 B/s | 0 B 00:00 Errors during downloading metadata for repository 'media-baseos': - Curl error (37): Couldn't read a file:// file for file:///media/CentOS/BaseOS/repodata/repomd.xml [Couldn't open file /media/CentOS/BaseOS/repodata/repomd.xml] Error: Failed to download metadata for repo 'media-baseos': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried [root@localdomain ~]#
- 解决方法
- 挂载镜像:
mount /dev/sr0 /media/CentOS/
- 重新生成缓存
yum makecache
[root@localdomain yum.repos.d]# mount /dev/sr0 /media/CentOS/ mount: /media/CentOS: WARNING: device write-protected, mounted read-only. [root@localdomain yum.repos.d]# yum clean all Failed to set locale, defaulting to C.UTF-8 Repository extras is listed more than once in the configuration 33 files removed [root@localdomain yum.repos.d]# yum makecache Failed to set locale, defaulting to C.UTF-8 Repository extras is listed more than once in the configuration CentOS-8 - Base - mirrors.aliyun.com 4.7 MB/s | 2.9 MB 00:00 CentOS-8 - Extras - mirrors.aliyun.com 33 kB/s | 10 kB 00:00 CentOS-8 - AppStream - mirrors.aliyun.com 7.6 MB/s | 6.9 MB 00:00 CentOS Linux 8 - AppStream 4.6 MB/s | 6.9 MB 00:01 CentOS Linux 8 - BaseOS 2.5 MB/s | 2.9 MB 00:01 CentOS Linux 8 - Media - BaseOS 279 MB/s | 1.5 MB 00:00 CentOS Linux 8 - Media - AppStream 487 MB/s | 6.0 MB 00:00 epel 7.5 MB/s | 11 MB 00:01 Metadata cache created. [root@localdomain yum.repos.d]#
8、创建一个普通用户并赋予 root 权限
用普通账号进行登录可以避免 root 用户进行错误操作,而且用普通用户登录就像给服务器建立了两道墙,必须先用普通用户登录再设置能用 root 账号登录,所以后面还要配置禁止 root 用户通过 SSH 登录。
- 创建普通用户
[root@localdomain ~]# useradd -d /usr/able -m able # 新增用户,其中 -d 和 -m 是为用户 able 产生一个主目录 /usr/able [root@localdomain ~]# passwd able # 为新增用户修改密码 Changing password for user able. New password: # 输入密码 BAD PASSWORD: The password fails the dictionary check - it does not contain enough DIFFERENT characters Retype new password: # 确认密码 passwd: all authentication tokens updated successfully. [root@localdomain ~]#
这个普通用户有时也需要使用 root 权限,所以讲他加入到sudoers 用户组,
允许其使用sudo临时调用 root 权限[root@localdomain etc]# echo 'able ALL=(ALL) ALL'>> /etc/sudoers [root@localdomain etc]# tail -1 /etc/sudoers able ALL=(ALL) ALL [root@localdomain etc]#
9、禁止 root 使用 ssh 登入
进入配置文件:
/etc/ssh/sshd_config
找到如下语句进行修改
PermitRootLogin yes
把它改成
PermitRootLogin no
重启 sshd
systemctl restart sshd.service
这样别人就要必须要获取普通用户账号密码,然后才能破解 root
最后喜欢的小伙伴,记得关注收藏哦!😏🍭😘
参考文章
参考文章1:在m1芯片的MacBook上安装centos7
参考文章2:在m1芯片的MacBook上centos7安装parallels tool
参考文章3:在m1芯片的MacBook上安装centos8
参考文章4:在m1芯片的MacBook上centos8安装parallels tool
参考文章5:CentOS 7 在 Parallels 中的安装及基本配置 -
-
centos 自动运行python脚本,centos配置 Python 定时任务
2022-02-21 16:14:09centos 实现自动运行 Python 脚本 正式配置前,先编写一段 Python 脚本,实现日志写入文件操作 import os import sys import logging current_path = os.getcwd() # 获取当前目录 logging.basicConfig(level=...centos 实现自动运行 Python 脚本
正式配置前,先编写一段 Python 脚本,实现日志写入文件操作
import os import sys import logging current_path = os.getcwd() # 获取当前目录 logging.basicConfig(level=logging.INFO, filename=current_path + '/new.log', filemode='a', format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s' ) logging.info("写入日志")
centos中测试定时任务
使用
crontab
进行定时任务的处理,如果没有安装可以自行百度进行设置。
在正式使用crontab
前,需要提前了解一下crond
,crond
和crontab
是密切相关了,crond
是linux
中用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows的计划任务类似,crontab
是一个编辑或者说是管理定时任务的工具。
简单理解就是 crond是一个服务,crontab是一个命令。与之相关的命令有
yum install crontabs systemctl enable crond (开机启动) systemctl start crond(启动 `crond` 服务) systemctl stop crond(停止服务) systemctl restart crond (重启服务) systemctl reload crond (重载配置文件) systemctl status crond (查看状态)
测试状态之后,展示为
active(running)
即表示成功。crontab文件
用户所建立的crontab文件中,每一行都代表一项任务,每行的每个字段代表一项设置,它的格式共分为六个字段,前五段是时间设定段,第六段是要执行的命令段,格式如下:minute hour day month week command
在正式开始前,可以使用
crontab -l
查看一下已经开启了哪些定时任务。crontab -l
其余
crontab
常见的命令如下:crontab -u
:设定某个用户的crond服务crontab -e
:编辑crontab文件(编辑定时任务)crontab -r
:删除crontab文件(删除定时任务)crontab -i
:删除crontab文件提醒用户(删除定时任务)
详细配置
上文已经提及了一个定时任务的6个字段,其取值分别为:minute hour day month week command
上述字段分别是:分,时,日,月,周,命令
-
第1列表示分钟1~59 每分钟用
*
或者*/1
表示; -
第2列表示小时1~23(0表示0点);
-
第3列表示日期1~31;
-
第4列表示月份1~12;
-
第5列标识号星期0~6(0表示星期天);
-
第6列要运行的命令;
-
*
:任意时间,可以代表00-23小时或者00-12每月或者00-59分,例如0 9 * * * cmd
表示每月每周每日的 9:00 都执行cmd任务; -
-
:表示区间,是一个范围,例如00 17-19 * * * cmd
,就是每天17, 18, 19点的整点执行命令; -
,
:是分割时段,例如30 1,3,5 * * * cmd
,就是每天凌晨1点30,3点30,5点30都执行命令; -
/n
:n
为数字,表示分割,每隔n
单位时间,可以看成除法,*/6 * * * * cmd
,每隔6分钟执行一次。
设置定时任务
crontab -e
:直接写入定时任务*/1 1-2 * * * root /usr/bin/python3 /var/test1.py */1 1-2 * * * root /usr/bin/python3 /var/test2.py
vim /etc/crontab
:文件形式添加任务SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 1 * * * * /usr/bin/python3 /usr/test/test.py
重新加载配置
service crond reload
重启cron
service crond restart
两种方法的区别
crontab -e
对应的是用户级,vim /etc/crontab
对应的系统级的。
crontab -e
与vim /etc/crontab
修改语法格式不一样,后者多一个user指定。查看文件的权限
ls /etc/crontab -lh
查看任务是否添加
crontab -l -u root
在 centos 查找文件
find / -name xxxx.conf # 在根目录查找 find /var -name xxxx.conf # 在 var 目录查找
记录时间
2022年度 Flag,写作的 564 / 1024 篇。
可以关注我,点赞我、评论我、收藏我啦。更多精彩
👇👇👇扫码加入【78技术人】~ Python 事业部👇👇👇 -
如何安装CentOS 8
2022-03-30 09:45:29继 RHEL 8 发布之后,CentOS 社区也发布了让人期待已久的 CentOS 8,并发布了两种模式: CentOS stream:滚动发布的 Linux 发行版,适用于需要频繁更新的开发者 CentOS:类似 RHEL 8 的稳定操作系统,系统管理员... -
CentOS 7下载地址(ISO文件)
2021-04-08 10:09:14CentOS安装文件有两类(32位和64位),每类下载对应有不同的版本,这些版本适合不同需求的用户。 CentOS 7官方下载地址:https://www.centos.org/download/ 在CentOS官方网站上,CentOS 7提供了三种ISO镜像文件的... -
Centos Linux 和 CentOS Stream比较
2022-01-17 15:55:12CentOS 计划产生两个变体:CentOS Linux 和 CentOS Stream。它们在很多方面都是相似的。这是它们与众不同的地方。 另请参阅:CentOS Stream FAQhttps://www.redhat.com/en/blog/faq-centos-stream-updates 生命... -
CentOS-7-x86_64-DVD-1503-01
2015-12-28 16:28:12CentOS-7-x86_64-DVD-1503-01 -
Centos 8 配置清华centos-vault源
2022-03-08 10:35:21Centos 8 配置清华centos-vault源 -
Centos 8升级至Centos 8 Stream教程
2022-04-18 00:55:15Centos 8升级至Centos 8 Stream教程,一直使用Centos 8.2,但近期在服务器上安装软件时,遇到错误:Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: No URLs in mirrorlist... -
CentOS7各个版本镜像下载地址
2021-08-04 19:55:05# CentOS7.6 下载地址 # CentOS-7-x86_64-DVD-1810.iso CentOS 7.6 DVD 版 4G http://mirrors.163.com/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso # CentOS-7-x86_64-Everything-1810.iso ... -
centos linux 和 centos stream 的区别
2021-10-06 20:51:27文章目录CentOS Linux 和 CentOS StreamStream 的区别项目终止日期(EOL)上游 vs 下游更新频率贡献方式测试 CentOS Linux 和 CentOS StreamStream 的区别 CentOS 项目有两个分支:CentOS Linux 和 CentOS Stream。... -
从CentOS 8到CentOS Stream,到底发生什么事了?
2021-09-26 07:18:50在Linux服务器操作系统领域,CentOS一直被认为是一个稳定安全并且可靠的发行版本。它是从RHEL源代码复刻,去除了RHEL有关的商标等一些内容构建出来的。 但是从CentOS被Red Hat收购以后,它的命运发生了转变。最新的... -
vm虚拟机安装CentOS8.2服务器系统
2022-03-11 16:35:17开发服务器应用,需要使用到CentOS8.2,安装到虚拟机上方便快捷! -
Centos6.X升级至Centos7.2升至Centos7.9详细步骤和踩过的坑(升级者必看~)
2021-06-24 10:12:59首先说一下升级,从centos6.X版本升级至centos7.2版本算是一个比较大的跨越性的升级,会考虑到的问题也比较多,一些内核兼容不兼容,会不会缺失什么必要文件导致不能启动,不能正常使用,这些原本的文件服务会不会... -
CentOS之——CentOS8 安装 Docker
2020-04-13 00:39:32官方参考地址:https://docs.docker.com/install/linux/docker-ce/centos/ 里面包含包下载地址:https://download.docker.com/linux/centos/7/x86_64/stable/Packages/ 安装依赖 sudo yum install -y yum-utils ... -
centos7部署
2022-04-05 22:32:251.下载CentOS 7.9 先下载centos7.9,进入http://mirrors.163.com/centos/7.9.2009/isos/x86_64/ 2.开始安装 一般选择标准安装 下载完后进入VMware选择创建新的虚拟机,选择自定义–>下一步 选择稍后安装操作... -
CentOS 迎来更新换代版本 CentOS Stream 9 附下载镜像OS地址
2022-02-15 11:28:38CentOS Stream 9 镜像下载地址 https://mirrors.centos.org/mirrorlist?path=/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-dvd1.iso&redirect=1&protocol=https -
从 CentOS 8 平滑升级至 CentOS Stream
2021-11-21 15:51:31前言 CentOS 8已被放弃,将在2021...[root@centos ~]# dnf swap centos-linux-repos centos-stream-repos [root@centos ~]# dnf distro-sync 参考文章:FAQ - CentOS Project shifts focus to CentOS Stream Q7: H -
Centos各个版本下载地址
2022-04-09 21:34:03CentOS7.6 下载地址 CentOS-7-x86_64-DVD-1810.iso CentOS 7.6 DVD 版 4G http://mirrors.163.com/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso CentOS-7-x86_64-Everything-1810.iso CentOS 7.6 ... -
CentOS8镜像源问题【解决镜像源已经弃用的问题】
2022-02-22 15:02:06CentOS8阿里新镜像源【旧的已经弃用】 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法... -
CentOS Linux和CentOS Stream 区别
2022-04-14 10:40:04CentOS Linux和CentOS Stream 区别 CentOS有两个主要版本,具体取决于您的需求,现在,有两种使用CentOS平台的方式,它们分别是CentOS Linux和CentOS Stream。 CentOSLinux是Red Hat提供的企业Linux(RHEL)源代码的... -
CentOS8 与 CentOS7 的区别
2021-01-09 13:04:44目录前言一、CentOS 介绍二、RHEL7 和 RHEL8 区别总结 前言 之前一直使用的是 CentOS 7 系统,后面公司使用了 CentOS 8 对于用习惯了 CentOS 7 的我突然在实际生产中接触到 8 的版本,确实是有点挑战性的,但对于... -
CentOS7详细安装教程--图文介绍超详细
2021-09-09 20:05:46本文超详细的将CentOS 7的安装过程做了详细的记录,从下载镜像文件到安装CentOS再到最后的配置,手把手教学,保证能够顺利的将CentOS安装好、配置好。 -
CentOS7与centOS8 选择
2021-02-25 09:13:17CentOS7与centOS8的抉择 目前国内各大云服务器的默认centos 系统版本还是7,vultr,centos只有8了 作为本地主机玩的服务器,还是试一下centos8 国外下载之前版本: 官网默认下载:...