作者:gc(at)sysin.org,主页:www.sysin.org
转载请保留出处。
初始版本:CentOS 8.0.1905
继 RHEL 8 发布之后,CentOS 社区也发布了让人期待已久的 CentOS 8,并发布了两种模式:
CentOS stream:滚动发布的 Linux 发行版,适用于需要频繁更新的开发者
CentOS:类似 RHEL 8 的稳定操作系统,系统管理员可以用其部署或配置服务和应用
CentOS 8 系列只有64位系统,没有32位。
1 2 3 4 5 6 CentOS-8 -x86_64-1905 -boot.iso 16 -Aug-2019 05 :22 534 M CentOS-8 -x86_64-1905 -boot.iso.manifest 16 -Aug-2019 05 :23 626 CentOS-8 -x86_64-1905 -boot.torrent 24 -Sep-2019 04 :51 21 K CentOS-8 -x86_64-1905 -dvd1.iso 16 -Aug-2019 05 :59 7 G CentOS-8 -x86_64-1905 -dvd1.iso.manifest 16 -Aug-2019 05 :59 401 K CentOS-8 -x86_64-1905 -dvd1.torrent 24 -Sep-2019 04 :52 266 K
这里使用 CentOS-8-x86_64-1905-boot.iso 进行安装,由于没有提供类似于 CentOS7 的 Minimal 版本,安装过程中选择 Minimal 安装,不过需要指定 repo 地址。
更新:CentOS 8.2.2004 终于增加了 minimal iso。
CentOS 8 的新特性
DNF 成为了默认的软件包管理器,同时 yum 仍然是可用的
使用网络管理器(nmcli
和 nmtui
)进行网络配置,移除了网络脚本
使用 Podman 进行容器管理
引入了两个新的包仓库:BaseOS 和 AppStream
使用 Cockpit 作为默认的系统管理工具
默认使用 Wayland 作为显示服务器
iptables
将被 nftables
取代
使用 Linux 内核 4.18
动态编程语言、Web 和数据库服务器
Python 3.6
是默认的 Python 环境,有限支持 Python 2.7
Node.js
是在 RHEL 最新包含的,其他动态语言更新包括: PHP 7.2
, Ruby 2.5
, Perl 5.26
, SWIG 3.0
RHEL 8 提供的数据库服务包括:MariaDB 10.3
, MySQL 8.0
, PostgreSQL 10
, PostgreSQL 9.6
, 和 Redis 5
RHEL 8 提供Apache HTTP Server 2.4
以及首次引入的, nginx 1.14
Squid
版本升级到 4.4 ,同时也首次提供Varnish Cache 6.0
安装要点 具体参看 CentOS 8 安装截图,这里列出几个注意点
先配置网络,否则 NTP 无法配置,boot.iso 版本需要指定安装源也需要 Internet 访问
指定安装源,这里可以使用 163 或者阿里云镜像
https://mirrors.aliyun.com/CentOS/8/BaseOS/x86_64/os/
https://mirrors.163.com/CentOS/8/BaseOS/x86_64/os/
系统配置 1. 格式化网卡命名 即禁用 consistent interface device naming
要点:与 CentOS 7 配置上略有不同
CentOS 7:net.ifnames=0 biosdevname=0
CentOS 8:net.ifnames=0
[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens160 #注意这里的名称根据硬件有所变动,这里是vm环境,默认ens160,如果你希望继续使用 eth0 这样的传统名称,那么在安装启动时加上参数:net.ifnames=0
从 CentOS 7 开始,这种变化的原因,是由于systemd 和 udev 引入了一种新的网络设备命名方式 – 一致网络设备命名(CONSISTENT NETWORK DEVICE NAMING)。可以根据固件、拓扑、位置信息来设置固定名字,带来的好处是命名自动化,名字完全可预测,在硬件坏了以后更换也不会影响设备的命名,这样可以让硬件的更换无缝化。带来的不利是新的设备名称比传统的名称难以阅读。比如新的名称是enp5s0.
1.1 编辑 grub 配置文件
1 2 3 4 5 6 7 8 9 10 # 如果系统已经安装,希望改成eth0这样的名称,那么需要: # 修改grub2启动参数 vi /etc/sysconfig/grub # 增加内容:net.ifnames=0 原内容: GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet" 修改后(位置并没有严格要求): GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap net.ifnames=0 rhgb quiet" # 保存 :x
1 2 # 直接用sed命令替换,经过测试sed修改不生效,未知 sed -i '/^GRUB_CMDLINE_LINUX=.*/c GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap net.ifnames=0 rhgb quiet"' /etc/sysconfig/grub
1.2 运行如下命令重建 grub.cfg 文件
1 grub2-mkconfig -o /boot/grub2/grub.cfg
1.3 重命名网卡配置文件
1 2 3 4 5 6 7 # 重新对文件进行命名: cd /etc/sysconfig/network-scripts/ mv ifcfg-ens160 ifcfg-eth0 vi ifcfg-eth0 编辑NAME=eth0 编辑DEVICE=eth0 注释HWADDR,如果有
1.4 重启生效
参考官方文档
2. 配置网络 2.1 方法一:手工配置 ifcfg,使用 nmcli 来生效新的网络配置 安装过程中最好配置好网络,如果需要编辑网络,修改配置文件如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=eth0 UUID=34f 808f1-1232 -4900 -83 db-82 d32533f776 DEVICE=eth0 ONBOOT=yes IPADDR=10.3 .5 .5 PREFIX=24 GATEWAY=10.3 .5 .1 DNS1=10.3 .5 .11 DNS2=10.3 .5 .12 DOMAIN=sysin.org IPV6_PRIVACY=no
1 2 3 4 5 nmcli c reload #重新加载网络配置 ping www.baidu.com #测试网络是否正常 ip addr #查看IP地址
重启网络
比如配置了静态路由,使用nmcli c reload无法生效,需要重启网络
1 2 systemctl restart NetworkManager.service nmcli networking off && nmcli networking on
CentOS 8 网卡命令(CentOS 7 也可用)
1 2 3 4 5 6 7 nmcli n #查看nmcli状态 nmcli n on #启动nmcli nmcli c up eth0 #启动网卡eth0 nmcli c down eth0 #关闭网卡eth0 nmcli d c eth0 #激活网卡 nmcli d show eth0 #查看网卡eth0信息 nmcli r all off #关闭无线
2.2 方法二:RHEL8 和 CentOS8 完全使用 nmcli 来管理网络 nmcli 命令帮助
命令不支持自动补全,但是可以通过-h参数逐步获得帮助
1 2 3 4 5 6 7 # # # nmcli -h nmcli connection -h nmcli connection add -h nmcli connection modify -h
创建一个完整的配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 IFACE=`nmcli dev|grep ethernet|awk '{print $1}'` nmcli con delete $IFACE # 下面将使用传统的eth0命名方式,前提是已经做了下面格式化网卡名称的配置 nmcli con add con-name eth0 ifname eth0 type ethernet autoconnect yes nmcli connection modify eth0 ipv4.method manual \ ipv4.addresses 10.3.5.5/24 \ ipv4.dns "10.3.5.11, 10.3.5.12" \ ipv4.gateway 10.3.5.1 \ ipv4.dns-search sysin.org nmcli c up eth0 nmcli c reload
可以配置的参数选项:
ipv4.[method, dns, dns-search, dns-options, dns-priority, addresses, gateway, routes, route-metric, route-table, ignore-auto-routes, ignore-auto-dns, dhcp-client-id, dhcp-timeout, dhcp-send-hostname, dhcp-hostname, dhcp-fqdn, never-default, may-fail, dad-timeout]
nmcli示例命令参考
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 # 查看网卡信息 nmcli connection NAME UUID TYPE DEVICE eth0 db05ccae-3a48-4300-b3a6-7c56429c4f54 ethernet eth0 # 显示具体的网络接口信息 nmcli connection show eth0 # 显示所有活动连接 nmcli connection show --active # 删除一个网卡连接 nmcli connection delete eth0 # 创建一个网卡连接 IFACE=`nmcli dev|grep ethernet|awk '{print $1}'` nmcli con delete $IFACE nmcli con add con-name "$IFACE" ifname "$IFACE" type ethernet autoconnect yes # 给eth0添加一个IP和子网掩码(NETMASK) nmcli connection modify eth0 ipv4.addresses 10.3.5.5/24 # 给eth0添加两个IP地址和掩码 nmcli connection modify eth0 ipv4.addresses "10.3.5.5/24, 10.3.5.6/24" # IP获取方式设置成手动(BOOTPROTO=static/none) nmcli connection modify eth0 ipv4.method manual # 添加一个ipv4 nmcli connection modify eth0 +ipv4.addresses 10.3.5.6/24 # 删除一个ipv4 nmcli connection modify eth0 -ipv4.addresses 10.3.5.6/24 # 添加DNS nmcli connection modify eth0 ipv4.dns 10.3.5.11 # 同时添加两个DNS nmcli connection modify eth0 ipv4.dns "10.3.5.11, 10.3.5.12" # 删除DNS nmcli connection modify eth0 -ipv4.dns 10.3.5.11 # 删除第一个DNS nmcli connection modify eth0 -ipv4.dns 1 # 添加一个网关(GATEWAY) nmcli connection modify eth0 ipv4.gateway 10.3.5.1 # 都可以同时写,例如: nmcli connection modify eth0 ipv4.dns 10.3.5.11 ipv4.gateway 10.3.5.1 # 域名dns-search,对应ifcfg中的DOMAIN nmcli connection modify eth0 ipv4.dns-search sysin.org # 使用nmcli重新回载网络配置 nmcli c reload # 如果之前没有eth0的connection,则上一步reload后就已经自动生效了 nmcli c up eth0
2.3 方法三:手工配置 ifcfg,安装 network.service 服务 可以通过 yum install network-scripts
来安装传统的 network.service,不过 redhat 说了,在下一个RHEL的大版本里将彻底废除,因此不建议使用 network.service。
1 2 3 yum install network-scripts service network restart #重启网络服务 systemctl restart network.service #重启网络服务
3. 修改主机名 说明:与 CentOS 7 方法相同
1 2 3 4 5 6 7 8 9 10 vi /etc/hostname #编辑配置文件 www #修改localhost.localdomain为www :x #保存退出 或者使用命令:hostnamectl set-hostname www 同时修改hosts文件: vi /etc/hosts #编辑配置文件 127.0.0.1 localhost www #修改localhost.localdomain为www :x #保存退出
通过命令快速修改示例
1 2 3 4 5 6 7 8 9 10 11 hostnamectl set-hostname www # 主机名这里是www,替换实际名称直接执行 NICName=`ip add|egrep global|awk '{ print $NF }'|head -n 1` IP=`ip add|grep global|awk -F'[ /]+' '{ print $3 }'|head -n 1` Hostname=`hostname` HostnameAll=`hostname --fqdn` #注意这里不是引号`` echo "网卡名称:$NICName" echo "IP地址: $IP" echo "主机名称: $Hostname $HostnameAll" echo "$IP $Hostname $HostnameAll">>/etc/hosts
4. 激活 cockpit web console CentOS 8 默认集成了 cockpit,登录画面提示激活方法(模板未启用):
然后通过浏览器访问:http://IP:9090
补充说明:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Cockpit(飞机驾驶舱)使用方法 在 web 浏览器中查看服务器并使用鼠标执行系统任务。很容易管理存储、配置网络和检查日志等操作。 1 ) RHEL 8 自动安装了 Cockpit,Cockpit 所需的防火墙端口会自动打开2 ) Cockpit 界面可用于将基于策略的解密(PBD)规则应用于受管系统上的磁盘3 ) 对于在身份管理(IdM)域中注册的系统,Cockpit 默认使用域的集中管理的 IdM 资源4 ) Cockpit 菜单和页面可以在移劢浏览器上导航5 ) 可以从 Cockpit Web 界面创建和管理虚拟机6 ) 现在可以将“虚拟机”页面添加到 Cockpit 界面,该界面使用户可以创建和管理基于 libvirt 的虚拟机安装 cockpit yum -y install cockpit 启用 cockpit systemctl enable --now cockpit.socket 设置开机自启动同时开启服务一条命令就可以搞定 使用 Cockpit Cockpit 监听 9090 端口 使用浏览器访问 http:
5. 关闭 SELINUX 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 vi /etc/selinux/config # SELINUX=enforcing # SELINUXTYPE=targeted SELINUX=disabled #增加 :x #保存,关闭 setenforce 0 #使配置立即生效,或者重启系统 shutdown -r now #重启系统生效 sestatus #查看状态 # 直接使用sed命令修改 # 修改ELINUX=enforcing为SELINUX=disabled,即替换行 sed '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config # 或者:sed -i '/^SELINUX=enforcing/c SELINUX=disabled' /etc/selinux/config # 注释SELINUXTYPE=targeted sed -i 's/^SELINUXTYPE=targeted/#&/' /etc/selinux/config
6. 配置firewalld 关闭 firewalld (模板配置)
CentOS 8 主要改动和 RedHat Enterprise Linux 8 是一致的,基于 Fedora 28 和内核版本 4.18
,其中网络方面的主要改动是用 nftables 框架替代 iptables 框架作为默认的网络包过滤工具。
1 2 3 systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 firewall-cmd --state #查看状态
firewalld 常用命令 (nftables 使用nft 命令,参看其他文档)
CentOS 8 中 firewalld 已经与 iptables 解绑,后端改用 nftables,需要用 nft
或者 firewall-cmd
开放端口或者服务。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 # 查看配置 firewall-cmd --list-all firewall-cmd --list-services #默认开放:ssh dhcpv6-client firewall-cmd --zone=public --list-services #指定区域进行查看 firewall-cmd --list-ports firewall-cmd --zone=public --list-ports #指定区域进行查看 # 配置保存文件 cat /etc/firewalld/zones/public.xml # 添加一个TCP端口(删除将add关键字修改为remove) firewall-cmd --zone=public --add-port=80/tcp --permanent #--permanent表示永久生效 firewall-cmd --add-port=80/tcp --permanent #与上面是等价的,默认zone为pulic firewall-cmd --reload #重新加载配置生效 # 关于zone firewall-cmd --get-zones #查看所有zone的命令,CentOS 7 一共有9个zone block dmz drop external home internal public trusted work firewall-cmd --get-zones ##CentOS 8 有10个zone block dmz drop external home internal libvirt public trusted work firewall-cmd --get-default-zone #查看默认的zone的命令 public # 添加一个服务 firewall-cmd --add-service=snmp --permanent firewall-cmd --reload firewall-cmd --get-services #查看可用的服务 # 限定源地址访问 firewall-cmd --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="3306" accept" --permanent firewall-cmd --reload
添加几个常用的服务
1 2 3 4 firewall-cmd --add-service=snmp --permanent firewall-cmd --add-service=http --permanent firewall-cmd --add-service=https --permanent firewall-cmd --reload
禁Ping
1 2 firewall-cmd --permanent --add-rich-rule='rule protocol value=icmp drop' #全部禁ping firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" protocol value="icmp" accept' #指定192.168.1.0/24允许icmp
1 2 3 4 5 yum install epel-release -y 或者 (EL8): rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
8. 安装一些必备工具 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 # 一些基本工具最小化安装可能没有(经测vim和wget没有安装) yum install vim wget zip unzip man gcc make -y # 以下网络工具已经不存在 # yum install setuptool system-config-network-tui system-config-firewall-tui -y # 默认安装没有ifconfig命令,安装net-tools: # ifconfig、netstat、route等命令集 yum install net-tools -y # 更好的top工具 yum install htop -y # host、dig和nslookup yum install bind-utils -y # 文件传输:sz和rz(样本未安装) yum install lrzsz -y # 查看日志神器Log file Navigator # yum install lnav -y # EPEL中没有了,直接在线安装 rpm -ivh https://github.com/tstack/lnav/releases/download/v0.8.5/lnav-0.8.5-1.x86_64.rpm # NTP已经废弃,改用chrony # yum install ntp -y # nc: yum install nc -y # lsof: yum install lsof -y # tree: yum install tree -y # pstree: yum install psmisc -y
fd 命令(fd-find,强烈推荐)
1 2 3 4 # gcc 编译版本 wget https://github.com/sharkdp/fd/releases/download/v8.0.0/fd-v8.0.0-x86_64-unknown-linux-gnu.tar.gz # musl libc 编译版本 wget https://github.com/sharkdp/fd/releases/download/v8.0.0/fd-v8.0.0-x86_64-unknown-linux-musl.tar.gz
1 2 3 4 5 6 tar -zxvf fd-v8.0.0-x86_64-unknown-linux-*.tar.gz cd fd-v8.0.0-x86_64-unknown-linux-gnu cp ./fd /usr/local/bin/ cp ./fd.1 /usr/local/share/man/man1/ mandb
rg 命令
1 2 3 wget https://github.com/BurntSushi/ripgrep/releases/download/12.0.0/ripgrep-12.0.0-x86_64-unknown-linux-musl.tar.gz tar xzvf ripgrep-12.0.0-x86_64-unknown-linux-musl.tar.gz cp ripgrep-12.0.0-x86_64-unknown-linux-musl/rg /usr/local/bin/
9. 配置 NTP 在 CentOS 8.0 中默认不再支持 ntp 软件包,时间同步将由 chrony 来实现。
1 2 3 4 5 6 cat /etc/chrony.conf # These servers were defined in the installation: pool 2.centos.pool.ntp.org iburst pool 0.pool.ntp.org iburst pool ntp1.aliyun.com iburst pool ntp2.aliyun.com iburst
10. 安装 SNMP 1 2 3 4 yum install net-snmp net-snmp-devel net-snmp-libs net-snmp-utils -y # 对比 CentOS 7 net-snmp-perl 已经不存在(未知) # 因为是模板,这里暂不配置
在系统安装时候勾选了“Guest Agent”,将自动安装open-vm-tools
1 2 3 4 5 6 7 8 9 10 11 手动安装open-vm-tools: # http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2073803 yum install open-vm-tools -y # 开启服务 chkconfig vmtoolsd on systemctl enable vmtoolsd.service # 启动服务 service vmtoolsd start systemctl start vmtoolsd
12. 用 yum 排除不需要的更新包 1 2 3 4 5 6 7 8 9 10 11 修改 yum 的配置文件 vi /etc/yum.conf 在 [main] 的最后添加 exclude =kernel* 示例: [main] gpgcheck =1installonly_limit =3clean_requirements_on_remove =True best =True exclude =kernel*
说明: 通常在用 yum 进行更新时老是会更新内核,这样就造成了两个问题: 1).内核过多,占用系统的空间 2).如果是自行编译安装的 nvidia 显卡驱动的话,进入更新的核心时需要再重新安装显卡驱动
这里介绍好的办法解决这个问题,就是在更新时排除对内核的更新,方法有两个: 1).修改yum的配置文件 vi /etc/yum.conf,在[main]的最后添加 exclude=kernel* 2).直接在yum的命令行执行如下的命令: yum –exclude=kernel* update
以上的办法也适合你要求自行排除的其它更新软件包。
1 备注:安装某些软件包需要新版内核支持,需要删除以上配置。
13. 更换国内镜像 yum 源 说明:与 CentOS 7 具体不太一样
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 cd /etc/yum.repos.d ls -l # repo更多 -rw-r--r--. 1 root root 731 Aug 14 14:42 CentOS-AppStream.repo -rw-r--r--. 1 root root 712 Aug 14 14:42 CentOS-Base.repo -rw-r--r--. 1 root root 798 Aug 14 14:42 CentOS-centosplus.repo -rw-r--r--. 1 root root 1320 Aug 14 14:42 CentOS-CR.repo -rw-r--r--. 1 root root 668 Aug 14 14:42 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 756 Aug 14 14:42 CentOS-Extras.repo -rw-r--r--. 1 root root 338 Aug 14 14:42 CentOS-fasttrack.repo -rw-r--r--. 1 root root 928 Aug 14 14:42 CentOS-Media.repo -rw-r--r--. 1 root root 736 Aug 14 14:42 CentOS-PowerTools.repo -rw-r--r--. 1 root root 1382 Aug 14 14:42 CentOS-Sources.repo -rw-r--r--. 1 root root 74 Aug 14 14:42 CentOS-Vault.repo -rw-r--r--. 1 root root 1351 Aug 7 02:17 epel-playground.repo -rw-r--r--. 1 root root 1206 Aug 7 02:17 epel.repo -rw-r--r--. 1 root root 1305 Aug 7 02:17 epel-testing.repo dnf repolist # 只需要修改以下4个启用的repo Last metadata expiration check: 0:00:45 ago on Sat 09 Nov 2019 01:26:02 PM CST. repo id repo name status AppStream CentOS-8 - AppStream 5,089 BaseOS CentOS-8 - Base 2,843 epel Extra Packages for Enterprise Linux 8 - x86_64 2,911 extras CentOS-8 - Extras 3 # 备份 cp CentOS-Base.repo CentOS-Base.repo.bak cp CentOS-AppStream.repo CentOS-AppStream.repo.bak cp CentOS-Extras.repo CentOS-Extras.repo.bak # 替换 sed -i 's/mirrorlist=/#mirrorlist=/g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo sed -i 's/#baseurl=/baseurl=/g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo sed -i 's/http:\/\/mirror.centos.org/https:\/\/mirrors.aliyun.com/g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo # 修改epel(url不一样) cp epel.repo epel.repo.bak sed -i 's/metalink=/#metalink=/g' epel.repo sed -i 's/#baseurl=/baseurl=/g' epel.repo sed -i 's/https:\/\/download.fedoraproject.org\/pub/https:\/\/mirrors.aliyun.com/g' epel.repo
以下是 CentOS 7 的修改方法,备忘:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 # 推荐使用163镜像(Base使用163,epel使用ustc) # http://mirrors.163.com/.help /centos.html mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup cp /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup sudo sed -e 's!^mirrorlist=!#mirrorlist=!g' \ -e 's!^#baseurl=!baseurl=!g' \ -e 's!//download\.fedoraproject\.org/pub!//mirrors.ustc.edu.cn!g' \ -e 's!http://mirrors\.ustc!https://mirrors.ustc!g' \ -i /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo yum clean all yum makecache # 也可以使用阿里云镜像 # http://mirrors.aliyun.com/repo/ 第一步:备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup 第二步:下载 CentOS 7 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo wget -O /etc/yum.repos.d/epel-testing.repo http://mirrors.aliyun.com/repo/epel-testing.repo 第三步:运行yum makecache生成缓存 yum clean all rm -rf /var/cache/yum yum makecache
禁用 fastestmirror 插件
模板未配置,下个版本加入
1 2 3 4 5 6 # sed -i '/^enabled=.*/c enabled=0' /etc/yum/pluginconf.d/fastestmirror.conf sed -i '/^enabled=1/c enabled=0' /etc/yum/pluginconf.d/fastestmirror.conf # 写入文件需要添加 -i 参数 # ^ 表示一行的开头 # . 匹配一个非换行符的任意字符 # * 匹配0个或多个字符
14. 系统更新 1 2 3 4 dnf mackecache dnf update dnf clean all rm -rf /var /cache /dnf
1 2 3 echo > ~/.bash_history \rhistory -c rm -rf /tmp/ *
1 2 3 4 5 6 7 8 9 10 11 12 #比较完整的清空历史记录 rm -f /var /log /audit/audit*\recho > /var /log /audit/audit.log \r rm -f /var /log /secure*\recho > /var /log /secure\r rm -f /var /log /btmp*\recho > /var /log /btmp\r rm -f /var /log /wtmp*\recho > /var /log /wtmp\r echo > /var /log /lastlog\r echo > ~/.bash_history\r history -c\r
15. 安装图形界面 基于特定场景需要,一般不用安装
1 2 3 4 5 6 yum grouplist #查看可安装的组件 yum groupinstall "Server with GUI" #安装GNOME图形界面(与CentOS 7名称不一样) yum groupinstall "Graphical Administration Tools" #将自动安装 startx #启动图形界面
实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 [[email protected] ~]# yum grouplist Last metadata expiration check: 1:12:58 ago on Sat 09 Nov 2019 03:59:09 PM CST. Available Environment Groups: Server with GUI Server Workstation KDE Plasma Workspaces Virtualization Host Custom Operating System Installed Environment Groups: Minimal Install Installed Groups: Development Tools Available Groups: Container Management .NET Core Development RPM Development Tools Smart Card Support Graphical Administration Tools Headless Management Legacy UNIX Compatibility Network Servers Scientific Support Security Tools System Tools Fedora Packager
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 [[email protected] ~]# yum groupinstall "Server with GUI" Installing Environment Groups: Server with GUIInstalling Groups: Container Management Core Fonts GNOME Guest Desktop Agents Hardware Monitoring Utilities Hardware Support Headless Management Internet Browser Multimedia Common NetworkManager submodules Printing Client Server product core Standard Transaction Summary ============================================================================================================== Install 744 Packages Total download size: 696 M Installed size: 2.1 G Is this ok [y/N]:
如果文章中使用的内容或图片侵犯了您的版权,请联系作者删除。如果您喜欢这篇文章或者觉得它对您有所帮助,欢迎您发表评论,也欢迎您分享这个网站,或者赞赏一下作者,谢谢!