ARTICLE DETAIL

资讯详情

深耕商务建站与企业官网运营的一线实战洞察。

Rhcsa 二

Rhcsa 二 第一部分 网络服务第一章 Linux的例行性工作单一一次的任务计划单一一次的定时任务at程序包是否安装[rootlocalhost ~]# rpm -q at at-3.1.23-11.el9.x86_64 [rootlocalhost ~]# rpm -qa | grep -w at at-spi2-core-2.40.3-1.el9.x86_64 at-spi2-atk-2.38.0-4.el9.x86_64 at-3.1.23-11.el9.x86_64软件程序是否运行[rootlocalhost ~]# ps -aux | grep -w atd root 1195 0.0 0.2 12472 4992 ? Ss 18:13 0:00 /usr/sbin/atd -f root 2442 0.0 0.1 221812 2688 pts/0 S 18:57 0:00 grep --colorauto -w atd [rootlocalhost ~]# systemctl status atd ● atd.service - Deferred execution scheduler Loaded: loaded (/usr/lib/systemd/system/atd.service; enabled; preset: enabled) Active: active (running) since Wed 2026-10-21 18:13:02 CST; 44min ago Docs: man:atd(8) Main PID: 1195 (atd) Tasks: 1 (limit: 10707) Memory: 896.0K CPU: 13ms CGroup: /system.slice/atd.service └─1195 /usr/sbin/atd -f [rootlocalhost ~]# systemctl is-active atd active [rootlocalhost ~]# yum install at -y #没安装通过该命令安装单一一次的定时任务at命令-m当任务完成后即使没有标准输出也会给用户发送邮件 --了解-l列出系统上所有用户的at任务等价于atq-d删除或取消一个任务-v任务项以前显示时间列出at任务-c可以列出任务之后的命令内容-f从文件中读取时间格式参数说明HH:MM在今天HH小时的MM分钟执行若时间点错过将在明天执行HH:MM YYYY-MM-DD规定在某年某月的某一天的特殊时刻执行该工作now 2 minutes从现在开始的minutes、hours、days、weeks执行4pm12am 00:00命令用法示例[rootnode1 ~]# at 12:12 warning: commands will be executed using /bin/sh at touch file111 #执行任务 at EOT #ctrl-D job 1 at Thu Oct 22 12:12:00 2026 #查看 [rootnode1 ~]# at -l 1 Thu Oct 22 12:12:00 2026 a root [rootnode1 ~]# atq 1 Thu Oct 22 12:12:00 2026 a root #删除 [rootnode1 ~]# at -d 1 #通过任务文件匹配任务 [rootnode1 ~]# at -f at.txt 12:12 warning: commands will be executed using /bin/sh job 3 at Thu Oct 22 12:12:00 2026[rootlocalhost ~]# wall haha wall: /dev/seat0: 没有那个文件或目录 来自 rootlocalhost.localdomain (pts/0) (Wed Oct 21 19:22:52 2026) 的广播 haha [rootlocalhost ~]# at now 2 minutes warning: commands will be executed using /bin/sh at wall 外面太吵了 at EOTEOT job 7 at Wed Oct 21 19:25:00 2026 [rootlocalhost ~]#配置文件程序运行参数文件程序按照约定格式读取从而决定怎么软件如何运行。/etc/at.allow白名单/etc/at.deny黑名单定义的任务文件存放位置/var/spool/at周期任务crontabcrontabs程序是否存在[rootnode1 at]# dnf list installed | grep crontabs crontabs.noarch 1.11-27.20190603git.el9_0 anacondacrond程序运行状态[rootnode1 at]# ps -aux | grep crond root 1142 0.0 0.2 223976 3676 ? Ss 18:48 0:00 /usr/sbin/crond -n root 3101 0.0 0.1 221812 2588 pts/0 S 19:58 0:00 grep --colorauto crond [rootnode1 at]# systemctl status crond ● crond.service - Command Scheduler Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; preset: enabled) Active: active (running) since Wed 2026-10-21 18:48:26 CST; 1h 10min ago Main PID: 1142 (crond) Tasks: 2 (limit: 10289) Memory: 1.5M (peak: 4.2M) CPU: 38ms CGroup: /system.slice/crond.service ├─1142 /usr/sbin/crond -n └─2748 /usr/sbin/anacron -s Oct 21 19:01:01 node1 run-parts[2738]: (/etc/cron.hourly) starting 0anacron Oct 21 19:01:01 node1 anacron[2748]: Anacron started on 2026-10-21 Oct 21 19:01:01 node1 anacron[2748]: Will run job cron.daily in 42 min. Oct 21 19:01:01 node1 anacron[2748]: Will run job cron.weekly in 62 min. Oct 21 19:01:01 node1 anacron[2748]: Will run job cron.monthly in 82 min. Oct 21 19:01:01 node1 anacron[2748]: Jobs will be executed sequentially Oct 21 19:01:01 node1 run-parts[2750]: (/etc/cron.hourly) finished 0anacron Oct 21 19:01:01 node1 CROND[2734]: (root) CMDEND (run-parts /etc/cron.hourly) Oct 21 19:43:01 node1 anacron[2748]: Job cron.daily started Oct 21 19:43:01 node1 anacron[2748]: Job cron.daily terminated [rootnode1 at]# systemctl is-active crond activecrontab周性任务管理命令用法参数解释示例-llist 查看定时任务crontab -l-eedit 编辑定时任务建议手动编辑crontab -e-i删除定时任务提示用户确认删除避免出错crontab -i-r删除定时任务移除/var/spool/cron/username文件crontab -r-u user指定用户执行任务root 可以管理普通用户计划任务crontab -u redhat -l代表意义分钟小时日期月份星期命令数字范围0-590-231-311-120-70和7表示周日执行的动作特使字符含义*任意时刻-表示时间范围1-5逗号分割时段 月 1,3*/数字指定时间间隔的频率如每3分钟执行一次crontab命令用法示例 ---用户级别定义单用户[rootnode1 at]# crontab -e no crontab for root - using an empty one crontab: installing new crontab [rootnode1 at]# crontab -l # 分 时 日 月 周 任务 * * * * * touch /crontab1 [rootnode1 at]# ll /crontab1 -rw-r--r--. 1 root root 0 Oct 21 20:06 /crontab1 [rootnode1 at]# #清空周期性任务 [rootnode1 at]# crontab -r [rootnode1 at]# crontab -l #周期性任务文件位置 [rootnode1 at]# ll /var/spool/cron/ total 4 -rw-------. 1 root root 25 Oct 21 20:09 root [rootnode1 at]# vim /var/spool/cron/root/etc/crontab 定义周期性任务系统级别可以是系统中任意用户定义周期性任务课堂练习定时发送邮件企业应用场景判断当前系统内存是否不足如果内存使用率超过80%需要给运维管理员以邮箱方式发送警告提示通过linux通过邮箱客户端s-nail 登录邮箱账户能够给其他邮箱用户发送邮件1.安装s-nail软件[rootnode1 at]# mkdir /sr0 [rootnode1 at]# mount /dev/sr0 /sr0 mount: /sr0: WARNING: source write-protected, mounted read-only. 2.[rootnode1 ~]# cat /etc/yum.repos.d/base.repo [AppStream] nameAppStream baseurlfile:///sr0/AppStream gpgcheck0 [BaseOS] nameBaseOS baseurlfile:///sr0/BaseOS gpgcheck0 3.[rootnode1 ~]#dnf install s-nail -y2.在该软件软件登录邮箱账户[rootnode1 ~]# tail -6 /etc/s-nail.rc ################################################## set fromlxx1xxxxxx163.com set smtpsmtp.163.com set smtp-auth-userlxx1xxxxx8163.com set smtp-auth-passwordVRxxxxx set smtp-authlogin3.发送邮件[rootnode1 ~]# echo 邮件内容 | mail -s 邮件主题 lxx1065372838163.com周期性触发定时发送邮件[rootnode1 ~]# crontab -e crontab: installing new crontab [rootnode1 ~]# crontab -l 26 * * * * echo 尽快处理问题 | mail -s 内存严重不足 lxx1065372838163.com第二章 Chrony服务器1.服务网络由一方按照约定方式给用户或者主机程序提供对应功能、数据、计算能力。服务响应方式被动方式OSI应用层数据传输的标准协议 ntp ssh http/https nfs/ftp表示层数据格式转换 编码会话层通信会话传输层 端口TCP 可靠传输 效率低UDP 不可靠 高网络层ip 源ip 目标ip 发送 主机地址标记数据链路层MAC物理接口ens160TCP/IP应用层 应用层协议 数据 chrony(ntp) http/https dns ssh chrony(ntp) nfs传输层 端口TCP 可靠传输 效率低网络层 ip sip dip物理接口 ens160配置文件守护进程daemon不依赖终端窗口进程在主机后台运行正常系统运行中不手动结束进程是实时运行的。Chrony时间服务时间管理命令hwclock-s 硬件时间到系统时间-w 系统时间到硬件时间date 月日时分年点秒-s 设置时间%F%Ttimedatectl set-timezone 时区软件程序 chrony/ntpnetstat 查看报文监听结果-t TCP-u UDPss 查看报文监听结果软件程序 chronyNTP network time protocal 网络时间协议守护进程daemon程序运行后再主机后运行且该程序进程不依赖终端设备不会因终端退出结束进程只有系统重启进程才会受影响NTP应用层协议 网络时间协议提供时间的查看的校验端口区分不同程序进行数据交互 ntp协议的端口是123/udp配置文件介绍/etc/chrony.conf客户端 pool 2.rhel.pool.ntp.org iburst # 池 时间服务器的主机名 初始化爆发 pool 3.rhel.pool.ntp.org iburst #上层服务器存储池 间服务器的主机名 服务端主机 # local stratum 10 #标记时间服务器主机的层级 1-16 # allow 192.168.0.0/16 #允许哪些客户端主机可以发起请求连接实验一自定义时间服务能够给客户端主机进行时间校时环境准备 S/Cserver (linux) --- 192.168.211.131client (linux) --- 192.168.211.1321.server主机1.判断chrony软件程序是否安装 2.判断软件是否启动 3.自定义软件功能ntp时间服务器 vim /etc/chrony.conf #pool 2.rhel.pool.ntp.org iburst #当前主机的时间就是标准时间不再通过上层服务器进行校时 allow 172.25.250.0/24 #哪些客户端主机发起校时请求 local stratum 10 #1-16 指定自定义时间服务区的层级 4.加载新的配置 systemctl restart chronyd 5.关闭防火墙selinux systemctl stop firewalld #立即停止防火墙 systemctl disable firewalld #取消防火墙的开机自启 systemctl status firewalld #查看防火墙服务状态 setenforce 0 #临时把selinux设置为permissive宽容模式 getenforce #查看selinux状态 Permissive 关闭 | enforce 开启 vim /etc/selinux/config SELINIUXPermissive #永久关闭2.client1.判断chrony软件程序是否安装 2.判断软件是否启动 3.自定义软件功能ntp时间客户端 vim /etc/chrony.conf pool 192.168.211.131 iburst 4.辨别时间校时是否成功 date 月日时分年月点秒 5.发起时间同步请求 systemctl restart chronyd 6.判断 [rootclient-146 ~]# date Fri Dec 12 10:10:38 AM CST 2025 [rootclient-146 ~]# date Fri Dec 12 10:10:39 AM CST 2025 [rootclient-146 ~]# date Sat Oct 24 11:46:23 AM CST 2026 [rootlocalhost ~]# chronyc sources -v # -v参数表示显示内容是否有解释 .-- Source mode ^ server, peer, # local clock. / .- Source state * current best, combined, - not combined, | / x may be in error, ~ too variable, ? unusable. || .- xxxx [ yyyy ] /- zzzz || Reachability register (octal) -. | xxxx adjusted offset, || Log2(Polling interval) --. | | yyyy measured offset, || \ | | zzzz estimated error. || | | \ MS Name/IP address Stratum Poll Reach LastRx Last sample ^* 203.107.6.88 2 6 177 8 18ms[ 19ms] /- 48ms ^*:server 类型当前最优同步源 Stratum 3三层时间服务器 Poll 6每64秒同步一次 Reach 377最近8次全部连通 377八进制表示8次连通八进制377 二进制 111111118位全1 LastRx 1212秒前刚收到回复 offest -423us本机比NTP服务器慢423微秒实验二主机通过外网时间服务器进行校时1.更改配置同步外网时间服务器 ntp.aliyun.com vim /etc/chrony.conf pool ntp.aliyun.com iburst 2.发起校时请求 systemctl restart chronyd 3.查看同步的服务器 [rootlocalhost ~]# chronyc sources -v # -v参数表示显示内容是否有解释 [rootclient-146 ~]# chronyc sources MS Name/IP address Stratum Poll Reach ^* 203.107.6.88 3 6 17 35ms [rootclient-146 ~]# ping ntp.aliyun.com PING ntp.aliyun.com(203.107.6.88) 56(84) byte 64 bytes from 203.107.6.88 (203.107.6.88): icms问题分析1.客户端主机和服务端主机网络互通 ping 2.包能不能正常请求 pool SERVERNAME iburst 3.服务端是否可以成功响应 allow 主机/主机网段 4.服务程序不能成功启动错误分析方式 [rootserver-142 ~]# journalctl -xeu chronyd.service # 早期启动的日志结果也会记录 时间不能同步的另外两个细节 两台主时区不一致 时间偏差过大第三章 SSH远程登陆服务1.概念2.telnet能够通过当前主机远程连接对端主机通过命令行接口进行控制管理23 / tcp 数据明文传输搭建telnet远程连接服务支持终端主机设备能够通过telnet进行远程连接server linux --- telnet-server --- 192.168.211.131clientwindows --- xshell --- 192.168.211.1server端 1.部署telnet服务 dnf install telnet-server -y 2.启动服务监听23/tcp端口等待客户端主机的请求连接 systemctl start telnet.socket client xshell 发起telnet连接 [C:\~]$ telnet 192.168.211.131 Connecting to 192.168.211.131:23... Connection established. To escape to local shell, press CtrlAlt]. Kernel 5.14.0-570.12.1.el9_6.x86_64 on an x86_64 localhost login: root Password: Last login: Sat Oct 24 16:07:50 from ::ffff:192.168.211.1 [rootnodel -]# dnf install wireshark -y 通过主机图形化终端启动wireshark程序 [rootnodel ~]# wireshark 16:10:23.189 Main Info Warning: Ignoring XDG_SESSION_TYPEWayland on Gnome. Use QT_OPALPLATFORMwayland to run on Wayland anyway.3.ssh secure shell能够通过当前主机远程连接对端主机通过命令行接口进行控制管理22 / tcp 数据加密传输实验二部署ssh远程openssh-clients-8.7p1-45.el9.x86_64 客户端程序名-----sshopenssh-server-8.7p1-45.el9.x86_64 服务程序名查看ssh程序网络监听信息 [rootlocalhost ~]# ss -tunlp | grep ssh tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:((sshd,pid1154,fd3)) tcp LISTEN 0 128 [::]:22 [::]:* users:((sshd,pid1154,fd4)) [rootlocalhost ~]# netstat -tunlp | grep ssh tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1154/sshd: /usr/sbi tcp6 0 0 :::22 :::* LISTEN 1154/sshd: /usr/sbi 查看指定端口监听的程序 [rootlocalhost ~]# lsof -i:22 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd 1154 root 3u IPv4 19184 0t0 TCP *:ssh (LISTEN) sshd 1154 root 4u IPv6 19186 0t0 TCP *:ssh (LISTEN)安全加固管理vim /etc/ssh/sshd_config Port 2222 AllowUsers 用户名1 用户名2 vim /etc/ssh/sshd_config.d/01-permitrootlogin.conf PermitRootLogin no 秘钥验证配置文件初始化重装软件程序编辑配置文件时记得对配置文件进行备份主配置/etc/ssh/sshd_conf/etc/ssh/ssh_conf --- 客户端的配置文件子配置文件/etc/ssh/sshd_config.d/*.conf自配置文件名的数值越小级别越高优先读取SSH建立远程连接的原理1.tcp三次握手2.版本协商3.对称算法的协商阶段数据加密算法的协商4.身份验证身份伪装数据泄露加密算法对称加密算法加密 解密用的是同一把秘钥 A秘钥---123? --- 加密*............---B 秘钥秘钥不允许发送数据双向传输数据传输的效率较高非对称加密算法加密解密用的是不同秘钥 私钥 --- 数据解密 公钥 --- 数据加密私钥留到制作端主机不允许公开发送公钥公开发送所有用户都能够获取数据仅支持单向传输身份验证A私钥 B公钥公钥密钥交换算法Diffie-HellmanDH密钥交换算法 ----非对称算法服务端验证客户端身份通过秘钥验证服务验证客户端主机身份1.客户端提前将自己的公钥(如~/.ssh/id_rsa.pub)上传到服务器的~/.ssh/authorized_keys 文件中;2.验证时服务器生成一个随机字符串用服务端公钥加密后发送给客户端;3.客户端用自己的私钥解密得到随机字符串再用会话密钥加密后返回给服务器;4.服务器解密并对比原始随机字符串一致则验证通过。宿舍远程实现秘钥验证免密登录预处理:2台机子都恢复快照第一步:定位客户端制作公私钥对客户端:192.168.48.128服务端:192.168.48.130[rootnodel ~]# ssh-keygen -t rsa #一路回车第二步:定位客户端将公钥上传到服务器端[rootnodel ~]# ssh-copy-id root192.168.48.130 # 输入服务端的账户及IP地址 The authenticity of host 192.168.48.130 (192.168.48.130) cant be established. ED25519 key fingerprint is SHA256:K7nvJFkfIhp9YytEGR44wLbTfpB0Y52oVou0UdG6nc. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes # 输Ayes /usr/bin/ssh-copy-id: INFo: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root192.168.48.130s password: #输入服务端root账户的的密码 Number of key(s) added: 1 Now try logging into the machine, with: ssh root192.168.48.130 and check to make sure that only the key(s) you wanted were added. #注意:客户端将公钥上传到服务器端后服务器端的/root/.ssh/authorized_keys文件会存储客户端的公钥数据第三步:客户端测试[rootnodel ~]# ssh root192.168.48.130 Activate the web console with: systemctl enable --now cockpit.socket Register this system with Red Hat Insights: insights-client --register Create an account or view all your systems at https://red.ht/insights-dashboard Last login: Wed Mar 22 11:31:31 2023 [rootserver ~]#实验三 通过window---xshell和服务器主机进行秘钥验证
返回列表
PREV
查看更多资讯
NEXT
返回资讯列表