日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

任务计划、chkconfig工具、systemd管理服务、unit、target

發布時間:2025/3/8 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 任务计划、chkconfig工具、systemd管理服务、unit、target 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

比如備份數據或者重啟服務。

crontab -u、-e-l、-r(刪除)

?格式:分?時?日?月?周?user command

?文件/var/spool/cron/username

?分范圍0-59,時范圍0-23,日范圍1-31,月范圍1-12,周1-7

?可用格式1-5表示一個范圍15

?可用格式1,2,3表示1或者2或者3

?可用格式*/2表示被2整除的數字,比如小時,那就是每隔2小時

?要保證服務是啟動狀態

?systemctl start crond.service


cat /etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

# 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

crontab –e??//進入編輯模式

0 2 * * * /bin/bash /usr/local/sbin/123.sh >>/tmp/123.txt 2>>12.txt

#每天凌晨2點 執行腳本123.sh?把正確的輸入到123.txt,把錯誤的輸入到12.txt

?

0 2 1-4 */2 2,5 /bin/bash /usr/local/sbin/123.sh >>/tmp/123.txt 2>>12.txt

#每天凌晨2,14號,2,4,6,8,10,12月(能被2整除的)周2和周5一個區間用-。逗號隔開??執行腳本?123.sh?把正確的輸入到123.txt,把錯誤的輸入到12.txt

任務計劃沒執行

1.可能腳本里可能只是一個命令,不是絕對路徑?//(因為不在crondPATH里。cat /etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin)。最好的辦法就是寫絕對路徑

2.追加一個日志,正確的輸出或者錯誤的輸出。保證有據可查


chkconfig服務管理工具

chkconfig --list??//查看系統使用chkcongfig服務有哪些

chkconfig network on/off ?//分別表示開機開機還是關閉

?chkconfig --level 3 network off??//關閉3級別

?chkconfig --level 345 network off??//關閉345級別

?chkconfig --del network?//刪除

?chkconfig --add network??//增加

chkconfig --he


自己添加一個服務

要把文件放到/etc/init.d目錄下


systemd服務管理

systemctl list-units --all --type=service?//所有的服務都列出(包括未激活的)幾個常用的服務相關的命令

systemctl enable crond.service //讓服務開機啟動

systemctl disable crond //不讓開機啟動

?systemctl status crond //查看狀態

?systemctl stop crond //停止服務

?systemctl start crond //啟動服務

?systemctl restart crond //重啟服務

?systemctl is-enabled crond //檢查服務是否開機啟動


unit介紹

ls /usr/lib/systemd/system //系統所有unit,分為以下類型

?service?系統服務

?target?多個unit組成的組

ls -l runlevel*

device?硬件設備

?mount?文件系統掛載點

?automount?自動掛載點

?path?文件或路徑

?scope?不是由systemd啟動的外部進程

?slice?進程組

?snapshot systemd快照

?socket?進程間通信套接字

?swap ?swap文件

?timer?定時器

unit相關的命令

?systemctl list-units //列出正在運行的unit

?systemctl list-units --all //列出所有,包括失敗的或者inactive

?systemctl list-units --all --state=inactive //列出inactiveunit

?systemctl list-units --type=service//列出狀態為activeservice

?systemctl is-active crond.service //查看某個服務是否為active


target介紹

系統為了方便管理用target來管理unit

?systemctl list-unit-files --type=target?//列出所有的target

?systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit

?systemctl get-default //查看系統默認的target

?systemctl set-default multi-user.target

?一個service屬于一種類型的unit

?多個unit組成了一個target

?一個target里面包含了多個service

?cat /usr/lib/systemd/system/sshd.service //看這個service屬于哪個unit。看[install]部分



本文轉自 蝦米的春天 51CTO博客,原文鏈接:http://blog.51cto.com/lsxme/2047099,如需轉載請自行聯系原作者

總結

以上是生活随笔為你收集整理的任务计划、chkconfig工具、systemd管理服务、unit、target的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。