初次體驗CentOS 7的systemd

來源:互聯網
上載者:User

標籤:centos7   linux   systemd   

新發布的CentOS 7 中使用systemd服務代替了之前版本的SysV服務,對比下兩種啟動方式的不同。


修改系統啟動層級

舊版

編輯設定檔/etc/inittab,設定啟動層級為3 (多使用者文字介面),修改initdefault前面的數字為3,儲存重啟

新版

修改預設啟動層級為3

systemctl enable multi-user.target

這個命令實際則是在目錄 /etc/systemd/system 下建立了一個軟連結

ln -s ‘/usr/lib/systemd/system/multi-user.target‘ ‘/etc/systemd/system/default.target‘

若修改預設啟動層級為5,需要將之前的啟動層級disable

systemctl disable multi-user.target

該命令實際刪除了軟連結default.target

rm ‘/etc/systemd/system/default.target‘

然後再啟用啟動層級5

systemctl enable graphical.target

實際建立了新的軟連結

ln -s ‘/usr/lib/systemd/system/graphical.target‘ ‘/etc/systemd/system/default.target‘

當然你也可以跳過命令直接以建立軟連結的方式來改變啟動層級


應用程式的自啟動項

當通過yum安裝了httpd服務後,準備將其添加到自啟動項裡,

舊版

chkconfig httpd on

新版

systemctl enable httpd

實際是建立了軟連結

ln -s ‘/usr/lib/systemd/system/httpd.service‘ ‘/etc/systemd/system/multi-user.target.wants/httpd.service‘

關掉httpd的自啟動

systemctl disable httpd

實際軟連結被刪除

rm ‘/etc/systemd/system/multi-user.target.wants/httpd.service‘

關於啟動層級3下面的服務啟動項都在/etc/systemd/system/multi-user.target.wants目錄下,而層級5的則在目錄graphical.target.wants下面

我們開啟這個連結檔案 httpd.service 可以看到內容,就是有關httpd的啟動指令碼

[Unit]Description=The Apache HTTP ServerAfter=network.target remote-fs.target nss-lookup.target[Service]Type=notifyEnvironmentFile=/etc/sysconfig/httpdExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUNDExecReload=/usr/sbin/httpd $OPTIONS -k gracefulExecStop=/bin/kill -WINCH ${MAINPID}# We want systemd to give httpd some time to finish gracefully, but still want# it to kill httpd after TimeoutStopSec if something went wrong during the# graceful stop. Normally, Systemd sends SIGTERM signal right after the# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give# httpd time to finish.KillSignal=SIGCONTPrivateTmp=true[Install]WantedBy=multi-user.target


關於服務的啟動/關閉/重啟

舊版

service httpd {start|stop|restart}

新版

systemctl {start|stop|restart} httpd

查看當前httpd的運行狀態

systemctl status httpd

輸出結果

httpd.service - The Apache HTTP Server   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)   Active: active (running) since Thu 2014-07-17 15:12:50 CST; 4s ago  Process: 2762 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)Main PID: 2769 (httpd)   Status: "Processing requests..."   CGroup: /system.slice/httpd.service           ?..2769 /usr/sbin/httpd -DFOREGROUND           ?..2770 /usr/sbin/httpd -DFOREGROUND           ?..2771 /usr/sbin/httpd -DFOREGROUND           ?..2772 /usr/sbin/httpd -DFOREGROUND           ?..2773 /usr/sbin/httpd -DFOREGROUND           ?..2774 /usr/sbin/httpd -DFOREGROUNDJul 17 15:12:50 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...Jul 17 15:12:50 localhost.localdomain httpd[2769]: AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain. Set the ...his messageJul 17 15:12:50 localhost.localdomain systemd[1]: Started The Apache HTTP Server.Hint: Some lines were ellipsized, use -l to show in full

查看所有服務自啟動狀態

舊版

chkconfig --list

新版

systemctl list-unit-files


以上是我對systemd的一個初步印象,需要一個逐步適應的過程,希望大家多多討論交流。

本文出自 “努力為之” 部落格,請務必保留此出處http://carllai.blog.51cto.com/1664997/1439562

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.