如何除錯Systemctl

2021-09-13 12:21:06 字數 2468 閱讀 4279

有時候我們使用systemctl命令,比如systemctl start kube-apiserver時會提示錯誤:

[root@vultr kubenetes]# systemctl start kube-apiserver         

job for kube-apiserver.service failed because the control process exited with error code. see "systemctl status kube-apiserver.service" and "journalctl -xe" for details.

根據提示,再執行systemctl status kube-apiserver.service 會提示類似:

● kube-apiserver.service - kubernetes api service

loaded: loaded (/usr/lib/systemd/system/kube-apiserver.service; disabled; vendor preset: disabled)

active: failed (result: start-limit) since fri 2018-07-20 06:37:05 utc; 1min 17s ago

docs:

process: 8208 execstart=/usr/bin/kube-apiserver $kube_logtostderr $kube_log_level $kube_etcd_servers $kube_api_address $kube_api_port $kubelet_port $kube_allow_priv $kube_service_addresses $kube_admission_control $kube_api_args (code=exited, status=203/exec)

jul 20 06:37:05 vultr.guest systemd[1]: kube-apiserver.service: main process exited, code=exited, status=203/exec

jul 20 06:37:05 vultr.guest systemd[1]: failed to start kubernetes api service.

jul 20 06:37:05 vultr.guest systemd[1]: unit kube-apiserver.service entered failed state.

jul 20 06:37:05 vultr.guest systemd[1]: kube-apiserver.service failed.

jul 20 06:37:05 vultr.guest systemd[1]: kube-apiserver.service holdoff time over, scheduling restart.

jul 20 06:37:05 vultr.guest systemd[1]: start request repeated too quickly for kube-apiserver.service

jul 20 06:37:05 vultr.guest systemd[1]: failed to start kubernetes api service.

jul 20 06:37:05 vultr.guest systemd[1]: unit kube-apiserver.service entered failed state.

jul 20 06:37:05 vultr.guest systemd[1]: kube-apiserver.service failed.

注意看execstart

execstart=/usr/bin/kube-apiserver $kube_logtostderr $kube_log_level $kube_etcd_servers $kube_api_address $kube_api_port $kubelet_port $kube_allow_priv $kube_service_addresses $kube_admission_control $kube_api_args
其實我們除錯思想是,我們知道是這個kube-apiserver命令加上後續引數執行時出錯了,所以只要我們手動執行一下這個命令就知道錯在哪了,但是這裡環境變數還是類似$kube_log_level這種變數,不是編譯後的,不好除錯執行。

execstartpre=/bin/bash -l -c 'echo "/usr/bin/kube-apiserver $your_args">/tmp/systemctl.debug'
實際執行時這裡$your_asrgs替換為你自己在systemctl status後看到的引數。

然後systemctl daemon-reload,再start服務後,就可以執行 cat /tmp/systemctl.debug檢視具體的執行命令,然後拷貝下來在命令列執行下就可以知道具體的錯誤了。

systemctl 如何啟動 關閉 啟用 禁用服務

啟動服務 systemctl start service 關閉服務 systemctl stop service 重啟服務 systemctl restart service 顯示服務的狀態 systemctl status service 在開機時啟用服務 systemctl enable ser...

systemctl 命令用法

systemctl 是管 務的主要工具,它整合了chkconfig 與 service功能於一體。注 代表某個服務的名字,如http的服務名為httpd 例如在centos 7 上安裝http 啟動服務 等同於service httpd start 停止服務 等同於service httpd sto...

systemctl搜尋服務

unit 一共分成12種。service unit 系統服務 target unit 多個 unit 構成的乙個組 device unit 硬體裝置 mount unit 檔案系統的掛載點 automount unit 自動掛載點 path unit 檔案或路徑 scope unit 不是由 sys...