Rocky Linux 8 安装笔记

  • A+
所属分类:linux技术
摘要

请访问原文链接:https://sysin.org/blog/rocky-linux-8-install,查看最新版。原创作品,转载请保留出处。

请访问原文链接:https://sysin.org/blog/rocky-linux-8-install,查看最新版。原创作品,转载请保留出处。

作者:gc(at)sysin.org,主页:www.sysin.org

iso 下载:https://sysin.org/blog/rocky-linux-8

ovf 下载:https://sysin.org/blog/rocky-linux-8-ovf

Redhat 对 CentOS Linux 8 的支持也已从 2029年 5 月 31 日缩短至 2021 年 12 月 31 日。

Rocky Linux 8 正式版已经发布,作为 CentOS 的权威替代,是时候考虑将 CentOS 8 替换为 Rocky Linux 了。

Rocky Linux 简介

2021 年 6 月 21 日,Rocky Linux 8.4 首个正式版发布,Rocky Linux 由 CentOS 项目的创始人 Gregory Kurtzer 领导。

Rocky Linux 8 安装笔记

以社区驱动为导向,为您带来企业级、可生产的 Linux 系统。

Rocky Linux 项目是什么?

Rocky Linux 是一个社区化的企业级操作系统。其设计为的是与美国顶级企业 Linux 发行版实现 100% Bug 级兼容,而原因是后者的下游合作伙伴转移了发展方向。目前社区正在集中力量发展有关设施。Rocky Linux 由 CentOS 项目的创始人 Gregory Kurtzer 领导。目前已经发布了首个正式版。

常见问题

“下游合作伙伴转移了发展方向” 是什么意思?

CentOS 项目最近宣布了 CentOS 的战略转变,CentOS 以前是作为上游供应商的下游构建版本存在的(即它会在上游供应商之后收到补丁和更新),而现在它将转移为一个上游构建版本(即它会在上游供应商纳入之前测试补丁和更新)。另外,对 CentOS Linux 8 的支持也已从 2029 年 5 月 31 日缩短至 2021 年 12 月 31 日。

那么 Rocky Linux 从何而来呢?

Rocky Linux 的目标是像 CentOS 以前那样作为一个下游构建版本,在被上游供应商纳入包更新之后(而不是之前)构建发行。

CentOS 是红帽公司(Red Hat, Inc.)的注册商标,Rocky Linux 项目既不隶属于红帽公司(Red Hat, Inc.),也无受其认可。

新特性

CentOS 8 新特性

  • DNF 成为了默认的软件包管理器,同时 yum 仍然是可用的(yum 是 dnf 的链接)

  • 使用网络管理器(nmclinmtui)进行网络配置,移除了网络脚本

  • 使用 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.4 Upstream changes

See the Overview section of the upstream RHEL 8.4 release notes.

Of particular note, this release adds the following new versions of software in optional module streams.

  • Python 3.9
  • SWIG 4.0
  • Subversion 1.14
  • Redis 6
  • PostgreSQL 13
  • MariaDB 10.5

Several rolling AppStream have been rebased to newer versions.

  • LLVM Toolset 11.0.0
  • Rust Toolset 1.49.0
  • Go Toolset 1.15.7

Yum repo file and repoid changes

You may also want to update any scripts that you have that specify repoids using the --enablerepo or --disablerepo flags

Repoid (8.2.2004 and before) Repoid (8.3.2011 and later)
BaseOS baseos
AppStream appstream
PowerTools powertools
centosplus plus
HighAvailability ha
base-debuginfo debuginfo
Devel devel
BaseOS-source baseos-source
AppStream-source appstream-source
centosplus-source plus-source
base-debuginfo debuginfo

安装要点

详细步骤参看 CentOS 8 安装截图,这里列出几个注意点。

推荐使用 Minimal 安装介质。

先配置网络,否则某些项目无法配置。

  • Network & Hostname:点击 OFF 按钮为 ON,点击 Configure... 按钮,General 页面注意勾选 “Connect automatically with priority”,根据需要手动配置 IP 地址和 DNS。

  • Installation Destination:点选 Custom,默认使用 LVM,点击 “Click here to create them automatically” 自动创建,手动调整:删除 /home,将 SWAP 修改为整数 4 GiB,/boot 默认 1024 MiB,剩余分配给 /。

  • Installation Source:如果是 Minimal 或者 DVD 介质,默认是 Local media

    如果是 boot 安装介质,配置网络后自动修改为 Cloest mirror,也可以根据需要手动指定:这里可以使用 163 或者阿里云镜像 https://mirrors.aliyun.com/CentOS/8/BaseOS/x86_64/os/
    https://mirrors.163.com/CentOS/8/BaseOS/x86_64/os/

  • Keyboard:默认 English (US)

  • Language Support:下拉到最下面 “中文”,勾选 “简体中文” 和两个 “繁体中文”

  • Software Selection:Minimal Install,勾选 "Development Tools",虚机同时勾选 “Guest Agent”

  • KDUMP:默认启用

  • Time & Date:点选 Asia/Shanghai,Network Time 自动 ON(前面先配置了网络)

  • Security Policy:暂无,忽略

  • Root Password:支持 root 密码

  • User Creation:新建额外的账号,可选

"Development Tools" 有哪些软件?

# dnf groupinfo "Development Tools" Updating Subscription Management repositories.  Group: Development Tools  Description: A basic development environment.  Mandatory Packages:    autoconf    automake    binutils    bison    flex    gcc    gcc-c++    gdb    glibc-devel    libtool    make    pkgconf    pkgconf-m4    pkgconf-pkg-config    redhat-rpm-config    rpm-build    rpm-sign    strace  Default Packages:    asciidoc    byacc    ctags    diffstat    git    intltool    ltrace    patchutils    perl-Fedora-VSP    perl-generators    pesign    source-highlight    systemtap    valgrind  Optional Packages:    cmake    expect    rpmdevtools    rpmlint 

手动安装开发工具命令:dnf groupinstall "Development Tools"

系统配置

1. 格式化网卡命名

即禁用 consistent interface device naming

要点:与 CentOS 7 配置上略有不同。

  • CentOS 7:net.ifnames=0 biosdevname=0
  • CentOS 8:net.ifnames=0
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ [root@localhost ~]# ls ifcfg-ens33 

注意这里的名称根据硬件有所变动,这里是 vm 环境,本次名称为 ens33,如果你希望继续使用 eth0 这样的传统名称,那么在安装启动时加上参数:net.ifnames=0

这种变化的原因,从 CentOS 7 开始,是由于 systemd 和 udev 引入了一种新的网络设备命名方式 – 一致网络设备命名(CONSISTENT NETWORK DEVICE NAMING)。可以根据固件、拓扑、位置信息来设置固定名字,带来的好处是命名自动化,名字完全可预测,在硬件坏了以后更换也不会影响设备的命名,这样可以让硬件的更换无缝化。带来的不利是新的设备名称比传统的名称难以阅读。比如新的名称是 enp5s0.

Rocky Linux 8 grub 默认配置如下:

# cat /etc/default/grub GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed's, release .*$,,g'/etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/rl-swap rd.lvm.lv=rl/root rd.lvm.lv=rl/swap" GRUB_DISABLE_RECOVERY="true" GRUB_ENABLE_BLSCFG=true 

不同于 CentOS 8,没有 rhgb quiet

rhgb 表示 redhat graphics boot,就是会看到图片来代替启动过程中显示的文本信息,这些信息在启动后用 dmesg 也可以看到

quiet 表示在启动过程中只有重要信息显示,类似硬件自检的消息不回显示

1.1 编辑 grub 配置文件

# 如果系统已经安装,希望改成 eth0 这样的名称,那么需要: # 修改 grub2 启动参数 vi /etc/default/grub # 也有文章修改 /etc/sysconfig/grub,该文件是 /etc/default/grub 的链接 # 增加内容:net.ifnames=0 # 原内容: GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/rl-swap rd.lvm.lv=rl/root rd.lvm.lv=rl/swap" # 修改后 (位置并没有严格要求,一般添加在最后面即可): GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/rl-swap rd.lvm.lv=rl/root rd.lvm.lv=rl/swap net.ifnames=0" #保存 :x 

因为默认没有 rhgb quiet 参数,以下仅适用于 CentOS

# 直接用 sed 命令替换 # CentOS 8 sed -i 's/rhgb/net.ifnames=0 rhgb/' /etc/default/grub # CentOS 7 sed -i 's/rhgb/net.ifnames=0 biosdevname=0 rhgb/' /etc/default/grub 

1.2 运行如下命令重建 grub.cfg 文件

# legacy boot mode: grub2-mkconfig -o /boot/grub2/grub.cfg  # UEFI boot mode: grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg 

1.3 重命名网卡配置文件

# 重新对文件进行命名: cd /etc/sysconfig/network-scripts/ mv ifcfg-ens33 ifcfg-eth0 vi ifcfg-eth0 编辑 NAME=eth0 编辑 DEVICE=eth0 注释 HWADDR,如果有 

1.4 重启生效

reboot 

重新登录后,执行命令 nmcli 可以看到网卡名称已经变成 “eth0”,则配置成功。

参考:官方文档

2. 配置网络

2.1 方法一:手工配置 ifcfg,使用 nmcli 来生效新的网络配置

安装过程中最好配置好网络,如果需要编辑网络,修改配置文件如下:

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0  TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none  #static,使用静态 IP 配置(CentOS 8 这里是 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=34f808f1-1232-4900-83db-82d32533f776 DEVICE=eth0 ONBOOT=yes  #开机自动启用网络连接 IPADDR=10.3.5.5  #IP 地址 PREFIX=24  #掩码 GATEWAY=10.3.5.1  #默认网关 DNS1=10.3.5.11  #DNS 服务器 DNS2=10.3.5.12  #备用 NDS 服务器 DOMAIN=sysin.org  #域名 IPV6_PRIVACY=no 
nmcli c reload  #重新加载网络配置  ping www.baidu.com  #测试网络是否正常  ip addr  #查看 IP 地址 

重启网络

比如配置了静态路由,使用 nmcli c reload 无法生效,需要重启网络

systemctl restart NetworkManager.service nmcli networking off && nmcli networking on 

注意:CentOS 8 (默认安装) 重启网络 "systemctl restart network" 已经不可用。

CentOS 8 网卡命令 (CentOS 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 参数逐步获得帮助

## 说明 nmcli 后面的命令关键字都可以用第一个字母简写来标识,例如: ## nmcli connection = nmcli c ## nmcli connection show --active = nmcli c s --a nmcli -h nmcli connection -h nmcli connection add -h nmcli connection modify -h 

创建一个完整的配置文件:

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 示例命令参考:

# 查看网卡信息 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。

yum install network-scripts service network restart   #重启网络服务 systemctl restart network.service   #重启网络服务 

3. 修改主机名

说明:与 CentOS 7 方法相同

  • 即时生效
hostname  sysin  #设置主机名为 sysin 
  • 永久生效
vi /etc/hostname #编辑配置文件 sysin   #修改 localhost.localdomain 为 sysin :x  #保存退出  或者使用命令:`hostnamectl set-hostname sysin`  同时修改 hosts 文件: vi /etc/hosts #编辑配置文件 127.0.0.1   sysin   #增加一条 :x  #保存退出 

通过命令快速修改示例

hostnamectl set-hostname sysin # 主机名这里是 sysin,替换实际名称直接执行 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,登录画面提示激活方法(模板未启用):

systemctl enable --now cockpit.socket 

然后通过浏览器访问:http://<IP>:9090

补充说明:

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://<IP>:9090` 

5. 关闭 SELINUX

vi /etc/selinux/config # SELINUX=enforcing       #注释掉 # SELINUXTYPE=targeted    #注释掉 SELINUX=disabled         #增加 :x  #保存,关闭 setenforce 0 #使配置立即生效,或者重启系统 #shutdown -r now   #重启系统生效  sestatus  #查看状态  # 直接使用 sed 命令修改 # 修改 ELINUX=enforcing 为 SELINUX=disabled,即替换行 sed -i '/^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 框架作为默认的网络包过滤工具。

systemctl stop firewalld.service  #停止 firewall systemctl disable firewalld.service  #禁止 firewall 开机启动 firewall-cmd --state  #查看状态 

firewalld 常用命令(nftables 使用 nft 命令,参看其他文档)

CentOS 8 中 firewalld 已经与 iptables 解绑,后端改用 nftables,需要用 nft 或者 firewall-cmd 开放端口或者服务。

# 查看配置 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 

添加几个常用的服务:

firewall-cmd --add-service=snmp --permanent firewall-cmd --add-service=http --permanent firewall-cmd --add-service=https --permanent firewall-cmd --reload 

禁 Ping:

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 

7. 安装 EPEL (Extra Packages for Enterprise Linux)

yum -y install epel-release  或者 (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. 安装一些必备工具

# 一些基本工具最小化安装可能没有 (经测 vim 和 wget 等没有安装) yum -y install vim wget zip unzip  # gcc 等选择开发工具(上述安装过程建议勾选了"Development Tools") dnf groupinstall "Development Tools"  # Rocky Linux 默认没有 tar 命令,AlmaLinux 也没有,但是 CentOS 默认有 yum -y install tar  # 以下网络工具已经不存在 # yum -y install setuptool system-config-network-tui system-config-firewall-tui  # 默认安装没有 ifconfig 命令,安装 net-tools # ifconfig、netstat、route 等命令集 yum -y install net-tools  # host、dig 和 nslookup yum -y install bind-utils  # 更好的 top 工具 yum -y install htop #Anolis OS 中没有 #https://github.com/hishamhm/htop  # 文件传输:sz 和 rz yum -y install lrzsz  # 查看日志神器 Log file Navigator yum -y install lnav # 该软件现在已经包含在 EPEL 中 # 初期 EPEL 中没有,直接在线安装 #rpm -ivh https://github.com/tstack/lnav/releases/download/v0.9.0/lnav-0.9.0-1.x86_64.rpm #Anolis OS 中没有  # NTP 已经废弃,改用 chrony,默认自带 # yum -y install ntp  # nc: yum -y install nc  # lsof: yum -y install lsof  # tree: yum -y install tree  # pstree: yum -y install psmisc  # ncdu:NCurses Disk Usage yum -y install ncdu #新增工具,模板尚未加入,下个版本更新  # dstat 监控 CPU、磁盘和网络使用率,下个版本加入 yum -y install dstat 

fd 命令(fd-find,强烈推荐)

# 下载(二选一): # 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  # 安装: tar -zxvf fd-v8.0.0-x86_64-unknown-linux-*.tar.gz cd fd-v8.0.0-x86_64-unknown-linux-musl  cp ./fd /usr/local/bin/ cp ./fd.1 /usr/local/share/man/man1/ mandb 

可以根据个人习惯安装一些常用工具。

9. 配置 NTP

在 CentOS 8.0 中默认不再支持 ntp 软件包,时间同步将由 chrony 来实现。

cat /etc/chrony.conf # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). # These servers were defined in the installation: pool 2.pool.ntp.org iburst  #Rocky default pool 2.centos.pool.ntp.org iburst #CentOS default pool 0.pool.ntp.org iburst pool ntp1.aliyun.com iburst pool ntp2.aliyun.com iburst 

10. 安装 SNMP

yum -y install net-snmp net-snmp-devel net-snmp-libs net-snmp-utils  # 对比 CentOS 7 net-snmp-perl 已经不存在 (未知) # 因为是模板,这里暂不配置 

11. 虚机安装 VM-tools

在系统安装时候勾选了 “Guest Agent”,将自动安装 open-vm-tools

手动安装 open-vm-tools: # http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2073803 yum -y install open-vm-tools  # 开启服务 #chkconfig vmtoolsd on systemctl enable vmtoolsd.service  # 启动服务 #service vmtoolsd start systemctl start vmtoolsd  # 查看版本 vmtoolsd -v #现在已经 11.2.0 VMware Tools daemon, version 11.2.0.23855 (build-16938113) 

12. 用 yum 排除不需要的更新包

# 修改 yum 的配置文件 vi /etc/yum.conf # 在 [main] 的最后添加 exclude=kernel*  # 示例: [main] gpgcheck=1 installonly_limit=3 clean_requirements_on_remove=True best=True skip_if_unavailable=False exclude=kernel* 

说明:
通常在用 yum 进行更新时老是会更新内核,这样就造成了两个问题:
1). 内核过多,占用系统的空间
2). 如果是自行编译安装的 nvidia 显卡驱动的话,进入更新的核心时需要再重新安装显卡驱动

这里介绍好的办法解决这个问题,就是在更新时排除对内核的更新,方法有两个:
1). 修改 yum 的配置文件 vi /etc/yum.conf,在 [main] 的最后添加 exclude=kernel*
2). 直接在 yum 的命令行执行如下的命令: yum --exclude=kernel* update

以上的办法也适合你要求自行排除的其它更新软件包。

备注:安装某些软件包需要新版内核支持,需要删除以上配置。 

13. 更换国内镜像 yum 源

Rocky Linux 默认 repo 如下:

[root@localhost ~]# dnf repolist repo id                                                      repo name appstream                                                    Rocky Linux 8 - AppStream baseos                                                       Rocky Linux 8 - BaseOS extras                                                       Rocky Linux 8 - Extras [root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# ll total 44 -rw-r--r--. 1 root root  700 Jun 19 22:20 Rocky-AppStream.repo -rw-r--r--. 1 root root  685 Jun 19 22:20 Rocky-BaseOS.repo -rw-r--r--. 1 root root  713 Jun 19 22:20 Rocky-Devel.repo -rw-r--r--. 1 root root  685 Jun 19 22:20 Rocky-Extras.repo -rw-r--r--. 1 root root  721 Jun 19 22:20 Rocky-HighAvailability.repo -rw-r--r--. 1 root root  680 Jun 19 22:20 Rocky-Media.repo -rw-r--r--. 1 root root  685 Jun 19 22:20 Rocky-Plus.repo -rw-r--r--. 1 root root  705 Jun 19 22:20 Rocky-PowerTools.repo -rw-r--r--. 1 root root  736 Jun 19 22:20 Rocky-ResilientStorage.repo -rw-r--r--. 1 root root  671 Jun 19 22:20 Rocky-RT.repo -rw-r--r--. 1 root root 2407 Jun 19 22:20 Rocky-Sources.repo 

Rocky Linux 国内镜像源

上海交通大学示例:

sed -e 's|^mirrorlist=|#mirrorlist=|g'      -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.sjtug.sjtu.edu.cn/rocky|g'      -i.bak      /etc/yum.repos.d/Rocky-*.repo 

更换其他镜像,对应按照上面替换 Mirror Name 即可,注意路径 “/rocky”。

官方列表:https://mirror.rockylinux.org/mirrormanager/mirrors

CN 开头的站点

Country Site Name Mirror Name Categories Bandwidth Internet2 Comment
CN EuropeJing mirrors.europejing.com Rocky Linux: http 300 No Personal network, located in Guangdong, mirrors rocky-production every day at 3:00
CN eScience Center, Nanjing University mirrors.nju.edu.cn Rocky Linux: http | https | rsync 10000 No
CN SDU-Mirrors mirrors.sdu.edu.cn Rocky Linux: https 1000 No Located in Qingdao, Shandong, China. Shandong University, China. Sync from official Master. Sync once a day for now.
CN SJTUG mirrors.sjtug.sjtu.edu.cn Rocky Linux: https | rsync 1000 No Hosted by Shanghai Jiao Tong University Linux User Group. Server Location: Shanghai, China. For downstream mirror maintainers, please email [email protected] for request before rsync from us.
CN SKYSHE mirrors.skyshe.cn Rocky Linux: https | http 1000 Yes Personal network, Sync from official Master. Sync once a day for now.

修改 epel,若安装了 epel,同时修改如下:

# dnf repolist repo id                                         repo name appstream                                       Rocky Linux 8 - AppStream baseos                                          Rocky Linux 8 - BaseOS epel                                            Extra Packages for Enterprise Linux 8 - x86_64 epel-modular                                    Extra Packages for Enterprise Linux Modular 8 - x86_64 extras                                          Rocky Linux 8 - Extras  # 修改 epel(url 不一样) sed -e 's/metalink=/#metalink=/g'      -e 's/#baseurl=/baseurl=/g'      -e 's/https://download.fedoraproject.org/pub/https://mirrors.aliyun.com/g'      -i.bak      /etc/yum.repos.d/epel*.repo 

清理并重新生成软件包信息缓存

yum clean all yum autoremove rm -rf /var/cache/yum yum makecache 

14. 更新软件包

dnf clean all dnf mackecache  #缓存软件包信息 dnf upgrade  #更新软件包 #rm -rf /var/cache/dnf 

15. 安装图形界面

基于特定场景需要,一般不用安装

yum grouplist  #查看可安装的组件  yum groupinstall "Server with GUI"  #安装 GNOME 图形界面 (与 CentOS 7 名称不一样) yum groupinstall "Graphical Administration Tools"  #将自动安装  startx  #启动图形界面 

实例:

[root@localhost ~]# 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 
[root@localhost ~]# yum groupinstall "Server with GUI" Installing Environment Groups:  Server with GUI Installing 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]: 

16. Shell 配置

命令自动补全忽略大小写

该配置针对 Bash,仅使用 Zsh 可以忽略。

echo 'set completion-ignore-case on' >> ~/.inputrc 

修改 ll 命令

Linux 中默认定义了 ll 别名,但参数比较少,需要使用更加强大的 ll 别名。

写入环境变量(当前用户优先执行):

zsh:

echo 'alias ll="ls -lahF --color=auto --time-style=long-iso"' >> ~/.zshrc 

bash:

echo 'alias ll="ls -lahF --color=auto --time-style=long-iso"' >> ~/.bashrc 

注意:仅仅针对当前用户,写入全局用户配置文件:/etc/skel/.bashrc 或者 /etc/skel/.zshrc

高级版 ls:以数字显示权限

这里我们把命令叫做 lll

命令:

ls -lahF --color=auto --time-style=long-iso | awk '{k=0;s=0;for(i=0;i<=8;i++){k+=((substr($1,i+2,1)~/[rwxst]/)*2^(8-i))}j=4;for(i=4;i<=10;i+=3){s+=((substr($1,i,1)~/[stST]/)*j);j/=2}if(k){printf("%0o%0o ",s,k)}print}' 

创建文件

在使用 cat EOF 中出现 $ 变量通常会直接被执行,显示执行的结果。若想保持 $ 变量不变需要使用 符进行注释。

#如果非 root 用户,切换到 root sudo -i cat > /usr/local/bin/lll <<EOF #!/bin/bash ls -lahF --color=auto --time-style=long-iso | awk '{k=0;s=0;for(i=0;i<=8;i++){k+=((substr($1,i+2,1)~/[rwxst]/)*2^(8-i))}j=4;for(i=4;i<=10;i+=3){s+=((substr($1,i,1)~/[stST]/)*j);j/=2}if(k){printf("%0o%0o ",s,k)}print}' EOF #赋予执行权限: chmod +x /usr/local/bin/lll #如果非 root 用户,执行完毕退出 exit 

vi 和 vim

CentOS 8 系列 vi 和 vim 是不同的软件,默认安装的是 vi,vim 需要手动安装。

创建 vi 链接直接使用 vim:

ln -s /usr/bin/vim /usr/local/bin/vi 

创建 vimrc 配置文件:

可以根据个人习惯来配置 vim,并用于全局配置。

# 当面用户 ~/.vimrc # 全局新用户默认 /etc/skel/.vimrc 

17. Zsh

以下是针对当前用户配置。全局配置请参看其他文章,这里直接使用全局配置文件即可

# Zsh yum -y install zsh # or #dnf -y install zsh  chsh -s /bin/zsh  yum -y install git  sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"  sed -i '/^ZSH_THEME=.*/c ZSH_THEME="ys"' ~/.zshrc  echo 'alias ll="ls -lahF --color=auto --time-style=long-iso"' >> ~/.zshrc  git clone https://github.com/sangrealest/zsh-autosuggestions.git ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions  sed -i '/^plugins=.*/c plugins=(git zsh-autosuggestions)' ~/.zshrc  source ~/.zshrc 

18. 清理并制作镜像模板

清理 dnf/yum 缓存

dnf autoremove dnf clean all 

清理临时文件夹

rm -rf /tmp/*  #清空临时文件夹 

清空历史记录

#比较完整的清空历史记录 rm -f /var/log/audit/audit* echo > /var/log/audit/audit.log rm -f /var/log/secure* echo > /var/log/secure rm -f /var/log/btmp* echo > /var/log/btmp rm -f /var/log/wtmp* echo > /var/log/wtmp echo > /var/log/lastlog echo > ~/.bash_history echo > ~/.zsh_history history -c 

至此,Rocky Linux 的基本配置已经完成,可以制作模板了。