1.必要なコマンド
- systemctl status nginx.service、ユニットのステータスを表示します。
- systemctl start nginx.service、ユニットを開始します。
- systemctl restart nginx.service、ユニットを再起動します。
- systemctl stop nginx.service、ユニットを停止します。
- systemctl enable nginx.service、ブートから開始するように設定。
- systemctlはnginx.serviceを無効にし、オフにして自動的に起動します。
第二に、一般的に使用されるコマンド
- systemctl --version、バージョンを確認してください。
- whereis systemctl、場所を確認してください。
- systemctl list-unit-files、利用可能なすべてのユニット(サービス)をリストします。
- systemctl list-units、実行中のすべてのユニットをリストします。
- systemctl --failed、失敗したすべてのユニットをリストします。
- systemctl list-unit-files | grep enable、自動起動ソフトウェアを表示します。
- systemctl is-enabled nginx.service、ユニットの電源がオンになっているかどうかを確認します。
- systemctl daemon-reloadは、ユニットの構成ファイルを変更した後、構成ファイルを再ロードします。
- systemctl reload nginx.service、ユニットをリロードします。
- systemctl kill nginx、ユニットを強制終了します。
3. * .serviceファイルの構成:
centos7はファイルディレクトリを作成します:/ etc / systemd / system /
例:nginx.serviceを作成する
vi /etc/systemd/system/nginx.service
コンテンツを編集する
[単位]
Description = nginx
After = network.target
[サービス]
Type = forking
ExecStart = / usr / local / nginx / sbin / nginx
ExecReload = / usr / local / nginx / sbin / nginx -s reload
ExecStop = / usr / local / nginx / sbin / nginx -s stop
Privatetmp = true
[インストール]
WantedBy = multi-user.target
- [Unit]:サービスの説明
- 説明:サービスについて説明します
- 後:サービスカテゴリの説明
- 【サービス】サービス運用パラメーターの設定
- Type = forkingは、バックグラウンドで実行される形式です
- ExecStartは、サービスの特定の操作コマンドです
- ExecReloadは再起動コマンドです
- ExecStopは停止コマンドです
- PrivateTmp = Trueは、サービスに独立した一時スペースを割り当てることを意味します
- 注:[Service]の起動、再起動、停止コマンドはすべて絶対パスを使用する必要があります
- [インストール]実行レベルでのサービスインストールの関連設定をマルチユーザーに設定できます。つまり、システムの実行レベルは3です。