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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > centos >内容正文

centos

Centos7 systemctl使用

發(fā)布時間:2023/12/18 centos 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Centos7 systemctl使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

CentOS 7.x開始,CentOS開始使用systemd服務(wù)來代替daemon,原來管理系統(tǒng)啟動和管理系統(tǒng)服務(wù)的相關(guān)命令全部由systemctl命令來代替。

1、原來的 service 命令與 systemctl 命令對比

daemon命令

systemctl命令

說明

service [服務(wù)] start

systemctl start [unit type]

啟動服務(wù)

service [服務(wù)] stop

systemctl stop [unit type]

停止服務(wù)

service [服務(wù)] restart

systemctl restart [unit type]

重啟服務(wù)

此外還是二個systemctl參數(shù)沒有與service命令參數(shù)對應(yīng)

  • status:參數(shù)來查看服務(wù)運行情況
  • reload:重新加載服務(wù),加載更新后的配置文件(并不是所有服務(wù)都支持這個參數(shù),比如network.service)

應(yīng)用舉例:

#啟動網(wǎng)絡(luò)服務(wù)

systemctl start network.service

#停止網(wǎng)絡(luò)服務(wù)

systemctl stop network.service

#重啟網(wǎng)絡(luò)服務(wù)

systemctl restart network.service

#查看網(wǎng)絡(luò)服務(wù)狀態(tài)

systemctl status network.serivce

2、原來的chkconfig 命令與 systemctl 命令對比

2.1、設(shè)置開機啟動/不啟動

daemon命令

systemctl命令

說明

chkconfig [服務(wù)] on

systemctl enable [unit type]

設(shè)置服務(wù)開機啟動

chkconfig [服務(wù)] off

systemctl disable [unit type]

設(shè)備服務(wù)禁止開機啟動

應(yīng)用舉例:

#停止cup電源管理服務(wù)

systemctl stop cups.service

#禁止cups服務(wù)開機啟動

systemctl disable cups.service

#查看cups服務(wù)狀態(tài)

systemctl status cups.service

#重新設(shè)置cups服務(wù)開機啟動

systemctl enable cups.service

2.2、查看系統(tǒng)上上所有的服務(wù)

命令格式:

systemctl [command] [–type=TYPE] [–all]

參數(shù)詳解:

command?- list-units:依據(jù)unit列出所有啟動的unit。加上 –all 才會列出沒啟動的unit; - list-unit-files:依據(jù)/usr/lib/systemd/system/ 內(nèi)的啟動文件,列出啟動文件列表

–type=TYPE?- 為unit type, 主要有service, socket, target

應(yīng)用舉例:

systemctl命令

說明

systemctl

列出所有的系統(tǒng)服務(wù)

systemctl list-units

列出所有啟動unit

systemctl list-unit-files

列出所有啟動文件

systemctl list-units –type=service –all

列出所有service類型的unit

systemctl list-units –type=service –all grep cpu

列出 cpu電源管理機制的服務(wù)

systemctl list-units –type=target –all

列出所有target

3、systemctl特殊的用法

systemctl命令

說明

systemctl is-active [unit type]

查看服務(wù)是否運行

systemctl is-enable [unit type]

查看服務(wù)是否設(shè)置為開機啟動

systemctl mask [unit type]

注銷指定服務(wù)

systemctl unmask [unit type]

取消注銷指定服務(wù)

應(yīng)用舉例:

#查看網(wǎng)絡(luò)服務(wù)是否啟動

systemctl is-active network.service

#檢查網(wǎng)絡(luò)服務(wù)是否設(shè)置為開機啟動

systemctl is-enable network.service

#停止cups服務(wù)

systemctl stop cups.service

#注銷cups服務(wù)

systemctl mask cups.service

#查看cups服務(wù)狀態(tài)

systemctl status cups.service

#取消注銷cups服務(wù)

systemctl unmask cups.service

4、init 命令與systemctl命令對比

init命令

systemctl命令

說明

init 0

systemctl poweroff

系統(tǒng)關(guān)機

init 6

systemctl reboot

重新啟動

與開關(guān)機相關(guān)的其他命令:

systemctl命令

說明

systemctl suspend

進入睡眠模式

systemctl hibernate

進入休眠模式

systemctl rescue

強制進入救援模式

systemctl emergency

強制進入緊急救援模式

5、設(shè)置系統(tǒng)運行級別

5.1、運行級別對應(yīng)表

init級別

systemctl target

0

shutdown.target

1

emergency.target

2

rescure.target

3

multi-user.target

4

5

graphical.target

6

此外還是一個getty.target用來設(shè)置tty的數(shù)量。

5.2、設(shè)置運行級別

命令格式:

systemctl [command]?[unit.target]

參數(shù)詳解:

command:

  • get-default :取得當(dāng)前的target
  • set-default :設(shè)置指定的target為默認(rèn)的運行級別
  • isolate :切換到指定的運行級別
  • unit.target :為5.1表中列出的運行級別

systemctl命令

說明

systemctl get-default

獲得當(dāng)前的運行級別

systemctl set-default multi-user.target

設(shè)置默認(rèn)的運行級別為mulit-user

systemctl isolate multi-user.target

在不重啟的情況下,切換到運行級別mulit-user下

systemctl isolate graphical.target

在不重啟的情況下,切換到圖形界面下

6、使用systemctl分析各服務(wù)之前的依賴關(guān)系

命令格式:

systemctl list-dependencies [unit] [–reverse]

–reverse是用來檢查尋哪個unit使用了這個unit

應(yīng)用舉例:

#獲得當(dāng)前運行級別的target[root@www ~]# systemctl get-default

multi-user.target

#查看當(dāng)前運行級別target(mult-user)啟動了哪些服務(wù)[root@www ~]# systemctl list-dependencies

default.target

├─abrt-ccpp.service

├─abrt-oops.service

├─vsftpd.service

├─basic.target

│ ├─alsa-restore.service

│ ├─alsa-state.service

.....(中間省略).....

│ ├─sockets.target

│ │ ├─avahi-daemon.socket

│ │ ├─dbus.socket

.....(中間省略).....

│ ├─sysinit.target

│ │ ├─dev-hugepages.mount

│ │ ├─dev-mqueue.mount

.....(中間省略).....

│ └─timers.target

│ ??└─systemd-tmpfiles-clean.timer

├─getty.target

│ └─getty@tty1.service

└─remote-fs.target

#查看哪些target引用了當(dāng)前運行級別的target[root@www ~]# systemctl list-dependencies --reverse

default.target

└─graphical.target

7、關(guān)閉網(wǎng)絡(luò)服務(wù)

在使用systemctl關(guān)閉網(wǎng)絡(luò)服務(wù)時有一些特殊 需要同時關(guān)閉unit.servce和unit.socket

使用systemctl查看開啟的sshd服務(wù)

[root@www system]# ?systemctl list-units --all | grep sshd

sshd-keygen.service loaded inactive dead ???????OpenSSH Server Key Generation

sshd.service ???????loaded active ??running ????OpenSSH server daemon

sshd.socket ????????loaded inactive dead ???????OpenSSH Server Socket

可以看到系統(tǒng)同時開啟了?sshd.service?和?sshd.socket?, 如果只閉關(guān)了?sshd.service?那么?sshd.socket還在監(jiān)聽網(wǎng)絡(luò),在網(wǎng)絡(luò)上有要求連接 sshd 時就會啟動?sshd.service?。因此如果想完全關(guān)閉sshd服務(wù)的話,需要同時停用?sshd.service?和?sshd.socket?。

systemctl stop sshd.service

systemctl stop sshd.socket

systemctl disable sshd.service sshd.socket

由于centos 7.x默認(rèn)沒有安裝net-tools,因此無法使用netstat 來查看主機開發(fā)的商品。需要通過yum安裝來獲得該工具包:

yum -y install net-tools

查看是否關(guān)閉22端口

netstat -lnp |grep sshd

8、關(guān)閉防火墻firewall

Centos 7.x 中取消了iptables, 用firewall取而代之。要關(guān)閉防火墻并禁止開機啟動服務(wù)使用下面的命令:

systemctl stop firewalld.service

systemctl disable firewalld.service

轉(zhuǎn)載于:https://www.cnblogs.com/wx90/p/7729720.html

總結(jié)

以上是生活随笔為你收集整理的Centos7 systemctl使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。