Linux 命令使用筆記【systemctl】

systemctl 命令

 

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

命令

  • -h --help Show this help
  • --version Show package version
  • --system Connect to system manager
  • -H --host=[USER@]HOST 在遠程主機上操作
  • -M --machine=CONTAINER 本地集裝箱操作
  • -t --type=TYPE 列出特定類型的單元
  • --state=STATE 列出具有特定負載或子狀態或活動狀態的單元
  • -p --property=NAME 僅以此名稱顯示屬性
  • -a --all 顯示所有加載的單位/屬性,包括死亡/空的。要列出系統上安裝的所有單元,請使用“list-unit-files”命令。
  • -l --full 不要在輸出中使用橢圓表示單元名稱
  • -r --遞歸顯示主機和本地容器的單元列表
  • --reverse 使用“列表依賴”顯示反向依賴關係
  • --job-mode=MODE Specify 如何處理已排隊作業,當排隊新作業
  • --show-types 在顯示套接字時,顯式地顯示其類型
  • -i --ignore-inhibitors 當關閉或睡眠時,忽略抑制因素
  • --kill-who=WHO 向誰發送信號
  • -s --signal=SIGNAL 發送哪個信號
  • --now 啓動或停止單元,除了啓用或禁用它
  • -q --quiet 抑制輸出
  • --no-block 不要等到操作完成
  • --no-wall 在停止/關閉/重啓之前不要發送牆消息
  • --no-reload 不要在en-/ disabling單元文件後重新加載守護進程
  • --no-legend 不要打印圖例(列標題和提示)
  • --no-pager 不將輸出管道傳輸到分頁器
  • --no-ask-password 不要求輸入系統密碼
  • --global 全局啓用/禁用單元文件
  • --runtime 僅臨時啓用單元文件,直到下一次重新啓動
  • -f --force 當啓用單元文件時,覆蓋現有的符號鏈接。當關閉時,立即執行動作
  • --preset-mode= 僅應用啓用,僅禁用,或所有預設
  • --root=PATH 在指定的根目錄中啓用單元文件
  • -n --lines=INTEGER 要顯示的日誌條目數
  • -o --output=STRING 改變日誌輸出模式(short, short-iso,short-precise, short-monotonic, verbose,export, json, json-pretty, json-sse, cat)
  • --plain 以列表而不是樹的形式打印單元依賴項

實例

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章