八周一次課(1月29日) 10.23 linux任務計划cron 10.24 chkconfig工具 10.25 systemd管理服務 10.26 unit介紹 10.27 target介紹


八周一次課(1月29日)
10.23 linux任務計划cron
10.24 chkconfig工具
10.25 systemd管理服務
10.26 unit介紹
10.27 target介紹
===========================================================================================================================================================================================================================================================
crontab命令:
被用來提交和管理用戶的需要周期性執行的任務,與windows下的計划任務類似,當安裝完成操作系統后,默認會安裝此服務工具,並且會自動啟動crond進程,crond進程每分鍾會定期檢查是否有要執行的任務,如果有要執行的任務,則自動執行該任務。

語法
crontab(選項)(參數)

選項
-e:編輯該用戶的計時器設置;
-l:列出該用戶的計時器設置;
-r:刪除該用戶的計時器設置;
-u<用戶名稱>:指定要設定計時器的用戶名稱。

參數
crontab文件:指定包含待執行任務的crontab文件。

知識擴展
Linux下的任務調度分為兩類:系統任務調度和用戶任務調度。

系統任務調度:系統周期性所要執行的工作,比如寫緩存數據到硬盤、日志清理等。在/etc目錄下有一個crontab文件,這個就是系統任務調度的配置文件。

/etc/crontab文件包括下面幾行:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""HOME=/

# run-parts
51 * * * * root run-parts /etc/cron.hourly
24 7 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
前四行是用來配置crond任務運行的環境變量,第一行SHELL變量指定了系統要使用哪個shell,這里是bash,第二行PATH變量指定了系統執行命令的路徑,第三行MAILTO變量指定了crond的任務執行信息將通過電子郵件發送給root用戶,如果MAILTO變量的值為空,則表示不發送任務執行信息給用戶,第四行的HOME變量指定了在執行命令或者腳本時使用的主目錄。

用戶任務調度:用戶定期要執行的工作,比如用戶數據備份、定時郵件提醒等。用戶可以使用 crontab 工具來定制自己的計划任務。所有用戶定義的crontab文件都被保存在/var/spool/cron目錄中。其文件名與用戶名一致,使用者權限文件如下:
/etc/cron.deny 該文件中所列用戶不允許使用crontab命令
/etc/cron.allow 該文件中所列用戶允許使用crontab命令
/var/spool/cron/ 所有用戶crontab文件存放的目錄,以用戶名命名
crontab文件的含義:用戶所建立的crontab文件中,每一行都代表一項任務,每行的每個字段代表一項設置,它的格式共分為六個字段,前五段是
時間設定段,第六段是要執行的命令段,格式如下:
minute hour day month week command
順序:分 時 日 月 周

其中:
minute: 表示分鍾,可以是從0到59之間的任何整數。
hour:表示小時,可以是從0到23之間的任何整數。
day:表示日期,可以是從1到31之間的任何整數。
month:表示月份,可以是從1到12之間的任何整數。
week:表示星期幾,可以是從0到7之間的任何整數,這里的0或7代表星期日。
command:要執行的命令,可以是系統命令,也可以是自己編寫的腳本文件。
在以上各個字段中,還可以使用以下特殊字符:

星號(*):代表所有可能的值,例如month字段如果是星號,則表示在滿足其它字段的制約條件后每月都執行該命令操作。
逗號(,):可以用逗號隔開的值指定一個列表范圍,例如,“1,2,5,7,8,9”
中杠(-):可以用整數之間的中杠表示一個整數范圍,例如“2-6”表示“2,3,4,5,6”
正斜線(/):可以用正斜線指定時間的間隔頻率,例如“0-23/2”表示每兩小時執行一次。同時正斜線可以和星號一起使用,例如*/10,如果用在minute字段,表示每十分鍾執行一次。
crond服務

/sbin/service crond start //啟動服務
/sbin/service crond stop //關閉服務
/sbin/service crond restart //重啟服務
/sbin/service crond reload //重新載入配置

查看crontab服務狀態:
service crond status

手動啟動crontab服務:
service crond start

查看crontab服務是否已設置為開機啟動,執行命令:
ntsysv

加入開機自動啟動:
chkconfig –level 35 crond on
實例

每1分鍾執行一次command
* * * * * command

每小時的第3和第15分鍾執行
3,15 * * * * command

在上午8點到11點的第3和第15分鍾執行
3,15 8-11 * * * command

每隔兩天的上午8點到11點的第3和第15分鍾執行
3,15 8-11 */2 * * command

每個星期一的上午8點到11點的第3和第15分鍾執行
3,15 8-11 * * 1 command

每晚的21:30重啟smb
30 21 * * * /etc/init.d/smb restart

每月1、10、22日的4 : 45重啟smb
45 4 1,10,22 * * /etc/init.d/smb restart

每周六、周日的1:10重啟smb
10 1 * * 6,0 /etc/init.d/smb restart

每天18 : 00至23 : 00之間每隔30分鍾重啟smb
0,30 18-23 * * * /etc/init.d/smb restart

每星期六的晚上11:00 pm重啟smb
0 23 * * 6 /etc/init.d/smb restart

每一小時重啟smb
* */1 * * * /etc/init.d/smb restart

晚上11點到早上7點之間,每隔一小時重啟smb
* 23-7/1 * * * /etc/init.d/smb restart

每月的4號與每周一到周三的11點重啟smb
0 11 4 * mon-wed /etc/init.d/smb restart

一月一號的4點重啟smb
0 4 1 jan * /etc/init.d/smb restart

每小時執行/etc/cron.hourly目錄內的腳本
01 * * * * root run-parts /etc/cron.hourly
===========================================================================================================================================================================================================================================================
chkconfig命令:
檢查、設置系統的各種服務。這是Red Hat公司遵循GPL規則所開發的程序,它可查詢操作系統在每一個執行等級中會執行哪些系統服務,其中包括各類常駐服務。謹記chkconfig不是立即自動禁止或激活一個服務,它只是簡單的改變了符號連接。

語法
chkconfig(選項)

選項
--add:增加所指定的系統服務,讓chkconfig指令得以管理它,並同時在系統啟動的敘述文件內增加相關數據;
--del:刪除所指定的系統服務,不再由chkconfig指令管理,並同時在系統啟動的敘述文件內刪除相關數據;
--level<等級代號>:指定讀系統服務要在哪一個執行等級中開啟或關畢。

等級代號列表:
等級0表示:表示關機
等級1表示:單用戶模式
等級2表示:無網絡連接的多用戶命令行模式
等級3表示:有網絡連接的多用戶命令行模式
等級4表示:不可用
等級5表示:帶圖形界面的多用戶模式
等級6表示:重新啟動
需要說明的是,level選項可以指定要查看的運行級而不一定是當前運行級。對於每個運行級,只能有一個啟動腳本或者停止腳本。當切換運行級時,init不會重新啟動已經啟動的服務,也不會再次去停止已經停止的服務。

運行級文件:
每個被chkconfig管理的服務需要在對應的init.d下的腳本加上兩行或者更多行的注釋。第一行告訴chkconfig缺省啟動的運行級以及啟動和停止的優先級。如果某服務缺省不在任何運行級啟動,那么使用-代替運行級。第二行對服務進行描述,可以用\跨行注釋。

例如random.init包含三行:
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
# higher quality random number generation.

實例
chkconfig --list #列出所有的系統服務。
chkconfig --add httpd #增加httpd服務。
chkconfig --del httpd #刪除httpd服務。
chkconfig --level httpd 2345 on #設置httpd在運行級別為2、3、4、5的情況下都是on(開啟)的狀態。
chkconfig --list #列出系統所有的服務啟動情況。
chkconfig --list mysqld #列出mysqld服務設置情況。
chkconfig --level 35 mysqld on #設定mysqld在等級3和5為開機運行服務,--level 35表示操作只在等級3和5執行,on表示啟動,off表示關閉。
chkconfig mysqld on #設定mysqld在各等級為on,“各等級”包括2、3、4、5等級。

如何增加一個服務:
服務腳本必須存放在/etc/ini.d/目錄下;
chkconfig --add servicename在chkconfig工具服務列表中增加此服務,此時服務會被在/etc/rc.d/rcN.d中賦予K/S入口了;
chkconfig --level 35 mysqld on修改服務的默認啟動等級。
===========================================================================================================================================================================================================================================================
systemctl命令:
是系統服務管理器指令,它實際上將 service 和 chkconfig 這兩個命令組合到一起。

任務 舊指令 新指令
使某服務自動啟動chkconfig--level 3 httpd on,systemctl enable httpd.service
使某服務不自動啟動chkconfig--level 3 httpd off,systemctl disable httpd.service
檢查服務狀態service httpd status,systemctl status httpd.service(服務詳細信息)
systemctl is-active httpd.service (僅顯示是否 Active)
顯示所有已啟動的服務chkconfig --list systemctl list-units --type=service
啟動某服務service httpd start systemctl start httpd.service
停止某服務service httpd stop systemctl stop httpd.service
重啟某服務service httpd restart systemctl restart httpd.service

實例
1.啟動nfs服務
systemctl start nfs-server.service
2.設置開機自啟動
systemctl enable nfs-server.service
3.停止開機自啟動
systemctl disable nfs-server.service
4.查看服務當前狀態
systemctl status nfs-server.service
5.重新啟動某服務
systemctl restart nfs-server.service
6.查看所有已啟動的服務
systemctl list -units --type=service
開啟防火牆22端口
iptables -I INPUT -p tcp --dport 22 -j accept
如果仍然有問題,就可能是SELinux導致的
關閉SElinux:
修改/etc/selinux/config文件中的SELINUX=””為disabled,然后重啟。
徹底關閉防火牆:
sudo systemctl status firewalld.service
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service
============================================================================================================================================================================================================================================================================================================================================================================
rsync命令:
是一個遠程數據同步工具,可通過LAN/WAN快速同步多台主機間的文件。rsync使用所謂的“rsync算法”來使本地和遠程兩個主機之間的文件達到同步,這個算法只傳送兩個文件的不同部分,而不是每次都整份傳送,因此速度相當快。 rsync是一個功能非常強大的工具,其命令也有很多功能特色選項,我們下面就對它的選項一一進行分析說明。

語法
rsync [OPTION]... SRC DEST
rsync [OPTION]... SRC [USER@]host:DEST
rsync [OPTION]... [USER@]HOST:SRC DEST
rsync [OPTION]... [USER@]HOST::SRC DEST
rsync [OPTION]... SRC [USER@]HOST::DEST
rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
對應於以上六種命令格式,rsync有六種不同的工作模式:

拷貝本地文件。當SRC和DES路徑信息都不包含有單個冒號":"分隔符時就啟動這種工作模式。如:rsync -a /data /backup
使用一個遠程shell程序(如rsh、ssh)來實現將本地機器的內容拷貝到遠程機器。當DST路徑地址包含單個冒號":"分隔符時啟動該模式。如:rsync -avz *.c foo:src
使用一個遠程shell程序(如rsh、ssh)來實現將遠程機器的內容拷貝到本地機器。當SRC地址路徑包含單個冒號":"分隔符時啟動該模式。如:rsync -avz foo:src/bar /data
從遠程rsync服務器中拷貝文件到本地機。當SRC路徑信息包含"::"分隔符時啟動該模式。如:rsync -av root@192.168.78.192::www /databack
從本地機器拷貝文件到遠程rsync服務器中。當DST路徑信息包含"::"分隔符時啟動該模式。如:rsync -av /databack root@192.168.78.192::www
列遠程機的文件列表。這類似於rsync傳輸,不過只要在命令中省略掉本地機信息即可。如:rsync -v rsync://192.168.78.192/www

選項
-v, --verbose 詳細模式輸出。
-q, --quiet 精簡輸出模式。
-c, --checksum 打開校驗開關,強制對文件傳輸進行校驗。
-a, --archive 歸檔模式,表示以遞歸方式傳輸文件,並保持所有文件屬性,等於-rlptgoD。
-r, --recursive 對子目錄以遞歸模式處理。
-R, --relative 使用相對路徑信息。
-b, --backup 創建備份,也就是對於目的已經存在有同樣的文件名時,將老的文件重新命名為~filename。可以使用--suffix選項來指定不同的備份文件前綴。
--backup-dir 將備份文件(如~filename)存放在在目錄下。
-suffix=SUFFIX 定義備份文件前綴。
-u, --update 僅僅進行更新,也就是跳過所有已經存在於DST,並且文件時間晚於要備份的文件,不覆蓋更新的文件。
-l, --links 保留軟鏈結。
-L, --copy-links 想對待常規文件一樣處理軟鏈結。
--copy-unsafe-links 僅僅拷貝指向SRC路徑目錄樹以外的鏈結。
--safe-links 忽略指向SRC路徑目錄樹以外的鏈結。
-H, --hard-links 保留硬鏈結。
-p, --perms 保持文件權限。
-o, --owner 保持文件屬主信息。
-g, --group 保持文件屬組信息。
-D, --devices 保持設備文件信息。
-t, --times 保持文件時間信息。
-S, --sparse 對稀疏文件進行特殊處理以節省DST的空間。
-n, --dry-run現實哪些文件將被傳輸。
-w, --whole-file 拷貝文件,不進行增量檢測。
-x, --one-file-system 不要跨越文件系統邊界。
-B, --block-size=SIZE 檢驗算法使用的塊尺寸,默認是700字節。
-e, --rsh=command 指定使用rsh、ssh方式進行數據同步。
--rsync-path=PATH 指定遠程服務器上的rsync命令所在路徑信息。
-C, --cvs-exclude 使用和CVS一樣的方法自動忽略文件,用來排除那些不希望傳輸的文件。
--existing 僅僅更新那些已經存在於DST的文件,而不備份那些新創建的文件。
--delete 刪除那些DST中SRC沒有的文件。
--delete-excluded 同樣刪除接收端那些被該選項指定排除的文件。
--delete-after 傳輸結束以后再刪除。
--ignore-errors 及時出現IO錯誤也進行刪除。
--max-delete=NUM 最多刪除NUM個文件。
--partial 保留那些因故沒有完全傳輸的文件,以是加快隨后的再次傳輸。
--force 強制刪除目錄,即使不為空。
--numeric-ids 不將數字的用戶和組id匹配為用戶名和組名。
--timeout=time ip超時時間,單位為秒。
-I, --ignore-times 不跳過那些有同樣的時間和長度的文件。
--size-only 當決定是否要備份文件時,僅僅察看文件大小而不考慮文件時間。
--modify-window=NUM 決定文件是否時間相同時使用的時間戳窗口,默認為0。
-T --temp-dir=DIR 在DIR中創建臨時文件。
--compare-dest=DIR 同樣比較DIR中的文件來決定是否需要備份。
-P 等同於 --partial。
--progress 顯示備份過程。
-z, --compress 對備份的文件在傳輸時進行壓縮處理。
--exclude=PATTERN 指定排除不需要傳輸的文件模式。
--include=PATTERN 指定不排除而需要傳輸的文件模式。
--exclude-from=FILE 排除FILE中指定模式的文件。
--include-from=FILE 不排除FILE指定模式匹配的文件。
--version 打印版本信息。
--address 綁定到特定的地址。
--config=FILE 指定其他的配置文件,不使用默認的rsyncd.conf文件。
--port=PORT 指定其他的rsync服務端口。
--blocking-io 對遠程shell使用阻塞IO。
-stats 給出某些文件的傳輸狀態。
--progress 在傳輸時現實傳輸過程。
--log-format=formAT 指定日志文件格式。
--password-file=FILE 從FILE中得到密碼。
--bwlimit=KBPS 限制I/O帶寬,KBytes per second。
-h, --help 顯示幫助信息。

實例
SSH方式
首先在服務端啟動ssh服務:
service sshd start
啟動 sshd: [確定]
使用rsync進行同步
接下來就可以在客戶端使用rsync命令來備份服務端上的數據了,SSH方式是通過系統用戶來進行備份的,如下:
rsync -vzrtopg --progress -e ssh --delete work@172.16.78.192:/www/* /databack/experiment/rsync
work@172.16.78.192's password:
receiving file list ...
5 files to consider
test/
a
0 100% 0.00kB/s 527:35:41 (1, 20.0% of 5)
b
67 100% 65.43kB/s 0:00:00 (2, 40.0% of 5)
c
0 100% 0.00kB/s 527:35:41 (3, 60.0% of 5)
dd
100663296 100% 42.22MB/s 0:00:02 (4, 80.0% of 5)
sent 96 bytes received 98190 bytes 11563.06 bytes/sec
total size is 100663363 speedup is 1024.19
上面的信息描述了整個的備份過程,以及總共備份數據的大小。

后台服務方式
啟動rsync服務,編輯/etc/xinetd.d/rsync文件,將其中的disable=yes改為disable=no,並重啟xinetd服務,如下:
vi /etc/xinetd.d/rsync
#default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync {
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
/etc/init.d/xinetd restart
停止 xinetd: [確定]
啟動 xinetd: [確定]
創建配置文件,默認安裝好rsync程序后,並不會自動創建rsync的主配置文件,需要手工來創建,其主配置文件為“/etc/rsyncd.conf”,創建該文件並插入如下內容:
vi /etc/rsyncd.conf
uid=root
gid=root
max connections=4
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
secrets file=/etc/rsyncd.passwd
hosts deny=172.16.78.0/22

[www]
comment= backup web
path=/www
read only = no
exclude=test
auth users=work

創建密碼文件,采用這種方式不能使用系統用戶對客戶端進行認證,所以需要創建一個密碼文件,其格式為“username:password”,用戶名可以和密碼可以隨便定義,最好不要和系統帳戶一致,同時要把創建的密碼文件權限設置為600,這在前面的模塊參數做了詳細介紹。
echo "work:abc123" > /etc/rsyncd.passwd
chmod 600 /etc/rsyncd.passwd

備份,完成以上工作,現在就可以對數據進行備份了,如下:
rsync -avz --progress --delete work@172.16.78.192::www /databack/experiment/rsync
Password:
receiving file list ...
6 files to consider
./ files...
a
0 100% 0.00kB/s 528:20:41 (1, 50.0% of 6)
b
67 100% 65.43kB/s 0:00:00 (2, 66.7% of 6)
c
0 100% 0.00kB/s 528:20:41 (3, 83.3% of 6)
dd
100663296 100% 37.49MB/s 0:00:02 (4, 100.0% of 6)
sent 172 bytes received 98276 bytes 17899.64 bytes/sec
total size is 150995011 speedup is 1533.75

恢復,當服務器的數據出現問題時,那么這時就需要通過客戶端的數據對服務端進行恢復,但前提是服務端允許客戶端有寫入權限,否則也不能在客戶端直接對服務端進行恢復,使用rsync對數據進行恢復的方法如下:
rsync -avz --progress /databack/experiment/rsync/ work@172.16.78.192::www

Password:
building file list ...
6 files to consider
./
a
b
67 100% 0.00kB/s 0:00:00 (2, 66.7% of 6)
c
sent 258 bytes received 76 bytes 95.43 bytes/sec
total size is 150995011 speedup is 452080.87

============================================================================================================================================================================================================================================================================================================================================================================
[root@localhost ~]# 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

[root@localhost ~]# crontab -e
no crontab for root - using an empty one

[No write since last change]
/bin/bash: q: 未找到命令

shell returned 127

Press ENTER or type command to continue
crontab: installing new crontab
"/tmp/crontab.2eMw17":1: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit? y
crontab: installing new crontab
[root@localhost ~]# systemctl start crond.service
[root@localhost ~]# systemctl start crond\
> ^C
[root@localhost ~]# systemctl start crond\
> ^C
Failed to start crond\x03.service: Unit not found.
[root@localhost ~]# systemctl start crond
[root@localhost ~]# ps aux |gerp cron
-bash: gerp: 未找到命令
[root@localhost ~]# ps aux |grep cron
root 571 0.0 0.0 126228 1600 ? Ss 21:10 0:00 /usr/sbin/crond -n
root 2601 0.0 0.0 112680 976 pts/0 S+ 21:31 0:00 grep --color=auto cron
[root@localhost ~]# systemctl status crond
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since 一 2018-01-29 21:10:41 CST; 21min ago
Main PID: 571 (crond)
CGroup: /system.slice/crond.service
└─571 /usr/sbin/crond -n

1月 29 21:10:41 localhost.localdomain systemd[1]: Started Command Scheduler.
1月 29 21:10:41 localhost.localdomain systemd[1]: Starting Command Scheduler...
1月 29 21:10:41 localhost.localdomain crond[571]: (CRON) INFO (RANDOM_DELAY will be scaled with....)
1月 29 21:10:41 localhost.localdomain crond[571]: (CRON) INFO (running with inotify support)
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl stop crond
[root@localhost ~]# systemctl status crond
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: inactive (dead) since 一 2018-01-29 21:32:16 CST; 2s ago
Process: 571 ExecStart=/usr/sbin/crond -n $CRONDARGS (code=exited, status=0/SUCCESS)
Main PID: 571 (code=exited, status=0/SUCCESS)

1月 29 21:10:41 localhost.localdomain systemd[1]: Started Command Scheduler.
1月 29 21:10:41 localhost.localdomain systemd[1]: Starting Command Scheduler...
1月 29 21:10:41 localhost.localdomain crond[571]: (CRON) INFO (RANDOM_DELAY will be scaled with....)
1月 29 21:10:41 localhost.localdomain crond[571]: (CRON) INFO (running with inotify support)
1月 29 21:32:16 localhost.localdomain systemd[1]: Stopping Command Scheduler...
1月 29 21:32:16 localhost.localdomain crond[571]: (CRON) INFO (Shutting down)
1月 29 21:32:16 localhost.localdomain systemd[1]: Stopped Command Scheduler.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl start crond
[root@localhost ~]# systemctl stop crond
[root@localhost ~]# systemctl start crond
[root@localhost ~]# ps aux |grep cron
root 2633 0.0 0.0 126236 1584 ? Ss 21:32 0:00 /usr/sbin/crond -n
root 2635 0.0 0.0 112676 972 pts/0 S+ 21:32 0:00 grep --color=auto cron
[root@localhost ~]# crontab -l

[root@localhost ~]# cat /var/spool/cron/
cat: /var/spool/cron/: 是一個目錄
[root@localhost ~]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
如果您想列出 systemd 服務,請執行 'systemctl list-unit-files'。
欲查看對特定 target 啟用的服務請執行
'systemctl list-dependencies [target]'。

netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:開 3:開 4:開 5:開 6:關
[root@localhost ~]# top
top - 21:40:32 up 30 min, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 117 total, 1 running, 116 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.1 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 4162512 total, 3831016 free, 161500 used, 169996 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 3774624 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
270 root 20 0 0 0 0 S 0.3 0.0 0:00.13 kworker/u256:2
1 root 20 0 190684 3616 2388 S 0.0 0.1 0:02.79 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root 20 0 0 0 0 S 0.0 0.0 0:00.41 rcu_sched
10 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/0
11 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/1
12 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/1
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/1
15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H
16 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/2
17 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/2
18 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/2
20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/2:0H
21 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/3
22 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/3
23 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/3
25 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/3:0H
27 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 khelper
28 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
[root@localhost ~]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
如果您想列出 systemd 服務,請執行 'systemctl list-unit-files'。
欲查看對特定 target 啟用的服務請執行
'systemctl list-dependencies [target]'。

netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:開 3:開 4:開 5:開 6:關
[root@localhost ~]# ls /etc/init.d/
functions netconsole network README sshd
[root@localhost ~]# chkconfig network off
[root@localhost ~]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
如果您想列出 systemd 服務,請執行 'systemctl list-unit-files'。
欲查看對特定 target 啟用的服務請執行
'systemctl list-dependencies [target]'。

netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:關 3:關 4:關 5:關 6:關
[root@localhost ~]# chkconfig network on
[root@localhost ~]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
如果您想列出 systemd 服務,請執行 'systemctl list-unit-files'。
欲查看對特定 target 啟用的服務請執行
'systemctl list-dependencies [target]'。

netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:開 3:開 4:開 5:開 6:關
[root@localhost ~]# chkconfig --level 3 network off
[root@localhost ~]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
如果您想列出 systemd 服務,請執行 'systemctl list-unit-files'。
欲查看對特定 target 啟用的服務請執行
'systemctl list-dependencies [target]'。

netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:開 3:關 4:開 5:開 6:關
[root@localhost ~]# level 345 network off
-bash: level: 未找到命令
[root@localhost ~]# level 345 network off
-bash: level: 未找到命令
[root@localhost ~]# chkconfig --level 345 network off
[root@localhost ~]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
如果您想列出 systemd 服務,請執行 'systemctl list-unit-files'。
欲查看對特定 target 啟用的服務請執行
'systemctl list-dependencies [target]'。

netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:開 3:關 4:關 5:關 6:關
[root@localhost ~]# chkconfig --level 345 network on
[root@localhost ~]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
如果您想列出 systemd 服務,請執行 'systemctl list-unit-files'。
欲查看對特定 target 啟用的服務請執行
'systemctl list-dependencies [target]'。

netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:開 3:開 4:開 5:開 6:關
[root@localhost ~]# cd /etc/init.d/
[root@localhost init.d]# ls
functions netconsole network README sshd
[root@localhost init.d]# cp network 123
[root@localhost init.d]# ls
123 functions netconsole network README sshd
[root@localhost init.d]# chkconfig --add network
[root@localhost init.d]# chkconfig --add 123 network
chkconfig 版本 1.7.2 - 版權 (C) 1997-2000 紅帽公司
在 GNU 公共許可條款下,本軟件可以自由重發行。

用法: chkconfig [--list] [--type <類型>] [名稱]
chkconfig --add <名稱>
chkconfig --del <名稱>
chkconfig --override <名稱>
chkconfig [--level <級別>] [--type <類型>] <名稱> <on|off|reset|resetpriorities>
[root@localhost init.d]# chkconfig --add 123
[root@localhost init.d]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
如果您想列出 systemd 服務,請執行 'systemctl list-unit-files'。
欲查看對特定 target 啟用的服務請執行
'systemctl list-dependencies [target]'。

123 0:關 1:關 2:開 3:開 4:開 5:開 6:關
netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:開 3:開 4:開 5:開 6:關
[root@localhost init.d]# vim 123
[root@localhost init.d]# chkconfig --del 123
[root@localhost init.d]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
如果您想列出 systemd 服務,請執行 'systemctl list-unit-files'。
欲查看對特定 target 啟用的服務請執行
'systemctl list-dependencies [target]'。

netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:開 3:開 4:開 5:開 6:關
[root@localhost init.d]# chkconfig --add network
[root@localhost init.d]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
如果您想列出 systemd 服務,請執行 'systemctl list-unit-files'。
欲查看對特定 target 啟用的服務請執行
'systemctl list-dependencies [target]'。

netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:開 3:開 4:開 5:開 6:關
[root@localhost init.d]# systemctl list-units --all --type=service
UNIT LOAD ACTIVE SUB DESCRIPTION
auditd.service loaded active running Security Auditing Service
brandbot.service loaded inactive dead Flexible Branding Service
chronyd.service loaded active running NTP client/server
cpupower.service loaded inactive dead Configure CPU power related settin
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
● display-manager.service not-found inactive dead display-manager.service
dm-event.service loaded inactive dead Device-mapper event daemon
dracut-shutdown.service loaded inactive dead Restore /run/initramfs
ebtables.service loaded inactive dead Ethernet Bridge Filtering tables
emergency.service loaded inactive dead Emergency Shell
● exim.service not-found inactive dead exim.service
firewalld.service loaded active running firewalld - dynamic firewall daemo
getty@tty1.service loaded active running Getty on tty1
ip6tables.service loaded inactive dead IPv6 firewall with ip6tables
● ipset.service not-found inactive dead ipset.service
iptables.service loaded inactive dead IPv4 firewall with iptables
irqbalance.service loaded active running irqbalance daemon
kdump.service loaded active exited Crash recovery kernel arming
kmod-static-nodes.service loaded active exited Create list of required static dev
● libvirtd.service not-found inactive dead libvirtd.service
● lvm2-activation.service not-found inactive dead lvm2-activation.service
lvm2-lvmetad.service loaded active running LVM2 metadata daemon
lvm2-lvmpolld.service loaded inactive dead LVM2 poll daemon
lvm2-monitor.service loaded active exited Monitoring of LVM2 mirrors, snapsh
microcode.service loaded inactive dead Load CPU microcode update
network.service loaded active exited LSB: Bring up/down networking
● NetworkManager-wait-online.service loaded failed failed Network Manager Wait Online
lines 1-29

UNIT LOAD ACTIVE SUB DESCRIPTION
auditd.service loaded active running Security Auditing Service
brandbot.service loaded inactive dead Flexible Branding Service
chronyd.service loaded active running NTP client/server
cpupower.service loaded inactive dead Configure CPU power related settings
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
● display-manager.service not-found inactive dead display-manager.service
dm-event.service loaded inactive dead Device-mapper event daemon
dracut-shutdown.service loaded inactive dead Restore /run/initramfs
ebtables.service loaded inactive dead Ethernet Bridge Filtering tables
emergency.service loaded inactive dead Emergency Shell
● exim.service not-found inactive dead exim.service
firewalld.service loaded active running firewalld - dynamic firewall daemon
getty@tty1.service loaded active running Getty on tty1
ip6tables.service loaded inactive dead IPv6 firewall with ip6tables
● ipset.service not-found inactive dead ipset.service
iptables.service loaded inactive dead IPv4 firewall with iptables
irqbalance.service loaded active running irqbalance daemon
kdump.service loaded active exited Crash recovery kernel arming
kmod-static-nodes.service loaded active exited Create list of required static device
● libvirtd.service not-found inactive dead libvirtd.service
● lvm2-activation.service not-found inactive dead lvm2-activation.service
lvm2-lvmetad.service loaded active running LVM2 metadata daemon
lvm2-lvmpolld.service loaded inactive dead LVM2 poll daemon
lvm2-monitor.service loaded active exited Monitoring of LVM2 mirrors, snapshots
microcode.service loaded inactive dead Load CPU microcode update
network.service loaded active exited LSB: Bring up/down networking
● NetworkManager-wait-online.service loaded failed failed Network Manager Wait Online
lines 1-29

UNIT LOAD ACTIVE SUB DESCRIPTION
auditd.service loaded active running Security Auditing Service
brandbot.service loaded inactive dead Flexible Branding Service
chronyd.service loaded active running NTP client/server
cpupower.service loaded inactive dead Configure CPU power related settings
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
● display-manager.service not-found inactive dead display-manager.service
dm-event.service loaded inactive dead Device-mapper event daemon
dracut-shutdown.service loaded inactive dead Restore /run/initramfs
ebtables.service loaded inactive dead Ethernet Bridge Filtering tables
emergency.service loaded inactive dead Emergency Shell
● exim.service not-found inactive dead exim.service
firewalld.service loaded active running firewalld - dynamic firewall daemon
getty@tty1.service loaded active running Getty on tty1
ip6tables.service loaded inactive dead IPv6 firewall with ip6tables
● ipset.service not-found inactive dead ipset.service
iptables.service loaded inactive dead IPv4 firewall with iptables
irqbalance.service loaded active running irqbalance daemon
kdump.service loaded active exited Crash recovery kernel arming
kmod-static-nodes.service loaded active exited Create list of required static device
● libvirtd.service not-found inactive dead libvirtd.service
● lvm2-activation.service not-found inactive dead lvm2-activation.service
lvm2-lvmetad.service loaded active running LVM2 metadata daemon
lvm2-lvmpolld.service loaded inactive dead LVM2 poll daemon
lvm2-monitor.service loaded active exited Monitoring of LVM2 mirrors, snapshots
microcode.service loaded inactive dead Load CPU microcode update
network.service loaded active exited LSB: Bring up/down networking
● NetworkManager-wait-online.service loaded failed failed Network Manager Wait Online
NetworkManager.service loaded active running Network Manager
● ntpd.service not-found inactive dead ntpd.service
● ntpdate.service not-found inactive dead ntpdate.service
plymouth-quit-wait.service loaded inactive dead Wait for Plymouth Boot Screen to Quit
plymouth-quit.service loaded inactive dead Terminate Plymouth Boot Screen
plymouth-read-write.service loaded inactive dead Tell Plymouth To Write Out Runtime Da
plymouth-start.service loaded inactive dead Show Plymouth Boot Screen
polkit.service loaded active running Authorization Manager
postfix.service loaded active running Postfix Mail Transport Agent
rc-local.service loaded inactive dead /etc/rc.d/rc.local Compatibility
rescue.service loaded inactive dead Rescue Shell
rhel-autorelabel-mark.service loaded inactive dead Mark the need to relabel after reboot
rhel-autorelabel.service loaded inactive dead Relabel all filesystems, if necessary
rhel-configure.service loaded inactive dead Reconfigure the system on administrat
rhel-dmesg.service loaded active exited Dump dmesg to /var/log/dmesg
rhel-import-state.service loaded active exited Import network configuration from ini
rhel-loadmodules.service loaded inactive dead Load legacy module configuration
rhel-readonly.service loaded active exited Configure read-only root support
rsyslog.service loaded active running System Logging Service
● sendmail.service not-found inactive dead sendmail.service
● sntp.service not-found inactive dead sntp.service
sshd-keygen.service loaded inactive dead OpenSSH Server Key Generation
sshd.service loaded active running OpenSSH server daemon
● syslog.service not-found inactive dead syslog.service
sysstat.service loaded active exited Resets System Activity Logs
systemd-ask-password-console.service loaded inactive dead Dispatch Password Requests to Console
systemd-ask-password-plymouth.service loaded inactive dead Forward Password Requests to Plymouth
systemd-ask-password-wall.service loaded inactive dead Forward Password Requests to Wall
systemd-binfmt.service loaded inactive dead Set Up Additional Binary Formats
systemd-firstboot.service loaded inactive dead First Boot Wizard
systemd-fsck-root.service loaded inactive dead File System Check on Root Device
systemd-hwdb-update.service loaded inactive dead Rebuild Hardware Database
systemd-initctl.service loaded inactive dead /dev/initctl Compatibility Daemon
systemd-journal-catalog-update.service loaded inactive dead Rebuild Journal Catalog
systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-machine-id-commit.service loaded inactive dead Commit a transient machine-id on disk
systemd-modules-load.service loaded inactive dead Load Kernel Modules
● systemd-random-seed-load.service not-found inactive dead systemd-random-seed-load.service
systemd-random-seed.service loaded active exited Load/Save Random Seed
systemd-readahead-collect.service loaded inactive dead Collect Read-Ahead Data
systemd-readahead-done.service loaded inactive dead Stop Read-Ahead Data Collection
systemd-readahead-replay.service loaded inactive dead Replay Read-Ahead Data
systemd-reboot.service loaded inactive dead Reboot
systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
systemd-shutdownd.service loaded inactive dead Delayed Shutdown Service
systemd-sysctl.service loaded active exited Apply Kernel Variables
● systemd-sysusers.service not-found inactive dead systemd-sysusers.service
systemd-tmpfiles-clean.service loaded inactive dead Cleanup of Temporary Directories
systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev
systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories
systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
systemd-udevd.service loaded active running udev Kernel Device Manager
systemd-update-done.service loaded inactive dead Update is Completed
systemd-update-utmp-runlevel.service loaded inactive dead Update UTMP about System Runlevel Cha
systemd-update-utmp.service loaded active exited Update UTMP about System Boot/Shutdow
systemd-user-sessions.service loaded active exited Permit User Sessions
systemd-vconsole-setup.service loaded active exited Setup Virtual Console
tuned.service loaded active running Dynamic System Tuning Daemon
vmtoolsd.service loaded active running Service for virtual machines hosted o

LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.

89 loaded units listed.
systemd-ask-password-plymouth.service loaded inactive dead Forward Password Requests to Plymouth
systemd-ask-password-wall.service loaded inactive dead Forward Password Requests to Wall
systemd-binfmt.service loaded inactive dead Set Up Additional Binary Formats
systemd-firstboot.service loaded inactive dead First Boot Wizard
systemd-fsck-root.service loaded inactive dead File System Check on Root Device
systemd-hwdb-update.service loaded inactive dead Rebuild Hardware Database
systemd-initctl.service loaded inactive dead /dev/initctl Compatibility Daemon
systemd-journal-catalog-update.service loaded inactive dead Rebuild Journal Catalog
systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-machine-id-commit.service loaded inactive dead Commit a transient machine-id on disk
systemd-modules-load.service loaded inactive dead Load Kernel Modules
● systemd-random-seed-load.service not-found inactive dead systemd-random-seed-load.service
systemd-random-seed.service loaded active exited Load/Save Random Seed
systemd-readahead-collect.service loaded inactive dead Collect Read-Ahead Data
systemd-readahead-done.service loaded inactive dead Stop Read-Ahead Data Collection
systemd-readahead-replay.service loaded inactive dead Replay Read-Ahead Data
systemd-reboot.service loaded inactive dead Reboot
systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
systemd-shutdownd.service loaded inactive dead Delayed Shutdown Service
systemd-sysctl.service loaded active exited Apply Kernel Variables
● systemd-sysusers.service not-found inactive dead systemd-sysusers.service
systemd-tmpfiles-clean.service loaded inactive dead Cleanup of Temporary Directories
systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev
systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories
systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
systemd-udevd.service loaded active running udev Kernel Device Manager
systemd-update-done.service loaded inactive dead Update is Completed
systemd-update-utmp-runlevel.service loaded inactive dead Update UTMP about System Runlevel Cha
systemd-update-utmp.service loaded active exited Update UTMP about System Boot/Shutdow
systemd-user-sessions.service loaded active exited Permit User Sessions
systemd-vconsole-setup.service loaded active exited Setup Virtual Console
tuned.service loaded active running Dynamic System Tuning Daemon
vmtoolsd.service loaded active running Service for virtual machines hosted o

LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.

89 loaded units listed.
To show all installed unit files use 'systemctl list-unit-files'.
[root@localhost init.d]# systemctl enable crond.service
[root@localhost init.d]# systemctl is-enabled crond
enabled
[root@localhost init.d]# d
-bash: d: 未找到命令
[root@localhost init.d]#
[root@localhost init.d]# cd
[root@localhost ~]# ls -l runlevel*
ls: 無法訪問runlevel*: 沒有那個文件或目錄
[root@localhost ~]# ls /usr/lib/systemd/
catalog systemd-ac-power systemd-importd systemd-remount-fs systemd-update-utmp
import-pubring.gpg systemd-activate systemd-initctl systemd-reply-password systemd-user-sessions
ntp-units.d systemd-backlight systemd-journald systemd-rfkill systemd-vconsole-setup
rhel-autorelabel systemd-binfmt systemd-localed systemd-shutdown system-generators
rhel-configure systemd-bootchart systemd-logind systemd-shutdownd system-preset
rhel-dmesg systemd-bus-proxyd systemd-machined systemd-sleep system-shutdown
rhel-domainname systemd-cgroups-agent systemd-machine-id-commit systemd-socket-proxyd system-sleep
rhel-import-state systemd-coredump systemd-modules-load systemd-sysctl user
rhel-loadmodules systemd-cryptsetup systemd-pull systemd-sysv-install user-generators
rhel-readonly systemd-fsck systemd-quotacheck systemd-timedated user-preset
system systemd-hibernate-resume systemd-random-seed systemd-udevd
systemd systemd-hostnamed systemd-readahead systemd-update-done
[root@localhost ~]# ls -l runlevel*
ls: 無法訪問runlevel*: 沒有那個文件或目錄
[root@localhost ~]# systemctl list-unit-files --type=target
UNIT FILE STATE
basic.target static
bluetooth.target static
cryptsetup-pre.target static
cryptsetup.target static
ctrl-alt-del.target disabled
default.target enabled
emergency.target static
final.target static
getty.target static
graphical.target static
halt.target disabled
hibernate.target static
hybrid-sleep.target static
initrd-fs.target static
initrd-root-fs.target static
initrd-switch-root.target static
initrd.target static
iprutils.target disabled
kexec.target disabled
local-fs-pre.target static
local-fs.target static
machines.target disabled
multi-user.target enabled
network-online.target static
network-pre.target static
network.target static
nss-lookup.target static
nss-user-lookup.target static
paths.target static
poweroff.target disabled
printer.target static
reboot.target disabled
remote-fs-pre.target static
remote-fs.target enabled
rescue.target disabled
rpcbind.target static
runlevel0.target disabled
runlevel1.target disabled
runlevel2.target enabled
runlevel3.target enabled
runlevel4.target enabled
runlevel5.target static
runlevel6.target disabled
shutdown.target static
sigpwr.target static
sleep.target static
slices.target static
smartcard.target static
sockets.target static
sound.target static
suspend.target static
swap.target static
sysinit.target static
system-update.target static
time-sync.target static
timers.target static
umount.target static

57 unit files listed.
[root@localhost ~]# systemctl list-dependencies multi-user.target
multi-user.target
● ├─auditd.service
● ├─brandbot.path
● ├─chronyd.service
● ├─crond.service
● ├─dbus.service
● ├─irqbalance.service
● ├─kdump.service
● ├─network.service
● ├─NetworkManager.service
● ├─plymouth-quit-wait.service
● ├─plymouth-quit.service
● ├─postfix.service
● ├─rsyslog.service
● ├─sshd.service
● ├─sysstat.service
● ├─systemd-ask-password-wall.path
● ├─systemd-logind.service
● ├─systemd-readahead-collect.service
● ├─systemd-readahead-replay.service
● ├─systemd-update-utmp-runlevel.service
● ├─systemd-user-sessions.service
● ├─tuned.service
● ├─vmtoolsd.service
● ├─basic.target
● │ ├─firewalld.service
● │ ├─microcode.service
● │ ├─rhel-autorelabel-mark.service
● │ ├─rhel-autorelabel.service
● │ ├─rhel-configure.service
● │ ├─rhel-dmesg.service
● │ ├─rhel-loadmodules.service
● │ ├─paths.target
● │ ├─slices.target
● │ │ ├─-.slice
● │ │ └─system.slice
● │ ├─sockets.target
● │ │ ├─dbus.socket
● │ │ ├─dm-event.socket
● │ │ ├─systemd-initctl.socket
● │ │ ├─systemd-journald.socket
● │ │ ├─systemd-shutdownd.socket
● │ │ ├─systemd-udevd-control.socket
● │ │ └─systemd-udevd-kernel.socket
● │ ├─sysinit.target
● │ │ ├─dev-hugepages.mount
● │ │ ├─dev-mqueue.mount
● │ │ ├─kmod-static-nodes.service
● │ │ ├─lvm2-lvmetad.socket
● │ │ ├─lvm2-lvmpolld.socket
● │ │ ├─lvm2-monitor.service
● │ │ ├─plymouth-read-write.service
● │ │ ├─plymouth-start.service
● │ │ ├─proc-sys-fs-binfmt_misc.automount
● │ │ ├─sys-fs-fuse-connections.mount
● │ │ ├─sys-kernel-config.mount
● │ │ ├─sys-kernel-debug.mount
● │ │ ├─systemd-ask-password-console.path
● │ │ ├─systemd-binfmt.service
● │ │ ├─systemd-firstboot.service
● │ │ ├─systemd-hwdb-update.service
● │ │ ├─systemd-journal-catalog-update.service
● │ │ ├─systemd-journal-flush.service
● │ │ ├─systemd-journald.service
● │ │ ├─systemd-machine-id-commit.service
● │ │ ├─systemd-modules-load.service
● │ │ ├─systemd-random-seed.service
● │ │ ├─systemd-sysctl.service
● │ │ ├─systemd-tmpfiles-setup-dev.service
● │ │ ├─systemd-tmpfiles-setup.service
● │ │ ├─systemd-udev-trigger.service
● │ │ ├─systemd-udevd.service
● │ │ ├─systemd-update-done.service
● │ │ ├─systemd-update-utmp.service
● │ │ ├─systemd-vconsole-setup.service
● │ │ ├─cryptsetup.target
● │ │ ├─local-fs.target
● │ │ │ ├─-.mount
● │ │ │ ├─boot.mount
● │ │ │ ├─mnt.mount
● │ │ │ ├─rhel-import-state.service
● │ │ │ ├─rhel-readonly.service
● │ │ │ └─systemd-remount-fs.service
● │ │ └─swap.target
● │ │ └─dev-disk-by\x2duuid-f6c26a6b\x2d525e\x2d4356\x2d9304\x2db5ce6799805f.swap
● │ └─timers.target
● │ └─systemd-tmpfiles-clean.timer
● ├─getty.target
● │ └─getty@tty1.service
● └─remote-fs.target
[root@localhost ~]# systemctl get-default
multi-user.target
[root@localhost ~]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[root@localhost ~]# cat /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.service
Wants=sshd-keygen.service

[Service]
Type=forking
PIDFile=/var/run/sshd.pid
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
[root@localhost ~]# rsync -av /etc/passwd /tmp/1.txt
-bash: rsync: 未找到命令
[root@localhost ~]# yum install -y rsync
已加載插件:fastestmirror
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 6.4 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/3): epel/x86_64/updateinfo | 876 kB 00:00:00
(2/3): epel/x86_64/primary_db | 6.2 MB 00:00:00
(3/3): updates/7/x86_64/primary_db | 6.0 MB 00:00:01
Loading mirror speeds from cached hostfile
* epel: mirrors.tongji.edu.cn
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 rsync.x86_64.0.3.0.9-18.el7 將被 安裝
--> 解決依賴關系完成

依賴關系解決

=================================================================================================================================
Package 架構 版本 源 大小
=================================================================================================================================
正在安裝:
rsync x86_64 3.0.9-18.el7 base 360 k

事務概要
=================================================================================================================================
安裝 1 軟件包

總下載量:360 k
安裝大小:732 k
Downloading packages:
rsync-3.0.9-18.el7.x86_64.rpm | 360 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安裝 : rsync-3.0.9-18.el7.x86_64 1/1
驗證中 : rsync-3.0.9-18.el7.x86_64 1/1

已安裝:
rsync.x86_64 0:3.0.9-18.el7

完畢!
[root@localhost ~]# rsync -av /etc/passwd /tmp/1.txt
sending incremental file list
passwd
rsync: rename "/tmp/.1.txt.SGG1Nq" -> "1.txt": Operation not permitted (1)

sent 1288 bytes received 31 bytes 2638.00 bytes/sec
total size is 1214 speedup is 0.92
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]
[root@localhost ~]#
[root@localhost ~]# rsync -av /tmp/1.txt 192.168.40.128:/tmp/2.txt
The authenticity of host '192.168.40.128 (192.168.40.128)' can't be established.
ECDSA key fingerprint is 61:a4:c4:79:38:70:6f:b2:45:8f:95:d6:4a:07:6a:1e.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': yes
Warning: Permanently added '192.168.40.128' (ECDSA) to the list of known hosts.
root@192.168.40.128's password:
sending incremental file list
1.txt

sent 233 bytes received 31 bytes 11.73 bytes/sec
total size is 160 speedup is 0.61
[root@localhost ~]#


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM