单纯提供一个相对的解答,并不是标准答案!
单纯就是个解答的参考,写完之后再来这边查查看答案跟你想的一样不一样!?
# 先设置好网络参数,所有的参数通通设置好再激活! [root@localhost ~]# nmcli connection modify ens3 ipv4.method manual \ > ipv4.addresses 172.16.60.111/16 ipv4.gateway 172.16.200.254 ipv4.dns 168.95.1.1 # 比较重要的,就是上面反白的部份!每个同学都要不一样! [root@localhost ~]# nmcli connection up ens3 [root@localhost ~]# hostnamectl hostname station111.rockylinux
# a. 先经过 nmcli 来检查刚刚设置的是否正确的生效了! [root@station111 ~]# 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.111/16 ipv4.gateway: 172.16.200.254 IP4.ADDRESS[1]: 172.16.60.111/16 IP4.GATEWAY: 172.16.200.254 IP4.DNS[1]: 168.95.1.1 # 比较需要注意的,大概就是这几个设置项目与实际运作的项目了! # b.1. 检查各种消息,先找到上述 ipv4.gateway 后面接的那个 IP,直接 ping 她! [root@station111 ~]# 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@station111 ~]# 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@station111 ~]# hostname station111.rockylinux [root@station111 ~]# hostnamectl Static hostname: station200.rockylinux Icon name: computer-vm Chassis: vm Machine ID: d587a2c04fbb458e8015aef30df28fec Boot ID: d47cd3298e1c4e919003299b9cf413be Virtualization: kvm Operating System: Rocky Linux 9.1 (Blue Onyx) CPE OS Name: cpe:/o:rocky:rocky:9::baseos Kernel: Linux 5.14.0-162.12.1.el9_1.0.2.x86_64 Architecture: x86-64 Hardware Vendor: Red Hat Hardware Model: KVM [root@station111 ~]# cat /etc/hostname station111.rockylinux # 事实上,主机的名称记载在 /etc/hostname 噜!
[root@station111 ~]# 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@station111 ~]# timedatectl list-timezones Africa/Abidjan Africa/Accra Africa/Addis_Ababa ...... Pacific/Tongatapu Pacific/Wake Pacific/Wallis UTC lines 383-426/426 (END)可以找到标准时区的 UTC,但是找不到日本时区!要用东京 (Tokyo) 就可以找到!
[root@station111 ~]# find /usr/share/zoneinfo -name '*Japan*' /usr/share/zoneinfo/posix/Japan /usr/share/zoneinfo/right/Japan /usr/share/zoneinfo/Japan [root@station111 ~]# 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 来检查看看!
[root@station111 ~]# date Mon May 1 09:40:53 PM CST 2023 [root@station111 ~]# timedatectl set-timezone Asia/Tokyo [root@station111 ~]# date Mon May 1 10:41:27 PM JST 2023原来时间差异 1 个小时喔!台湾与日本东京!
[root@station111 ~]# date Mon May 1 10:42:01 PM JST 2023 [root@station111 ~]# timedatectl set-timezone UTC [root@station111 ~]# date Mon May 1 01:42:12 PM UTC 2023格林威治时间比日本时间慢了 9 个小时啊~比台湾慢了 8 个小时啊!
[root@station111 ~]# timedatectl set-timezone Asia/Taipei [root@station111 ~]# date Mon May 1 09:42:50 PM CST 2023 [root@station111 ~]# man timedatectl .... set-time [TIME] Set the system clock to the specified time. This will also update the RTC time accordingly. The time may be specified in the format "2012-10-30 18:17:16". [root@station111 ~]# timedatectl set-ntp false [root@station111 ~]# timedatectl set-time "2023-05-01 21:50:00" [root@station111 ~]# date Mon May 1 09:50:02 PM CST 2023
[root@station111 ~]# 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@station111 ~]# firewall-cmd --permanent --list-services cockpit dhcpv6-client http https ssh # 底下先删除所有的服务 [root@station111 ~]# firewall-cmd --permanent --remove-service=cockpit --remove-service=http \ > --remove-service=dhcpv6-client --remove-service=ssh --remove-service=https success [root@station111 ~]# firewall-cmd --permanent --list-services # 再加入需要的服务啰! [root@station111 ~]# firewall-cmd --permanent --add-service=http --add-service=https \ > --add-service=ssh --add-service=ftp success [root@station111 ~]# firewall-cmd --permanent --list-services ftp http https ssh [root@station111 ~]# firewall-cmd --reload
[root@station111 ~]# 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@station111 ~]# firewall-cmd --permanent \ > --add-rich-rule="rule family='ipv4' source address='172.16.100.254' accept" [root@station111 ~]# firewall-cmd --permanent --add-rich-rule="rule family='ipv4' \ > source address='172.16.0.0/16' service name='ssh' accept" [root@station111 ~]# 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
[root@station111 ~]# firewall-cmd --reload [root@station111 ~]# firewall-cmd --list-services ftp http https ssh [root@station111 ~]# firewall-cmd --list-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
[root@station111 ~]# cd /dev/shm [root@station111 shm]# mkdir zip [root@station111 shm]# cd zip [root@station111 zip]# ll -Sr /etc ..... -rw-r--r--. 1 root root 39107 Feb 26 14:46 ld.so.cache -rw-r--r--. 1 root root 67454 Apr 22 2020 mime.types -rw-r--r--. 1 root root 692252 Jun 23 2020 services [root@station111 zip]# cp /etc/services filename.1 [root@station111 zip]# cp /etc/services filename.2 [root@station111 zip]# cp /etc/services filename.3 [root@station111 zip]# cp /etc/services filename.4 [root@station111 zip]# ll -rw-r--r--. 1 root root 692252 May 7 15:30 filename.1 -rw-r--r--. 1 root root 692252 May 7 15:30 filename.2 -rw-r--r--. 1 root root 692252 May 7 15:30 filename.3 -rw-r--r--. 1 root root 692252 May 7 15:30 filename.4
[root@station111 zip]# time gzip filename.1 real 0m0.029s user 0m0.027s sys 0m0.002s [root@station111 zip]# time bzip2 filename.2 real 0m0.069s user 0m0.063s sys 0m0.002s [root@station111 zip]# time xz filename.3 real 0m0.381s user 0m0.337s sys 0m0.009s [root@station111 zip]# man xz -T threads, --threads=threads [root@station111 zip]# time xz -T 2 --block-size=128K filename.4 real 0m0.212s user 0m0.358s sys 0m0.024s [root@station111 zip]# ll -rw-r--r--. 1 root root 142530 May 7 15:30 filename.1.gz -rw-r--r--. 1 root root 129328 May 7 15:30 filename.2.bz2 -rw-r--r--. 1 root root 105872 May 7 15:30 filename.3.xz -rw-r--r--. 1 root root 113868 May 7 15:30 filename.4.xz基本上,xz 通过多线程进行压缩时,最好给予一个固定的 block size 作为每个线程分到的量,然后个别进行压缩, 这样的效率会好上很多。因为我们的文件容量不大,因此采用比较小的 128K 作为切割,你可以看到 user 的时间花费大约是 0.358s, 跟缺省的 xz 单线程没有差很多!不过,因为用到两颗 CPU,那个 0.358s 其实是两颗 CPU 使用时间的总和!所以, 事实上人类时间花费只有 0.212s,是比单线程好很多的!另外,因为我们上面测试的是小型的文件,所以, xz 的多线程效果不明显。如果是大型的文件,使用 xz 的多线程,其速度性能要比其他两个好喔!
[root@station111 zip]# time gzip -d filename.1.gz real 0m0.007s user 0m0.006s sys 0m0.001s [root@station111 zip]# time bzip2 -d filename.2.bz2 real 0m0.027s user 0m0.023s sys 0m0.004s [root@station111 zip]# time xz -d filename.3.xz real 0m0.016s user 0m0.014s sys 0m0.001s [root@station111 zip]# ll -rw-r--r--. 1 root root 692252 May 7 15:30 filename.1 -rw-r--r--. 1 root root 692252 May 7 15:30 filename.2 -rw-r--r--. 1 root root 692252 May 7 15:30 filename.3 -rw-r--r--. 1 root root 113868 May 7 15:30 filename.4.xz
[root@station111 zip]# gzip -c filename.1 > filename.1.gz [root@station111 zip]# ll filename.1* -rw-r--r--. 1 root root 692252 May 7 15:30 filename.1 -rw-r--r--. 1 root root 142530 May 7 15:34 filename.1.gz
# 解压缩的方式,当然就是 -x 这个支持项目 # 先在本目录底下解开: [root@station111 zip]# ll -rw-r--r--. 1 root root 3267448 May 7 15:35 etc.tar.xz [root@station111 zip]# tar -Jx -f etc.tar.xz [root@station111 zip]# ll drwxr-xr-x. 130 root root 4820 May 7 15:04 etc -rw-r--r--. 1 root root 3267448 May 7 15:35 etc.tar.xz # 在非本目录解开,可以通过 -C 来处理 [root@station111 zip]# ll -d /tmp/etc* ls: 无法访问 '/tmp/etc*': 没有此一文件或目录 [root@station111 zip]# tar -Jx -f etc.tar.xz -C /tmp [root@station111 zip]# ll -d /tmp/etc* drwxr-xr-x. 130 root root 8192 May 7 15:04 /tmp/etc
# 先测试单线程的时间 [root@station111 zip]# time tar -Jc -f etc2.tar.xz /etc tar: Removing leading `/' from member names real 0m12.891s user 0m12.752s sys 0m0.141s # 使用管线的方式,来处理一下数据的压缩: [root@station111 zip]# tar -Jc -f - /etc | cat > etc3.tar.xz [root@station111 zip]# ll etc*tar* -rw-r--r--. 1 root root 3267448 May 7 15:38 etc2.tar.xz -rw-r--r--. 1 root root 3267448 May 7 15:40 etc3.tar.xz -rw-r--r--. 1 root root 3267448 May 7 15:35 etc.tar.xz # 使用多线程来处理看看: [root@station111 zip]# cat /proc/cpuinfo | grep processor processor : 0 processor : 1 # 出现几行就是有几颗 CPU 的意思。不过,这里应该指的是线程喔! [root@station111 zip]# time tar -c -f - /etc | xz -c > etc4.tar.xz tar: Removing leading `/' from member names real 0m13.181s user 0m13.029s sys 0m0.145s [root@station111 zip]# time tar -c -f - /etc | xz -T 2 --block-size=1M -c > etc4.tar.xz tar: Removing leading `/' from member names real 0m6.006s user 0m11.654s sys 0m0.124s # 你只要看 real 项目就好,真的速度有差喔!虽然压缩后的容量会稍微放大! [root@station111 zip]# ll -d etc* drwxr-xr-x. 130 root root 4820 May 7 15:04 etc -rw-r--r--. 1 root root 3267448 May 7 15:38 etc2.tar.xz -rw-r--r--. 1 root root 3267448 May 7 15:40 etc3.tar.xz -rw-r--r--. 1 root root 3582312 May 7 15:41 etc4.tar.xz -rw-r--r--. 1 root root 3267448 May 7 15:35 etc.tar.xz
[root@station111 ~]# mkdir /backups [root@station111 ~]# cd /backups/ [root@station111 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@station111 backups]# sh backup_system.sh tar: Removing leading `/' from member names tar: Removing leading `/' from hard link targets [root@station111 backups]# ll -rw-r--r--. 1 root root 39847266 May 7 15:43 backup_system_2023_05_07.tar.gz -rw-r--r--. 1 root root 184 May 7 15:43 backup_system.sh
# 某些小型系统确实不会启动 atd 的,所以,如果发现没启动,就启动它即可! [root@station111 backups]# systemctl restart atd [root@station111 backups]# systemctl enable atd
[root@station111 backups]# at 17:00 2023-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 Sun Dec 31 17:00:00 2023
[root@station111 ~]# at now + 4 hours warning: commands will be executed using /bin/sh at> poweroff at> <EOT> job 3 at Sun May 7 19:50:00 2023
[student@station111 22:50 2 ~]$ crontab -e 0 11 * * * /usr/sbin/ip addr show > /home/student/myipshow.txt */10 * * * * ip addr show > /dev/shm/myip [student@station111 22:52 3 ~]$ crontab -l 0 11 * * * /usr/sbin/ip addr show > /home/student/myipshow.txt */10 * * * * ip addr show > /dev/shm/myip
[root@station111 ~]# chmod 744 /backups/backup_system.sh [root@station111 ~]# ll /backups/backup_system.sh -rwxr--r--. 1 root root 184 May 7 15:43 /backups/backup_system.sh [root@station111 ~]# cd /etc/cron.monthly/ [root@station111 cron.monthly]# ln /backups/backup_system.sh . [root@station111 cron.monthly]# ll -rwxr--r--. 2 root root 184 May 7 15:43 backup_system.sh
# a. 探查一下有多少 at job 存在! [root@station111 ~]# atq 1 Mon May 8 11:00:00 2023 a student 2 Sun Dec 31 17:00:00 2023 a root 3 Sun May 7 19:50:00 2023 a root [root@station111 ~]# ll /var/spool/at total 12 -rwx------. 1 student student 2844 May 7 15:47 a0000101ac23d4 -rwx------. 1 root root 3517 May 7 15:49 a0000201b15a5c -rwx------. 1 root root 3422 May 7 15:50 a0000301ac2046 drwx------. 2 root root 6 Oct 26 2022 spool # 可以看到三个文件!这三个文件就是 at job 的实际设置信息! # b. 查看有没有 poweroff 时,可以这样做: [root@station111 ~]# at -c 1 | tail PATH=/home/student/.local/bin:/home/student/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:\~/cmd; export PATH MAIL=/var/spool/mail/student; export MAIL cd /home/student || { echo 'Execution directory inaccessible' >&2 exit 1 } ${SHELL:-/bin/sh} << 'marcinDELIMITER5e00cb31' ip addr show &> /home/student/myipshow.txt marcinDELIMITER5e00cb31 [root@station111 ~]# at -c 2 | tail cd /backups || { echo 'Execution directory inaccessible' >&2 exit 1 } ${SHELL:-/bin/sh} << 'marcinDELIMITER41e6be6a' wall 'This system will shutdown at 17:30. Please backup your work and logout system' sleep 30m poweroff marcinDELIMITER41e6be6a [root@station111 ~]# at -c 3 | tail SSH_TTY=/dev/pts/0; export SSH_TTY OLDPWD=/root; export OLDPWD cd /backups || { echo 'Execution directory inaccessible' >&2 exit 1 } ${SHELL:-/bin/sh} << 'marcinDELIMITER6ff1bc3e' poweroff marcinDELIMITER6ff1bc3e # 所以看起来只有 2, 3 号有关机任务,所以,取消这两个即可! [root@station111 ~]# atrm 2 [root@station111 ~]# atrm 3 [root@station111 ~]# atq 1 Mon May 8 11:00:00 2023 a student # c. 检查一下 crond 这个服务的纪录档! [root@station111 ~]# tail /var/log/cron May 7 15:53:01 station200 anacron[2089]: Job `cron.weekly' started May 7 15:53:01 station200 anacron[2089]: Job `cron.weekly' terminated May 7 15:53:01 station200 anacron[2089]: Normal exit (2 jobs run) May 7 15:53:13 station200 crontab[3265]: (student) REPLACE (student) May 7 15:53:13 station200 crontab[3265]: (student) END EDIT (student) May 7 15:53:15 station200 crontab[3270]: (student) LIST (student) May 7 15:54:01 station200 crond[1115]: (*system*) RELOAD (/etc/crontab) May 7 16:00:01 station200 CROND[3307]: (student) CMD (ip addr show > /dev/shm/myip) May 7 16:00:01 station200 CROND[3304]: (student) CMDOUT (/bin/sh: line 1: ip: command not found) May 7 16:00:01 station200 CROND[3304]: (student) CMDEND (ip addr show > /dev/shm/myip) # 确实有运行喔!不过指令有点问题!应该要用绝对路径比较好! # d. 其实就是查看一般用户的 crontab 设置 [root@station111 ~]# ll /var/spool/cron -rw-------. 1 student student 107 May 7 15:53 student [root@station111 ~]# 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@station111 ~]# crontab -e -u student 0 11 * * * /usr/sbin/ip addr show > /home/student/myipshow.txt #*/10 * * * * ip addr show > /dev/shm/myip [root@station111 ~]# crontab -l -u student