国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

linux中service與chkconfig的替代者systemctl

2024-08-27 23:58:36
字體:
來源:轉載
供稿:網友

linux中有很多命令已經存在了N多年,漸漸一些已被一些新命令所代替,不過由于習慣的原因,很多時候我們并不能一下子適應過來 ,例如ifconfig之于ip命令。

最近在玩ubuntu和opensuse時發現了systemctl命令了,后來在試玩centos7時也發現了該命令,systemctl是systemd下的一個工具。網上查了下,該命令已經存在很久了。該命令是用來替代service和chkconfig兩個命令的 --- 盡管個人感覺還是后者好用。

為了順應時間的發展,這里總結下。在目前很多linux的新發行版本里,系統對于daemon的啟動管理方法不再采用SystemV形式,而是使用了sytemd的架構來管理daemon的啟動。

一、runlevel 到 target的改變

在systemd的管理體系里面,以前的運行級別(runlevel)的概念被新的運行目標(target)所取代。tartget的命名類似于multi-user.target等這種形式,比如原來的運行級別3(runlevel3)就對應新的多用戶目標(multi-user.target),run level 5就相當于graphical.target。

由于不再使用runlevle概念,所以/etc/inittab也不再被系統使用 --- 無怪乎在新版本ubuntu上找不到inittab文件了。

而在systemd的管理體系里面,默認的target(相當于以前的默認運行級別)是通過軟鏈來實現。如:

ln -s /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target

在/lib/systemd/system/ 下面定義runlevelX.target文件目的主要是為了能夠兼容以前的運行級別level的管理方法。 事實上/lib/systemd/system/runlevel3.target,同樣是被軟連接到multi-user.target。

注:opensuse下是在/usr/lib/systemd/system/目錄下。

二、單元控制(unit)

在systemd管理體系里,稱呼需要管理的daemon為單元(unit)。對于單元(unit)的管理是通過命令systemctl來進行控制的。例如顯示當前的處于運行狀態的unit(即daemon),如:

  1. #systemctl 
  2. #systemctl --all 
  3. #systemctl list-units --type=sokect 
  4. #systemctl list-units --type=service 

注:type后面可以接的類型可以通過help查看:

  1. 361way:~ # systemctl -t help 
  2. Available unit types: 
  3. service 
  4. socket 
  5. target 
  6. device 
  7. mount 
  8. automount 
  9. snapshot 
  10. timer 
  11. swap 
  12. path 
  13. slice 
  14. scope 

三、systemctl用法及示例

chkconfig、service命令與systemctl命令的區別見下表:

任務 舊指令 新指令

使某服務自動啟動 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 --add  test systemctl   load test.service

刪除服務 chkconfig --del  xxx 停掉應用,刪除相應的配置文件

顯示所有已啟動的服務 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

注:systemctl后的服務名可以到/usr/lib/systemd/system目錄查看(opensuse下),其他發行版是位于/lib/systemd/system/ 下。

  1. //opensuse下 
  2. 361way:~ # systemctl status network.service 
  3. network.service - LSB: Configure network interfaces and set up routing 
  4.    Loaded: loaded (/usr/lib/systemd/system/network.service; enabled) 
  5.    Active: active (exited) since Mon 2014-09-01 20:05:45 CST; 2h 14min ago 
  6.   Process: 1022 ExecStart=/etc/init.d/network start (code=exited, status=0/SUCCESS) 
  7. Sep 01 20:05:15 linux-pnp8 systemd[1]: Starting LSB: Configure network interfaces and set up routing... 
  8. Sep 01 20:05:15 linux-pnp8 network[1022]: Setting up network interfaces: 
  9. Sep 01 20:05:15 linux-pnp8 network[1022]: lo 
  10. Sep 01 20:05:15 linux-pnp8 network[1022]: lo        IP address: 127.0.0.1/8 
  11. Sep 01 20:05:45 linux-pnp8 network[1022]: ..done..done..doneSetting up service network  .  .  .  .  .  .  .  .  .  .  .  .  ...done 
  12. Sep 01 20:05:45 linux-pnp8 systemd[1]: Started LSB: Configure network interfaces and set up routing. 
  13. //centos下  --Vevb.com 
  14. # systemctl status httpd.service 
  15. httpd.service - The Apache HTTP Server (prefork MPM) 
  16.         Loaded: loaded (/lib/systemd/system/httpd.service; disabled) 
  17.         Active: inactive (dead)  <-- 表示未啟動 
  18.         CGroup: name=systemd:/system/httpd.service 

上面兩個命令相當于/etc/init.d/network status 和 /etc/init.d/httpd status,opensuse和centos下的用法相同,只不過顯示的路徑不同。其他操作類似。

四、service配置文件

還以上面提到的httpd.service配置為例,httpd.service文件里可以找到如下行:

[Install]

WantedBy=multi-user.target

則表明在多用戶目標(multi-user.target,相當于level3)時自動啟動,如果想在runlevel 5下也自啟動,則可以將配置改為如下:

[Install]

WantedBy=multi-user.target graphical.target

一旦設定了自動啟動(enbale),就在/etc/systemd/system/.wants/下面建了一個httpd.service的軟連接,連接到/lib/systemd/system/下的相應服務那里,所以顯示自動啟動狀態的unit(類似于chekconfig --list命令的結果),可以通過下面的方法:

#ls /etc/systemd/system/multi-user.target.wants/

systemctl的總結先寫到這里,其是systemd包內的一個工具,也是該包中最為常用的工具。回頭再針對systemd做一個總結.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 威宁| 吴堡县| 郓城县| 西藏| 法库县| 商都县| 舟山市| 城固县| 喀喇沁旗| 徐州市| 凤阳县| 东莞市| 吐鲁番市| 涟源市| 互助| 定结县| 神池县| 鸡西市| 佛坪县| 萝北县| 银川市| 东安县| 朔州市| 华池县| 许昌市| 康保县| 白城市| 崇信县| 安泽县| 汉寿县| 保康县| 长顺县| 洛阳市| 磴口县| 南安市| 西乌珠穆沁旗| 且末县| 江油市| 林口县| 泰宁县| 舞钢市|