久久精品精选,精品九九视频,www久久只有这里有精品,亚洲熟女乱色综合一区
    分享

    systemctl使用指南:Centos 7.x systemd對比Centos 6.x daemon

     老鶴閑聊 2016-01-23

    從CentOS 7.x開始,CentOS開始使用systemd服務來代替daemon,原來管理系統啟動和管理系統服務的相關命令全部由systemctl命令來代替。

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

    daemon命令 systemctl命令 說明
    service [服務] start systemctl start [unit type] 啟動服務
    service [服務] stop systemctl stop [unit type] 停止服務
    service [服務] restart systemctl restart [unit type] 停止服務

    此外還是二個systemctl參數沒有與service命令參數對應

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

    應用舉例:

    #啟動網絡服務
    systemctl start network.service
    #停止網絡服務
    systemctl stop network.service
    #重啟網絡服務
    systemctl restart network.service
    #查看網絡服務狀態
    systemctl status network.serivce
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

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

    2.1、設置開機啟動/不啟動

    daemon命令 systemctl命令 說明
    chkconfig [服務] on systemctl enable [unit type] 設置服務開機啟動
    chkconfig [服務] off systemctl disable [unit type] 設備服務禁止開機啟動

    應用舉例:

    #停止cup電源管理服務
    systemctl stop cups.service
    #禁止cups服務開機啟動
    systemctl disable cups.service
    #查看cups服務狀態
    systemctl status cups.service
    #重新設置cups服務開機啟動
    systemctl enable cups.service
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    2.2、查看系統上上所有的服務
    命令格式:

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

    參數詳解:

    command

    list-units:依據unit列出所有啟動的unit。加上 –all 才會列出沒啟動的unit;
    list-unit-files:依據/usr/lib/systemd/system/ 內的啟動文件,列出啟動文件列表

    –type=TYPE

    為unit type, 主要有service, socket, target

    應用舉例:

    systemctl命令 說明
    systemctl 列出所有的系統服務
    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電源管理機制的服務
    systemctl list-units –type=target –all 列出所有target

    3、systemctl特殊的用法

    systemctl 命令 說明
    systemctl is-active [unit type] 查看服務是否運行
    systemctl is-enable [unit type] 查看服務是否設置為開機啟動
    systemctl mask [unit type] 注銷指定服務]
    systemctl unmask [unit type] 取消注銷指定服務

    應用舉例:

    #查看網絡服務是否啟動
    systemctl is-active network.service
    #檢查網絡服務是否設置為開機啟動
    systemctl is-enable network.service
    #停止cups服務
    systemctl stop cups.service
    #注銷cups服務
    systemctl mask cups.service
    #查看cups服務狀態
    systemctl status cups.service
    #取消注銷cups服務
    systemctl unmask cups.service
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    4、init 命令與systemctl命令對比

    init命令 systemctl命令 說明
    init 0 systemctl poweroff 系統關機
    init 6 systemctl reboot 重新啟動

    與開關機相關的其他命令:

    systemctl命令 說明
    systemctl suspend 進入睡眠模式
    systemctl hibernate 進入休眠模式
    systemctl rescue 強制進入救援模式
    systemctl emergency 強制進入緊急救援模式

    5、設置系統運行級別

    5.1、運行級別對應表

    init級別 systemctl target
    0 shutdown.target
    1 emergency.target
    2 rescure.target
    3 multi-user.target
    4
    5 graphical.target
    6

    此外還是一個getty.target用來設置tty的數量。

    5.2、設置運行級別
    命令格式:

    systemctl [command] [unit.target]

    參數詳解:

    command:

    get-default :取得當前的target
    set-default :設置指定的target為默認的運行級別
    isolate :切換到指定的運行級別

    unit.target :為5.1表中列出的運行級別

    systemctl命令 說明
    systemctl get-default 獲得當前的運行級別
    systemctl set-default multi-user.target 設置默認的運行級別為mulit-user
    systemctl isolate multi-user.target 在不重啟的情況下,切換到運行級別mulit-user下
    systemctl isolate graphical.target 在不重啟的情況下,切換到圖形界面下

    6、使用systemctl分析各服務之前的依賴關系

    命令格式:

    systemctl list-dependencies [unit] [–reverse]

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

    應用舉例:

    #獲得當前運行級別的target
    [root@www ~]# systemctl get-default
    multi-user.target
    
    #查看當前運行級別target(mult-user)啟動了哪些服務
    [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引用了當前運行級別的target
    [root@www ~]# systemctl list-dependencies --reverse
    default.target
    └─graphical.target
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    7、關閉網絡服務

    在使用systemctl關閉網絡服務時有一些特殊
    需要同時關閉unit.servce和unit.socket

    使用systemctl查看開啟的sshd服務

    [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
    • 1
    • 2
    • 3
    • 4

    可以看到系統同時開啟了sshd.service和sshd.socket , 如果只閉關了sshd.service那么sshd.socket還在監聽網絡,在網絡上有要求連接sshd時就會啟動sshd.service。因此如果想完全關閉sshd服務的話,需要同時停用sshd.service和sshd.socket。

    systemctl stop sshd.service
    systemctl stop sshd.socket
    systemctl disable sshd.service sshd.socket
    • 1
    • 2
    • 3

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

     yum -y install net-tools
    • 1

    查看是否關閉22端口

    netstat -lnp |grep sshd
    • 1

    8、關閉防火墻firewall

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

    systemctl stop firewalld.service
    systemctl disable firewalld.service
    • 1
    • 2

      本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發現有害或侵權內容,請點擊一鍵舉報。
      轉藏 分享 獻花(0

      0條評論

      發表

      請遵守用戶 評論公約

      類似文章 更多

      主站蜘蛛池模板: 四虎永久免费高清视频| 日日碰狠狠添天天爽五月婷| 少妇愉情理伦片丰满丰满午夜| 中文有无人妻vs无码人妻激烈| 国产99青青成人A在线| 国产精品国产三级国快看| 国产精品白丝喷水在线观看| 69天堂人成无码免费视频| 无码熟妇人妻AV在线影片最多| 起碰免费公开97在线视频| 一本一本久久A久久精品综合不卡| 亚洲欧美日韩精品久久亚洲区| 久久这里有精品国产电影网| 亚洲熟女乱色一区二区三区 | 亚洲国产成人欧美在线观看| 亚洲欧洲一区二区精品| 隔壁老王国产在线精品| 人成午夜免费大片| 国产成人亚洲综合| 中文字幕日韩人妻一区| 色播久久人人爽人人爽人人片AV| 亚洲国产午夜福利精品| 国产波霸爆乳一区二区| 午夜国产精品福利一二| 国产乱子影视频上线免费观看| 日本高清一区免费中文视频| 成A人片亚洲日本久久| 午夜大片免费男女爽爽影院| 亚洲性无码AV在线欣赏网| 天堂影院一区二区三区四区| 日韩中文字幕国产精品| 免费无码成人AV在线播放不卡 | 亚洲一区二区三区在线观看精品中文| 国内少妇偷人精品免费| 97人人超碰国产精品最新O| 少妇被粗大的猛进出69影院| 四虎影视一区二区精品| 色噜噜狠狠狠综合曰曰曰| 男女18禁啪啪无遮挡激烈| 亚洲成人av综合一区| 亚洲小说乱欧美另类|