一、配置仓库
准备工作
# 本地源
[root@localhost yum.repos.d] # cat base.repo
[base]
name = base
baseurl = file:///mnt/BaseOS
gpgcheck = 0
[app]
name = appstream
baseurl = file:///mnt/AppStream
gpgcheck = 0
1.建立网络源
在/etc/yum.repos.d/下配置.repo文件
[root@client ~]# cd /etc/yum.repos.d/
[root@client ~]# vim aliyun.repo
[appstream]
name=appstream
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/AppStream/x86_64/os/
gpgcheck=0
[baseos]
name=baseos
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/BaseOS/x86_64/os/
gpgcheck=0
配置详解:
由于是网络源,baseurl中的信息是网址信息
这里用着阿里云的centos镜像源(阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区)
由于用着Redhat9的镜像,因此这里选择centos stream源
进入下载地址后选择9-stream/
得到的链接需删除 os/ 后的部分得到https://mirrors.aliyun.com/centos-stream/9-stream/BaseOS/x86_64/os/
这种形式的网络地址就是网络源的baseos的baseurl中的信息
同样的,appstream的baseurl:https://mirrors.aliyun.com/centos-stream/9-stream/AppStream/x86_64/os/
在yum.repos.d下能查看到:
2.验证是否成功
[root@client yum.repos.d]# yum install gcc
网络源建立成功!
二、at练习
1.下载at
[root@client yum.repos.d]# yum install at
2.at命令详解
命令格式: at [参数] [时间]
参数:
-m 当任务完成之后,即使没有标准输出,将给用户发送邮件
-l atq的别名,可列出目前系统上面的所有该用户的at调度
-d atrm的别名,可以取消一个在at调度中的工作
-v 使用较明显的时间格式,列出at调度中的任务列表
-c 可以列出后面接的该项工作的实际命令内容
-f 从文件中读取作作业
时间格式:
HH:MM 在今天的HH小时MM分钟执行,如果今天的这个时间点已经过了,则明
天执行
HH:MM YYYY-MM-DD 强制规定在某年某月的某一天的特殊时刻进行该工作
now + 2 minutes 从现在开始几分钟minutes, hours, days, or weeks
# 定义三分钟之后显示 hello
三、cron练习
crontab命令详解
[root@client ~]# crontab --help
crontab: 不适用的选项 -- -
crontab: usage error: unrecognized option
Usage:
crontab [options] file
crontab [options]
crontab -n [hostname]
Options:
-u <user> define user
-e edit user's crontab
-l list user's crontab
-r delete user's crontab
-i prompt before deleting
-n <host> set host in cluster to run users' crontabs
-c get host in cluster to run users' crontabs
-T <file> test a crontab file syntax
-s selinux context
-V print version and exit
-x <mask> enable debugging
Default operation is replace, per 1003.2
1.开启cron
[root@client ~]# systemctl status crond
2. 每天早上9点整说good morning
[root@client ~]# crontab -e
[root@client ~]# crontab -l
0 9 * * * wall "good morning"
[root@client ~]# cat /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