Linux 基础学习训练教材 - CentOS 8.x

课程问题参考解答

单纯提供一个相对的解答,并不是标准答案!

最近更新时间: 2020/06/11

单纯就是个解答的参考,写完之后再来这边查查看答案跟你想的一样不一样!?

第 11 堂课

  • 例题 11.1.1-1:
    1. con-name:该界面的连接名称,可以被修改,只是一个连接的名称,通常取名为与适配器名称相同。
    2. ifname:就是适配器的名称,如本教材的 ens3。
    3. type:达成连接的类型,包括有以太网路、wifi 无线网络、pppoe 拨接、bluetooth 蓝芽等等类型。
  • 例题 11.1.1-2:
    1. 设置属于自己的网络连接,其实重点就是老师给予的 IP 地址与网络参数要正确喔!
      # 先设置好网络参数,所有的参数通通设置好再激活!
      [root@localhost ~]# nmcli connection modify ens3 ipv4.method manual \
      > ipv4.addresses 172.16.60.200/16 ipv4.gateway 172.16.200.254 ipv4.dns 168.95.1.1
      # 比较重要的,就是上面反白的部份!每个同学都要不一样!
      
      [root@localhost ~]# nmcli connection up ens3
      [root@localhost ~]# hostnamectl set-hostname station200.centos
      
    2. 接下来则是检查上述的设置是否能够顺利的生效!非常重要的测试喔!
      # a. 先经过 nmcli 来检查刚刚设置的是否正确的生效了!
      [root@station200 ~]# nmcli connection show ens3
      connection.id:                          ens3
      connection.interface-name:              ens3
      connection.autoconnect:                 是
      ipv4.method:                            manual
      ipv4.dns:                               168.95.1.1
      ipv4.addresses:                         172.16.60.200/16
      ipv4.gateway:                           172.16.200.254
      IP4.ADDRESS[1]:                         172.16.60.200/16
      IP4.GATEWAY:                            172.16.200.254
      IP4.DNS[1]:                             168.95.1.1
      # 比较需要注意的,大概就是这几个设置项目与实际运作的项目了!
      
      # b.1. 检查各种消息,先找到上述 ipv4.gateway 后面接的那个 IP,直接 ping 她!
      [root@station200 ~]# ping 172.16.200.254
      PING 172.16.200.254 (172.16.200.254) 56(84) bytes of data.
      64 bytes from 172.16.200.254: icmp_seq=1 ttl=64 time=0.302 ms
      64 bytes from 172.16.200.254: icmp_seq=2 ttl=64 time=0.301 ms
      64 bytes from 172.16.200.254: icmp_seq=3 ttl=64 time=0.315 ms
      ^C   <==这里使用 [crtl]+c 中断指令
      --- 172.16.200.254 ping statistics ---
      3 packets transmitted, 3 received, 0% packet loss, time 70ms
      rtt min/avg/max/mdev = 0.301/0.306/0.315/0.006 ms
      
      # b.2. 如上所示,要出现 time=xxx ms 的字样,才是真的连到该通信闸喔!很重要!
      
      # b.3. 那个 ms 指的是 10-3 秒,就是 0.001 秒,很小的单位。
      # 意义是,将消息在 Server/Client 两端发送所经过的时间,越小越好!
      
      # c. 使用 dig 可以观察 DNS 由主机名称找到 IP 的信息。
      [root@station200 ~]# dig www.google.com
      
      ; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el8 <<>> www.google.com
      ;; global options: +cmd
      ;; Got answer:
      ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60556
      ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
      
      ;; OPT PSEUDOSECTION:
      ; EDNS: version: 0, flags:; udp: 4096
      ; COOKIE: 15d71555225eb80855fcf4d25ec0df934fd9517a795492fb (good)
      ;; QUESTION SECTION:
      ;www.google.com.                        IN      A  <==指的是 Address 的缩写
      
      ;; ANSWER SECTION:
      www.google.com.         104     IN      A       172.217.27.132  <==找到正确的 IP 啰!
      
      ;; Query time: 4 msec
      ;; SERVER: 168.95.1.1#53(168.95.1.1)   <==我们是向这部主机询问的结果!
      ;; WHEN: 日  5月 17 14:54:08 CST 2020
      ;; MSG SIZE  rcvd: 87
      # 通过 QUESTION 分析问题,通过 ANSWER 回答问题,通过 SERVER 确认哪个服务器的回应,
      # 所以,当然由 ANSWER 回答了我们的问题,得到了上述 172.217.27.132 这个 IP 地址。
      
      # d. 要找到本机的主机名称,通常有两个常用的指令如下:
      [root@station200 ~]# hostname
      station200.centos
      [root@station200 ~]# hostnamectl
         Static hostname: station200.centos
               Icon name: computer-vm
                 Chassis: vm
              Machine ID: 502dbaaf2a074134909a59ef9ab651c1
                 Boot ID: b2952f724af0470cafc231c72afbcf9e
          Virtualization: kvm
        Operating System: CentOS Linux 8 (Core)
             CPE OS Name: cpe:/o:centos:centos:8
                  Kernel: Linux 4.18.0-147.el8.x86_64
            Architecture: x86-64
      
      [root@station200 ~]# cat /etc/hostname
      station200.centos
      # 事实上,主机的名称记载在 /etc/hostname 噜!
      
  • 例题 11.1.2-1:
    1. 先通过 --help 或 man 等方式,查找到时区列表的功能,之后列出所有时区列表
      [root@station200 ~]# timedatectl --help
      timedatectl [OPTIONS...] COMMAND ...
      
      Query or change system time and date settings.
      .......
      
      Commands:
        status                   Show current time settings
        show                     Show properties of systemd-timedated
        set-time TIME            Set system time
        set-timezone ZONE        Set system time zone
        list-timezones           Show known time zones
        set-local-rtc BOOL       Control whether RTC is in local time
        set-ntp BOOL             Enable or disable network time synchronization
      .......
      
      [root@station200 ~]# timedatectl list-timezones
      Africa/Abidjan
      Africa/Accra
      Africa/Addis_Ababa
      ......
      Pacific/Tongatapu
      Pacific/Wake
      Pacific/Wallis
      UTC
      lines 383-426/426 (END)
      
      可以找到标准时区的 UTC,但是找不到日本时区喔!
    2. Linux 标准时区其实列在 /usr/share/zoneinfo 目录内,所以我们也到该目录去找找:
      [root@station200 ~]# find /usr/share/zoneinfo -name '*Japan*'
      /usr/share/zoneinfo/posix/Japan
      /usr/share/zoneinfo/right/Japan
      /usr/share/zoneinfo/Japan
      
      [root@station200 ~]# find /usr/share/zoneinfo -name '*Taipei*'
      /usr/share/zoneinfo/Asia/Taipei
      /usr/share/zoneinfo/posix/Asia/Taipei
      /usr/share/zoneinfo/right/Asia/Taipei
      
      其实是有日本时区喔!等等使用 /usr/share/zoneinfo/Japan 来检查看看!
    3. 目前的台湾、日本时间差异多少呢?检查看看:
      [root@station200 ~]# date
      日  5月 17 15:23:22 CST 2020
      
      [root@station200 ~]# timedatectl set-timezone Japan
      [root@station200 ~]# date
      日  5月 17 16:23:35 JST 2020
      
      原来时间差异 1 个小时喔!台湾与日本。
    4. 继续将时间改为格林威治标准时间 (UTC/GMT) 看看!
      [root@station200 ~]# date
      日  5月 17 16:25:49 JST 2020
      [root@station200 ~]# timedatectl set-timezone UTC
      [root@station200 ~]# date
      日  5月 17 07:25:55 UTC 2020
      
      格林威治时间比日本时间慢了 9 个小时啊~
    5. 将时间改回来啊~
      [root@station200 ~]# timedatectl set-timezone Asia/Taipei
      [root@station200 ~]# date
      日  5月 17 15:27:14 CST 2020
      [root@station200 ~]# man timedatectl
      [root@station200 ~]# timedatectl set-time "2020-05-17 15:28:20"
      [root@station200 ~]# date
      日  5月 17 15:28:22 CST 2020
      
  • 例题 11.1.4-1:
    1. 先确认系统服务的相关数据
      [root@station200 ~]# firewall-cmd --get-services
      RH-Satellite-6 amanda-client amanda-k5-client amqp amqps apcupsd audit 
       bacula bacula-client bb bgp bitcoin bitcoin-rpc bitcoin-testnet 
       bitcoin-testnet-rpc bittorrent-lsd ceph ceph-mon cfengine cockpit 
       ......
      
      [root@station200 ~]# firewall-cmd --permanent --list-services
      cockpit dhcpv6-client http ssh
      
      # 底下先删除所有的服务
      [root@station200 ~]# firewall-cmd --permanent --remove-service=cockpit
      success
      [root@station200 ~]# firewall-cmd --permanent --remove-service=http
      success
      [root@station200 ~]# firewall-cmd --permanent --remove-service=dhcpv6-client
      success
      [root@station200 ~]# firewall-cmd --permanent --remove-service=ssh
      success
      [root@station200 ~]# firewall-cmd --permanent --list-services
      
      # 再加入需要的服务啰!
      [root@station200 ~]# firewall-cmd --permanent --add-service=http
      success
      [root@station200 ~]# firewall-cmd --permanent --add-service=https
      success
      [root@station200 ~]# firewall-cmd --permanent --add-service=ssh
      success
      [root@station200 ~]# firewall-cmd --permanent --add-service=ftp
      success
      [root@station200 ~]# firewall-cmd --permanent --list-services
      ftp http https ssh
      
    2. 针对非服务的其他设置来说,规则比较麻烦!需要额外通过 firewalld.richlanguage 来查找才可以!
      [root@station200 ~]# man firewalld.richlanguage
      EXAMPLES
             These are examples of how to specify rich language rules. This format
             (i.e. one string that specifies whole rule) uses for example firewall-cmd
             --add-rich-rule (see firewall-cmd(1)) as well as D-Bus interface.
      .......
         Example 3
             Allow new IPv4 connections from address 192.168.0.0/24 for service tftp
             and log 1 per minutes using syslog
      
                 rule family="ipv4" source address="192.168.0.0/24" service name="tftp" 
                 log prefix="tftp" level="info" limit value="1/m" accept
      .......
         Example 6
             White-list source address to allow all connections from 192.168.2.2
      
                 rule family="ipv4" source address="192.168.2.2" accept
      .......
      
      [root@station200 ~]# firewall-cmd --permanent \
      > --add-rich-rule="rule family='ipv4' source address='172.16.100.254' accept"
      
      [root@station200 ~]# firewall-cmd --permanent --add-rich-rule="rule family='ipv4' \
      > source address='172.16.0.0/16' service name='ssh' accept"
      
      [root@station200 ~]# firewall-cmd --permanent --list-all
      public
        target: default
        icmp-block-inversion: no
        interfaces:
        sources:
        services: ftp http https ssh
        ports:
        protocols:
        masquerade: no
        forward-ports:
        source-ports:
        icmp-blocks:
        rich rules:
              rule family="ipv4" source address="172.16.100.254" accept
              rule family="ipv4" source address="172.16.0.0/16" service name="ssh" accept
      
    3. 直接将 firewalld 重新启动,规则就能够立刻更新了!
      [root@station200 ~]# firewall-cmd --list-all
      public (active)
        target: default
        icmp-block-inversion: no
        interfaces: ens3
        sources:
        services: cockpit dhcpv6-client http ssh
        ports:
        protocols:
        masquerade: no
        forward-ports:
        source-ports:
        icmp-blocks:
        rich rules:
      
      [root@station200 ~]# systemctl restart firewalld.service
      [root@station200 ~]# firewall-cmd --list-all
      public (active)
        target: default
        icmp-block-inversion: no
        interfaces: ens3
        sources:
        services: ftp http https ssh
        ports:
        protocols:
        masquerade: no
        forward-ports:
        source-ports:
        icmp-blocks:
        rich rules:
              rule family="ipv4" source address="172.16.100.254" accept
              rule family="ipv4" source address="172.16.0.0/16" service name="ssh" accept
      
  • 例题 11.2.1-1:
    1. 进行环境的建置:
      [root@station200 ~]# cd /dev/shm
      [root@station200 shm]# mkdir zip
      [root@station200 shm]# cd zip
      [root@station200 zip]# ll -Sr /etc
      .....
      -rw-r--r--.  1 root root     60352  5月 11  2017 mime.types
      -rw-r--r--.  1 root root     67225  4月 13 08:53 ld.so.cache
      -rw-r--r--.  1 root root    692241  9月 10  2018 services
      
      [root@station200 zip]# cp /etc/services filename.1
      [root@station200 zip]# cp /etc/services filename.2
      [root@station200 zip]# cp /etc/services filename.3
      [root@station200 zip]# cp /etc/services filename.4
      [root@station200 zip]# ll
      -rw-r--r--. 1 root root 692241  5月 17 16:39 filename.1
      -rw-r--r--. 1 root root 692241  5月 17 16:39 filename.2
      -rw-r--r--. 1 root root 692241  5月 17 16:39 filename.3
      -rw-r--r--. 1 root root 692241  5月 17 16:39 filename.4
      
    2. 开始处理压缩功能
      [root@station200 zip]# time gzip filename.1
      
      real    0m0.029s
      user    0m0.027s
      sys     0m0.002s
      [root@station200 zip]# time bzip2 filename.2
      
      real    0m0.069s
      user    0m0.063s
      sys     0m0.002s
      [root@station200 zip]# time xz filename.3
      
      real    0m0.381s
      user    0m0.337s
      sys     0m0.009s
      
      [root@station200 zip]# man xz
             -T threads, --threads=threads
      
      [root@station200 zip]# time xz -T 2 --block-size=128K filename.4
      
      real    0m0.212s
      user    0m0.358s
      sys     0m0.024s
      
      [root@station200 zip]# ll
      -rw-r--r--. 1 root root 142551  5月 17 16:39 filename.1.gz
      -rw-r--r--. 1 root root 129788  5月 17 16:39 filename.2.bz2
      -rw-r--r--. 1 root root 105872  5月 17 16:39 filename.3.xz
      -rw-r--r--. 1 root root 113896  5月 17 16:39 filename.4.xz
      
      基本上,xz 通过多线程进行压缩时,最好给予一个固定的 block size 作为每个线程分到的量,然后个别进行压缩, 这样的效率会好上很多。因为我们的文件容量不大,因此采用比较小的 128K 作为切割,你可以看到 user 的时间花费大约是 0.358s, 跟缺省的 xz 单线程没有差很多!不过,因为用到两颗 CPU,那个 0.358s 其实是两颗 CPU 使用时间的总和!所以, 事实上人类时间花费只有 0.212s,是比单线程好很多的!另外,因为我们上面测试的是小型的文件,所以, xz 的多线程效果不明显。如果是大型的文件,使用 xz 的多线程,其速度性能要比其他两个好喔!
    3. 开始解压缩:
      [root@station200 zip]# time gzip -d filename.1.gz
      
      real    0m0.007s
      user    0m0.006s
      sys     0m0.001s
      [root@station200 zip]# time bzip2 -d filename.2.bz2
      
      real    0m0.027s
      user    0m0.023s
      sys     0m0.004s
      [root@station200 zip]# time xz -d filename.3.xz
      
      real    0m0.016s
      user    0m0.014s
      sys     0m0.001s
      
      [root@station200 zip]# ll
      -rw-r--r--. 1 root root 692241  5月 17 16:39 filename.1
      -rw-r--r--. 1 root root 692241  5月 17 16:39 filename.2
      -rw-r--r--. 1 root root 692241  5月 17 16:39 filename.3
      -rw-r--r--. 1 root root 113896  5月 17 16:39 filename.4.xz
      
    4. 开始使用 gzip 压缩
      [root@station200 zip]# gzip -c filename.1 > filename.1.gz
      [root@station200 zip]# ll filename.1*
      -rw-r--r--. 1 root root 692241  5月 17 16:39 filename.1
      -rw-r--r--. 1 root root 142551  5月 17 16:49 filename.1.gz
      
  • 例题 11.2.2-1:
    1. 先来查找如何解压缩:
      # 解压缩的方式,当然就是 -x 这个支持项目
      
      # 先在本目录底下解开:
      [root@station200 zip]# ll
      -rw-r--r--. 1 root root 3726192  5月 17 20:15 etc.tar.xz
      
      [root@station200 zip]# tar -Jx -f etc.tar.xz
      [root@station200 zip]# ll
      drwxr-xr-x. 135 root root    5280  5月 17 15:47 etc
      -rw-r--r--.   1 root root 3726192  5月 17 20:15 etc.tar.xz
      
      # 在非本目录解开,可以通过 -C 来处理
      [root@station200 zip]# ll -d /tmp/etc*
      ls: 无法访问 '/tmp/etc*': 没有此一文件或目录
      
      [root@station200 zip]# tar -Jx -f etc.tar.xz -C /tmp
      [root@station200 zip]# ll -d /tmp/etc*
      drwxr-xr-x. 135 root root 8192  5月 17 15:47 /tmp/etc
      
    2. 由于 xz 可以支持多线程,同时现今 CPU 多有多内核,因此,可以尝试使用 xz 的支持来处理喔!
      # 先测试单线程的时间
      [root@station200 zip]# time tar -Jc -f etc2.tar.xz /etc
      tar: 从成员名称中移除前端的 /
      
      real    0m15.025s
      user    0m14.779s
      sys     0m0.138s
      
      # 使用管线的方式,来处理一下数据的压缩:
      [root@station200 zip]# tar -Jc -f - /etc | cat > etc3.tar.xz
      [root@station200 zip]# ll etc*tar*
      -rw-r--r--. 1 root root 3726192  5月 17 20:26 etc2.tar.xz
      -rw-r--r--. 1 root root 3726192  5月 17 20:27 etc3.tar.xz
      -rw-r--r--. 1 root root 3726192  5月 17 20:15 etc.tar.xz
      
      # 使用多线程来处理看看:
      [root@station200 zip]# cat /proc/cpuinfo  | grep processor
      processor       : 0
      processor       : 1
      # 出现几行就是有几颗 CPU 的意思。不过,这里应该指的是线程喔!
      
      [root@station200 zip]# time tar -c -f - /etc | xz -c > etc4.tar.xz
      tar: 从成员名称中移除前端的 /
      
      real    0m15.405s
      user    0m15.281s
      sys     0m0.129s
      
      [root@station200 zip]# time tar -c -f - /etc | xz -T 2 --block-size=1M -c > etc4.tar.xz
      tar: 从成员名称中移除前端的 /
      
      real    0m6.788s
      user    0m13.428s
      sys     0m0.073s
      # 你只要看 real 项目就好,真的速度有差喔!虽然压缩后的容量会稍微放大!
      
      [root@station200 zip]# ll -d etc*
      drwxr-xr-x. 135 root root    5280  5月 17 15:47 etc
      -rw-r--r--.   1 root root 3726192  5月 17 20:26 etc2.tar.xz
      -rw-r--r--.   1 root root 3726192  5月 17 20:27 etc3.tar.xz
      -rw-r--r--.   1 root root 3950316  5月 17 21:24 etc4.tar.xz
      -rw-r--r--.   1 root root 3726192  5月 17 20:15 etc.tar.xz
      
  • 例题 11.2.3-1:
    [root@station200 ~]# mkdir /backups
    [root@station200 ~]# cd /backups/
    [root@station200 backups]# vim backup_system.sh
    #!/bin/bash
    
    mysource="/etc /home /root /var/spool/mail /var/spool/cron /var/spool/at"
    mytarget="/backups/backup_system_$( date +%Y_%m_%d ).tar.gz"
    
    tar -zc -f ${mytarget} ${mysource}
    
    [root@station200 backups]# sh backup_system.sh
    tar: 从成员名称中移除前端的 /
    tar: 从硬式链接目标中移除前端的 /
    
    [root@station200 backups]# ll
    -rw-r--r--. 1 root root 8094681  5月 17 21:33 backup_system_2020_05_17.tar.gz
    -rw-r--r--. 1 root root     184  5月 17 21:33 backup_system.sh
    
  • 例题 11.3.1-1:
    # 某些小型系统确实不会启动 atd 的,所以,如果发现没启动,就启动它即可!
    [root@station200 backups]# systemctl restart atd
    [root@station200 backups]# systemctl enable atd
    
  • 例题 11.3.1-2:
    [root@station200 backups]# at 17:00 2020-12-31
    warning: commands will be executed using /bin/sh
    at> wall 'This system will shutdown at 17:30. Please backup your work and logout system'
    at> sleep 30m
    at> poweroff
    at> <EOT>
    job 2 at Thu Dec 31 17:00:00 2020
    
  • 例题 11.3.1-3:
    [root@station200 ~]# at now + 4 hours
    warning: commands will be executed using /bin/sh
    at> poweroff
    at> <EOT>
    job 3 at Mon May 18 02:46:00 2020
    
  • 例题 11.3.2-1:
    因为 student 要运行两个 crontab 的例行工作调度,所以,需要写两行喔!
    [student@station200 22:50 2 ~]$ crontab -e
    0   11 * * * /usr/sbin/ip addr show > /home/student/myipshow.txt
    */10 * * * * ip addr show > /dev/shm/myip
    
    [student@station200 22:52 3 ~]$ crontab -l
    0   11 * * * /usr/sbin/ip addr show > /home/student/myipshow.txt
    */10 * * * * ip addr show > /dev/shm/myip
    
  • 例题 11.3.2-2:
    [root@station200 ~]# chmod 744 /backups/backup_system.sh
    [root@station200 ~]# ll /backups/backup_system.sh
    -rwxr--r--. 1 root root 184  5月 17 21:33 /backups/backup_system.sh
    
    [root@station200 ~]# cd /etc/cron.monthly/
    [root@station200 cron.monthly]# ln /backups/backup_system.sh .
    [root@station200 cron.monthly]# ll
    -rwxr--r--. 2 root root 184  5月 17 21:33 backup_system.sh
    
  • 例题 11.4 课后练习
    1. 进行课堂上面的实做过程数据的清理!
      # a. 探查一下有多少 at job 存在!
      [root@station200 ~]# atq
      1       Mon May 18 11:00:00 2020 a root
      2       Thu Dec 31 17:00:00 2020 a root
      3       Mon May 18 02:46:00 2020 a root
      
      [root@station200 ~]# ll /var/spool/at
      总计 12
      -rwx------. 1 root root 3173  5月 17 21:40 a0000101944cb4
      -rwx------. 1 root root 3234  5月 17 21:44 a0000201994afc
      -rwx------. 1 root root 3136  5月 17 22:46 a0000301944ac6
      drwx------. 2 root root    6  5月 11  2019 spool
      # 可以看到三个文件!这三个文件就是 at job 的实际设置信息!
      
      # b. 查看有没有 poweroff 时,可以这样做:
      [root@station200 ~]# at -c 1 | tail
      PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin; export PATH
      HISTSIZE=1000; export HISTSIZE
      LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
      cd /backups || {
               echo 'Execution directory inaccessible' >&2
               exit 1
      }
      ${SHELL:-/bin/sh} << 'marcinDELIMITER0a17ade1'
      ip addr show &> /home/student/myipshow.txt
      marcinDELIMITER0a17ade1
      
      [root@station200 ~]# at -c 2 | tail
      LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
      cd /backups || {
               echo 'Execution directory inaccessible' >&2
               exit 1
      }
      ${SHELL:-/bin/sh} << 'marcinDELIMITER0a5b0fd2'
      wall 'This system will shutdown at 17:30. Please backup your work and logout system'
      sleep 30m
      poweroff
      marcinDELIMITER0a5b0fd2
      
      [root@station200 ~]# at -c 3 | tail
      PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin; export PATH
      HISTSIZE=1000; export HISTSIZE
      LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
      cd /root || {
               echo 'Execution directory inaccessible' >&2
               exit 1
      }
      ${SHELL:-/bin/sh} << 'marcinDELIMITER05b75d9b'
      poweroff
      marcinDELIMITER05b75d9b
      # 所以看起来只有 2, 3 号有关机任务,所以,取消这两个即可!
      
      [root@station200 ~]# atrm 2
      [root@station200 ~]# atrm 3
      [root@station200 ~]# atq
      1       Mon May 18 11:00:00 2020 a root
      
      # c. 检查一下 crond 这个服务的纪录档!
      [root@station200 ~]# tail /var/log/cron
      May 17 22:52:25 www crontab[22921]: (student) LIST (student)
      May 17 22:57:01 www crond[1138]: (*system*) RELOAD (/etc/crontab)
      May 17 22:58:01 www crond[1138]: (*system*) RELOAD (/etc/crontab)
      May 17 23:00:02 www CROND[23056]: (student) CMD (ip addr show > /dev/shm/myip)
      May 17 23:00:02 www CROND[23031]: (student) CMDOUT (/bin/sh: ip: command not found)
      May 17 23:01:01 www CROND[23087]: (root) CMD (run-parts /etc/cron.hourly)
      May 17 23:01:01 www run-parts[23087]: (/etc/cron.hourly) starting 0anacron
      May 17 23:01:01 www run-parts[23087]: (/etc/cron.hourly) finished 0anacron
      May 17 23:10:01 www CROND[23211]: (student) CMD (ip addr show > /dev/shm/myip)
      May 17 23:10:01 www CROND[23183]: (student) CMDOUT (/bin/sh: ip: command not found)
      # 确实有运行喔!不过指令有点问题!应该要用绝对路径比较好!
      
      # d. 其实就是查看一般用户的 crontab 设置
      [root@station200 ~]# ll /var/spool/cron
      -rw-------. 1 student student 107  5月 17 22:52 student
      
      [root@station200 ~]# cat /var/spool/cron/student
      0   11 * * * /usr/sbin/ip addr show > /home/student/myipshow.txt
      */10 * * * * ip addr show > /dev/shm/myip
      
      # e. 帮一般帐号处理 crontab 的方法:
      [root@station200 ~]# crontab -e -u student
      0   11 * * * /usr/sbin/ip addr show > /home/student/myipshow.txt
      #*/10 * * * * ip addr show > /dev/shm/myip
      
      [root@station200 ~]# crontab -l -u student
      
修改历史:
  • 2020/02/25:尝试直接在课程中加入解答,让大家有个参考依据。不过,没事不要来看啊!
  • 2020/03/10:加入了第三章的后课练习部份。
2020/03/02 以来统计人数
计数器
其他链接
环境工程模式篇
鸟园讨论区
鸟哥旧站

今日 人数统计
昨日 人数统计
本月 人数统计
上月 人数统计