7.2. コマンドラインアシスタントを使用した SELinux の問題のトラブルシューティング


コマンドラインアシスタントを使用して、SELinux の問題をトラブルシューティングできます。このトラブルシューティングプロセスの例では、コマンドラインアシスタントの診断機能を説明します。

前提条件

  • コマンドラインアシスタントを有効にした。
  • システムへの root アクセス権がある。

手順

  1. ターミナルで次のコマンドを入力して、システムにインストールされている httpd パッケージのバージョンをリスト表示します。

    $ sudo rpm -qa httpd
    httpd-2.4.62-2.fc40.x86_64
  2. すべての httpd パッケージを検索します。

    $ sudo rpm -qa httpd
  3. Web サーバーが着信リクエストを受け入れるポートを特定します。

    $ cat /etc/httpd/conf/httpd.conf | grep Listen
    # Listen: Allows you to bind Apache to specific IP addresses and/or
    # Change this to Listen on a specific IP address, but note that if
    #Listen 12.34.56.78:80
    Listen 80
  4. httpd サービスを再起動します。

    $ systemctl restart httpd
    
    Job for httpd. Service failed because the control process exited with error code.
    See "systemctl status httpd.service" and "journalctl -xeu httpd.service" for details.
    1. journalctl コマンドを実行して、失敗したサービスの詳細を確認します。

      $ sudo journalctl -xeu httpd.service
  5. コマンドラインアシスタントを使用して問題のトラブルシューティングを行い、サービスが失敗する理由を質問します。

    $ sudo c "why did httpd fail to start"
    1. コマンドラインアシスタントに selinux httpd ポートについて質問します。

      $ c "selinux httpd port"

      アシスタントが、次のように sestatus コマンドを使用して、現在の SELinux ステータスと httpd サービスの内容を確認することを提案します。

      $ sudo sestatus
      
      SELinux status:                 enabled
      SELinuxfs mount:                /sys/fs/selinux
      SELinux root directory:         /etc/selinux
      Loaded policy name:             targeted
      Current mode:                   enforcing
      Mode from config file:          enforcing
      Policy MLS status:              enabled
      Policy deny_unknown status:     allowed
      Memory protection checking:     actual (secure)
      Max kernel policy version:      33
    2. 次のコマンドを実行して、httpd サービスの特定の SELinux ポリシーを表示します。

      $ sudo cat /usr/share/selinux/targeted/contexts/httpd_var_run_t
      No such file or directory
    3. コマンドラインアシスタントにコンテキストについて質問します。

      $ c "i don't have a httpd_var_run_t contexts"

      コマンドラインアシスタントが要求を処理するまでに、しばらく時間がかります。処理が終わると、提案がいくつか提供されます。

    4. コンテキストがない可能性があるため、次のコマンドでコンテキストを設定する必要があるという指示が表示されます。

      $ sudo chcon -R -t httpd_var_run_t
    5. コマンドラインアシスタント (CLA) にポートについて質問します。

      $ c "selinux won't let httpd listen on port 12345"
    6. 次の提案を試して、コマンドを実行します。

      $ sudo semanage port -a -t httpd_port_t -p tcp 12345
      ValueError: Type httpd_port_t is invalid, must be a port type
    7. 出力に表示されたエラーについて CLA に質問します。

      $ c "how do I fix ValueError: Type httpd_port_t is invalid, must be a port type"
  6. CLA によって提供された手順を実行します。

    $ sudo ls -Z /usr/sbin/httpd
    system_u:object_r:httpd_exec_t:s0 /usr/sbin/httpd
    
    $ chcon -t httpd_exec_t /usr/sbin/httpd
    
    $ sudo setenforce 1
    1. httpd サービスを再起動し、httpd.service のステータスを確認します。

      $ sudo systemctl restart httpd
      Job failed
      
      $ sudo systemctl status httpd.service
      Failed to start the Apache Server
  7. httpdport 12345 で待ち受けできるようにする方法について、CLA に質問します。

    $ c "how do I enable httpd to listen on port 12345 selinux"
    1. CLA によって提案されたコマンドを実行します。

      $ sudo setsebool -P httpd_can_network_connect=1
  8. httpd サービスを再起動し、httpd.service のステータスを再度確認します。

    $ sudo systemctl status httpd
    $ sudo systemctl restart httpd
    Job failed, see journalctl
  9. journalctl サービスを確認します。

    $ journalctl -xeu httpd
    Output: An ExecStart= process belonging to unit httpd.service has exited.
  10. 出力を使用して CLA にトラブルシューティングを実行するよう求めます。

    $ c "An ExecStart= process belonging to unit httpd.service has exited."
    1. CLA の応答で返されるコマンドを実行します。

      $ sudo ausearch -m AVC,USER_AVC -ts recent
      Output: "avc:  denied  {name_bind}  for pid=7184 comm="httpd" src=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r: unreserved_port_t:s0 tclas=tcp_socket permissive=0"
    2. 前のコマンドの出力をコピーします。

      $ sudo c "avc: denied {name_bind} for pid=7184 comm="httpd" src=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r: unreserved_port_t:s0 tclas=tcp_socket permissive=0"
    3. "SELinux is preventing Apache Server (httpd) from binding to port 12345" というエラーを解決するために、次のコマンドを実行します。

      $ sudo semanage port -a -t http_port_t -p tcp 12345

検証

  • httpd サービスを再起動し、httpd.service のステータスを確認します。

    $ sudo systemctl restart httpd
    No error
    $ sudo systemctl status httpd.service

    サーバーが設定されて起動し、port 443port 12345 で待ち受けるようになります。

Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2026 Red Hat
トップに戻る