Fedora33:SSHサーバー設定

SSHサーバーのインストール

サーバーにwebmasterでログインします。

localhost login: webmaster
password:

rootでログインします。

[webmaster@localhost ~]$ us -
password:

SSHサーバーをインストールします。

[root@localhost ~]# dnf install openssh-server openssh-clients

SSHサーバーを起動します。

[root@localhost ~]# systemctl start sshd

SSHサーバーを自動起動設定をします。

[root@localhost ~]# systemctl enable sshd

SSHサーバーの作動確認します。

[root@localhost ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset>
   Active: active (running) since Sun 2021-04-11 18:03:51 JST; 5h 16min ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 870 (sshd)
    Tasks: 1 (limit: 23603)
   Memory: 4.6M
   CGroup: /system.slice/sshd.service
           mq870 /usr/sbin/sshd -D -oCiphers=aes256-gcm@openssh.com,chacha20-po>

 4月 11 18:03:51 localhost.localdomain systemd[1]: Starting OpenSSH server daem>
 4月 11 18:03:51 localhost.localdomain sshd[870]: Server listening on 0.0.0.0 p>
 4月 11 18:03:51 localhost.localdomain sshd[870]: Server listening on :: port 2>
 4月 11 18:03:51 localhost.localdomain systemd[1]: Started OpenSSH server daemo>
 4月 11 22:29:36 localhost.localdomain sshd[5425]: Accepted password for webmas>
 4月 11 22:29:36 localhost.localdomain sshd[5425]: pam_unix(sshd:session): sess>
 4月 11 23:19:30 localhost.localdomain sshd[5481]: Accepted password for webmas>
 4月 11 23:19:30 localhost.localdomain sshd[5481]: pam_unix(sshd:session): sess>
lines 1-19/19 (END)

「q」を押下して表示を終了します。

現在のネットワーク設定を確認

ネットワーク設定でIPアドレスを記録します。

webmaster@www:~$ ip addr
span style="color: #ffffff;">1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp14s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 0c:2e:48:2b:dg:f4 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.3/24 brd 192.168.1.255 scope global dynamic enp2s0 #IPアドレス、インターファイス名記録
valid_lft 11984sec preferred_lft 11984sec
inet6 20sd:ahq23:46dg:7rh9:2dg5:28uf:fls4:dehd/64 scope global dynamic mngtmpaddr noprefixroute
valid_lft 13592sec preferred_lft 11792sec
inet6 fft0::21fg3:2j8f:fo60:djed/64 scope link
valid_lft forever preferred_lft forever

192.168.1.3」(記録したIPアドレス)でクライアントPCよりTera Termで接続します。

Fedora33:インストール

Fedora33ダウンロード

ダウンロードページからインストールディスクイメージ(Fedora-Server-dvd-x86_64-33-1.2.iso)をダウンロードします。

インストールDVD作成

ImgBurnを使いFedora-Server-dvd-x86_64-33-1.2.isoでFedora33インストールディスクを作成します。

Fedora33インストール

インストール前にBIOSでDVDブートができるように設定します。

ご自身のサーバーの設定方法をメーカーサイトでお調べください。

作成したインストールDVDでインストールします。

下の画面が表示されたらキーボードの「Enter」を押下します。

「日本語」を選択して「続行」をクリックします。

「キーボード」で日本語に設定します。

「言語サポート」で日本語(日本)に設定します。

「日付と時刻」でアジア/東京 タイムゾーンに設定します。

「ソフトウェアの選択」をクリックします。

「Fedora Server Edition」を選択して「完了」をクリックします。

「インストール先」で自動パーティションを選択します。

「ネットワークとホスト名」をクリックします。

「ホスト名」をfedoraserver.jpに変更して「適用」をクリックします。

「設定」をクリックします。

「IPv4の設定」をクリックします。

方式の「手動」を選択します。

「追加」をクリックして、「アドレス」に192.168.1.3 、「ネットマスク」に24 、「ゲートウェイ」に192.168.1.1を入力します。

「DNSサーバー」に192.168.1.1を入力します。

「保存」をクリックします。

「オン」を選択します。

「完了」をクリックします。

「rootパスワード」をクリックします。

「rootパスワード」を入力します。

「完了」をクリックします。

「ユーザーの作成」をクリックします。

「フルネーム」「ユーザーネーム」にwebmasterを入力します。

「このユーザーを管理者にする」を選択します。

「このアカウントを使用する場合にパスワードを必要とする」を選択します。

「パスワード」を入力します。

「完了」をクリックします。

「インストール開始」をクリックします。

初心者におすすめ!コピペ(コピー&ペースト)でできる自宅サーバーFedora32の構築方法。

自宅サーバーFedora32(Linux)の作り方

初心者の方でもコピー、貼付けでLinux自宅サーバーを簡単に作れるように説明しています。
Webサーバー、メールサーバー、VPNサーバー、WordPressなどを設定します。

ご自身の設定情報を入力して、文章中の値を変更できますので簡単に設定できます。

DHCPのIPアドレス/マスク長:192.168.1.1/24
WebサーバのIPアドレス:192.168.1.3

Fedora32サーバー構築

Topへ戻る

サーバー構築準備:自宅サーバー準備作業

  • モデム設定(ご自身の環境に合わせてお調べください。)
  • サーバー本体
  • ルーターの設定
  • 有料ドメイン取得
  • isoファイルの容量確認
  • ImgBurn(インストールDVD作成ソフト)
  • Rufus(インストールUSBメモリ作成ソフト)
  • Tera Term(端末)
  • Gmailの登録
  • Thunderbirdのダウンロード・インストール

Fedora32:インストール

  • Fedora32ダウンロード
  • インストールDVD作成
  • Fedora32インストール

Fedora32:SSHサーバー設定

  • SSHサーバーのインストール

サーバー構築準備:SSHサーバーリモート接続(Tera Term)

  • SSHサーバーリモート接続の準備
  • Tera Termの使い方

Fedora32:初期設定

  • rootファイルシステムを拡張
  • 一般ユーザーの作成
  • rootになれるユーザーを限定
  • 一般ユーザーの削除
  • ファイアウォールとSELinuxを無効化
  • ネットワークの設定
  • システムの最新化
  • リポジトリを追加
  • パッケージの自動更新
  • 開発ツールパッケージのインストール
  • Vim(テキストエディタ)の設定
  • Sudo(root権限)の設定

Fedora32:デスクトップ環境設定

  • デスクトップ環境インストール
  • VNCサーバーの設定
  • Xrdpサーバーの設定
  • 日本語環境の設定

Fedora32:ファイルサーバー設定

  • sambaのインストール
  • sambaの初期設定

Fedora32:バックアップ設定

  • バックアップ領域の作成
  • 自動バックアップの設定

Fedora32:NTPサーバー設定(Chrony)

Fedora32:セキュリティ対策

  • アンチウィルスソフトの導入(Clam AntiVirus)
  • ファイル改竄検知システムの導入(Tripwire)
  • rootkit検知システムの導入(RkHunter)
  • SSHサーバー公開鍵認証方式接続の設定

Fedora32:ドメイン設定

  • DiCEのインストール
  • DiCE の設定
  • DiCEのイベントの追加

Fedora32:DNSサーバー設定

  • BINDのインストール
  • ゾーン情報の設定
  • TCP/UDP53番ポート開放
  • ポート開放テスト
  • BINDの起動と作動確認
  • chroot環境に移行
  • ホスト別名の設定
  • ホームネットワーク内PCのDNSを設定変更
  • 第二DNSの確認

Fedora32:Webサーバー設定

  • httpdのインストール
  • TCP80番ポート開放
  • ポート開放テスト
  • Perlのインストール
  • PHPのインストール
  • Rubyのインストール
  • Perlモジュールのインストール
  • ImageMagikのインストール
  • サーバー証明書の取得
  • SSLの設定

Fedora32:データベース設定

  • MariaDBの インストール

Fedora32:FTPサーバー設定

  • Vsftpd のインストール
  • FTPクライアントの設定

Fedora32:MAILサーバー設定

  • Postfixの設定
  • SMTP認証設定
  • Maildir形式メールボックスの作成
  • TCP25番、TCP587番ポート開放
  • ポート開放テスト
  • OP25B対策
  • Dovecotのインストール
  • TCP110番またはTCP143番ポート開放
  • ポート開放テスト
  • メールユーザーの追加
  • sendmailパスの確認
  • メールソフトの登録
  • サーバー証明書の取得
  • SSLの設定
  • TCP465番ポート開放
  • ポート開放テスト
  • TCP587番ポート閉鎖
  • ポート開放テスト
  • Dovecot設定
  • TCP995番またはTCP993番ポート開放
  • ポート開放テスト
  • メールソフトの設定変更
  • アンチウィルスソフトの連携(Clamav+Amavisd)

Fedora32:ログ解析設定

  • Webアクセスログ解析(AWStats)のインストール
  • メールログ解析(Pfiogsumm)のインストール

Fedora32:システム監視設定

  • Nagiosのインストール
  • Nagios起動

共通設定:VPNサーバー設定(Soft Ether VPN Saver)

  • Soft Ether VPN Serverインストール
  • Soft Ether VPN Server起動
  • UDP500番ポート、UDP4500番ポート開放
  • ポート開放テスト
  • Soft Ether VPN Server設定
  • Soft Ether VPN Serverダウンロード、インストール
  • Soft Ether VPN Server初期設定
  • 外部から固定ひかり電話子機接続

Fedora:サブドメイン設定

  • サブドメイン用ディレクトリ作成
  • テストページ作成
  • サーバー証明書取得
  • メインドメインSSL設定
  • サブドメインSSL設定

Fedora:複数ドメイン設定

  • 複数ドメイン用ディレクトリ作成
  • テストページ作成
  • サーバー証明書取得
  • 複数ドメインSSL設定
  • BIND設定
  • ゾーン情報の設定

Fedora:ブログサイト構築(Word Press)設定

  • Webサーバー、PHP設定
  • データベース設定
  • ブログ用データーベースを作成
  • WordPressインストール
  • WordPress設定
  • Apache設定
  • WordPress初期設定
  • WordPressをドメイン直下での表示設定

WordPress:使いやすいWordPressの作り方

  • 初期設定
  • 記事エディターの拡張
  • SEO対策
  • Site Kit by Google
  • 投稿記事ごとのSEO対策
  • ウィジェット追加
  • カスタムCSS
  • クイックタグの追加
  • スライドショー設置
  • コメント欄非表示
  • 関連記事表示
  • もくじ表示
  • リダイレクト検知
  • Google にインデックスさせる
  • マルチバイト機能の拡張
  • サイトマップを出力
  • お問い合わせフォーム
  • 予約自動投稿
  • 投稿記事の表示順
  • 代替え入力

共通設定:サーバー自動起動設定

  • BIOS設定

Fedora32:起動不能をインストールDVDで復旧

共通設定:ディスクのクローン作成

  • Ubuntu Desktopダウンロード
  • ライブDVD作成
  • ディスクのクローン作成

Fedora32:アップグレード

  • アップグレード

Fedora33:アップグレード

アップグレード

クライアントPC(Windows)でTera Termを起動します。

Tera Termの使い方

バックアップ設定を行います。

バックアップ設定

最新版のパッケージをインストールします。

[root@www ~]# dnf upgrade --refresh

再起動します。

[root@www ~]# shutdown -r now

ツールをインストールします。

[root@www ~]# dnf install dnf-plugin-system-upgrade
[root@www ~]# dnf system-upgrade download --refresh --releasever=33

指示に従ってコマンドを実行した後、再インストールします。

[root@www ~]# dnf system-upgrade download --refresh --releasever=33

アップグレードします。

[root@www ~]# dnf system-upgrade reboot

アップグレードを確認します。

[root@www ~]# cat /etc/os-release;
# NAME=Fedora
# VERSION="33 (Server Edition)"

インストールDVD作成

Fedora33 復元用にインストールDVDを作成します。

Fedora33ダウンロード

ダウンロードページからインストールディスクイメージ(Fedora-Server-dvd-x86_64-33-****.iso)をダウンロードします。

インストールDVDを作成

ImgBurnを使いFedora-Server-dvd-x86_64-33-****.isoでFedora32インストールディスクを作成し大切に保管します。

Fedora32:起動不能をインストールDVDで復旧

起動不能をインストールDVDで復旧

起動不能をインストールDVDで復旧します。
インストールDVDを投入して起動後、「Troubleshooting」を選択し「Enter」キーを押下します。

「Rescue a Fedora system」を選択し「Enter」キーを押下します。

「1」(continue)を入力し「Enter」キーを押下します。

「Enter」キーを押下します。

インストールDVDを取り出して、「reboot」と入力して、「Enter」キーを押下します。

起動を確認します。

Fedora:複数ドメイン設定

s50

複数ドメイン用ディレクトリ作成.

複数ドメイン用ディレクトリを作成します。

[root@www ~]# 50_1mkdir /var/www/html/virtual.jp

s51パーミッションを設定します。

[root@www ~]# 51_1chmod 777 /var/www/html/virtual.jp

s52複数ドメイン用設定ファイルを作成します。

[root@www ~]# 52_1vi /etc/httpd/conf.d/virtualhost-virtual.jp.conf
53_1<VirtualHost *:80>
    ServerName virtual.jp
    DocumentRoot /var/www/html/virtual.jp
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.virtual\.jp
    RewriteRule ^(.*)$ http://virtual.jp/$1 [R=301,L]
    ErrorLog logs/virtual.jp-error_log
    CustomLog logs/virtual.jp-access_log combined env=!no_log
</VirtualHost>

s54再起動します。

[root@www ~]# 54_1systemctl restart httpd

s55

テストページ作成.

テストページを作成します。

[root@www ~]# 55_1echo test >> /var/www/html/virtual.jp/index.html

s56Web作動確認サイトで複数ドメインの作動確認をします。

Free Monitoring Test Tools

複数ドメイン:http://virtual.jp
s57

サーバー証明書取得.

サーバー証明書を取得します。

[root@www ~]# 57_1certbot certonly --webroot -w /var/www/html/virtual.jp -m webmasterfedoraserver.jp -d virtual.jp --agree-tos

s58

複数ドメインSSL設定.

メインドメイン設定を表示します。

[root@www ~]# 58_1vi /etc/httpd/conf.d/virtualhost-00-fedoraserver.jp.conf

s59行番号を非表示にします。

59_1:set nonumber

s60SSLの設定項目をコピーしてメモ帳などに貼り付け、設定変更して保存します。

コピー範囲:<VirtualHost _default_:443>~</VirtualHost>

変更内容:<VirtualHost _default_:443> → <VirtualHost *:443>

<VirtualHost 60_1*:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot "60_2/var/www/html/virtual.jp"
ServerName 60_3virtual.jp:443

# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2

#   SSL Cipher Suite:
#   List the ciphers that the client is permitted to negotiate.
#   See the mod_ssl documentation for a complete list.
SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA

#   Speed-optimized SSL Cipher configuration:
#   If speed is your main concern (on busy HTTPS servers e.g.),
#   you might want to force clients to specific, performance
#   optimized ciphers. In this case, prepend those ciphers
#   to the SSLCipherSuite list, and enable SSLHonorCipherOrder.
#   Caveat: by giving precedence to RC4-SHA and AES128-SHA
#   (as in the example below), most connections will no longer
#   have perfect forward secrecy - if the server's key is
#   compromised, captures of past or future traffic must be
#   considered compromised, too.
#SSLCipherSuite RC4-SHA:AES128-SHA:HIGH:MEDIUM:!aNULL:!MD5
#SSLHonorCipherOrder on

#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile 61_1/etc/letsencrypt/live/virtual.jp/cert.pem

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile 62_1/etc/letsencrypt/live/virtual.jp/privkey.pem

#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convinience.
SSLCertificateChainFile 63_1/etc/letsencrypt/live/virtual.jp/chain.pem

#   Certificate Authority (CA):
#   Set the CA certificate verification path where to find CA
#   certificates for client authentication or alternatively one
#   huge file containing all of them (file must be PEM encoded)
#SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt

#   Client Authentication (Type):
#   Client certificate verification type and depth.  Types are
#   none, optional, require and optional_no_ca.  Depth is a
#   number which specifies how deeply to verify the certificate
#   issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth  10

#   Access Control:
#   With SSLRequire you can do per-directory access control based
#   on arbitrary complex boolean expressions containing server
#   variable checks and other lookup directives.  The syntax is a
#   mixture between C and Perl.  See the mod_ssl documentation
#   for more details.
#<Location />
#SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
#            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
#            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
#            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
#            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
#           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
#</Location>

#   SSL Engine Options:
#   Set various options for the SSL engine.
#   o FakeBasicAuth:
#     Translate the client X.509 into a Basic Authorisation.  This means that
#     the standard Auth/DBMAuth methods can be used for access control.  The
#     user name is the `one line' version of the client's X.509 certificate.
#     Note that no password is obtained from the user. Every entry in the user
#     file needs this password: `xxj31ZMTZzkVA'.
#   o ExportCertData:
#     This exports two additional environment variables: SSL_CLIENT_CERT and
#     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
#     server (always existing) and the client (only existing when client
#     authentication is used). This can be used to import the certificates
#     into CGI scripts.
#   o StdEnvVars:
#     This exports the standard SSL/TLS related `SSL_*' environment variables.
#     Per default this exportation is switched off for performance reasons,
#     because the extraction step is an expensive operation and is usually
#     useless for serving static content. So one usually enables the
#     exportation for CGI and SSI requests only.
#   o StrictRequire:
#     This denies access when "SSLRequireSSL" or "SSLRequire" applied even
#     under a "Satisfy any" situation, i.e. when it applies access is denied
#     and no other module can change it.
#   o OptRenegotiate:
#     This enables optimized SSL connection renegotiation handling when SSL
#     directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
    SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

#   SSL Protocol Adjustments:
#   The safe and default but still SSL/TLS standard compliant shutdown
#   approach is that mod_ssl sends the close notify alert but doesn't wait for
#   the close notify alert from client. When you need a different shutdown
#   approach you can use one of the following variables:
#   o ssl-unclean-shutdown:
#     This forces an unclean shutdown when the connection is closed, i.e. no
#     SSL close notify alert is send or allowed to received.  This violates
#     the SSL/TLS standard but is needed for some brain-dead browsers. Use
#     this when you receive I/O errors because of the standard approach where
#     mod_ssl sends the close notify alert.
#   o ssl-accurate-shutdown:
#     This forces an accurate shutdown when the connection is closed, i.e. a
#     SSL close notify alert is send and mod_ssl waits for the close notify
#     alert of the client. This is 100% SSL/TLS standard compliant, but in
#     practice often causes hanging connections with brain-dead browsers. Use
#     this only for browsers where you know that their SSL implementation
#     works correctly.
#   Notice: Most problems of broken clients are also related to the HTTP
#   keep-alive facility, so you usually additionally want to disable
#   keep-alive for those clients, too. Use variable "nokeepalive" for this.
#   Similarly, one has to force some clients to use HTTP/1.0 to workaround
#   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
#   "force-response-1.0" for this.
BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
CustomLog logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

s64ファイルを設定します。

[root@www ~]# 64_1vi /etc/httpd/conf.d/virtualhost-virtual.jp.conf

s65先に保存したものを最終行に貼り付けます。

<VirtualHost *:80>
    ServerName virtual.jp
    DocumentRoot /var/www/html/virtual.jp
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.virtual\.jp
    RewriteRule ^(.*)$ http://virtual.jp/$1 [R=301,L]
    ErrorLog logs/virtual.jp-error_log
    CustomLog logs/virtual.jp-access_log combined env=!no_log
</VirtualHost>

<VirtualHost *:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html/virtual.jp"
ServerName virtual.jp:443

# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2

#   SSL Cipher Suite:
#   List the ciphers that the client is permitted to negotiate.
#   See the mod_ssl documentation for a complete list.
SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA

#   Speed-optimized SSL Cipher configuration:
#   If speed is your main concern (on busy HTTPS servers e.g.),
#   you might want to force clients to specific, performance
#   optimized ciphers. In this case, prepend those ciphers
#   to the SSLCipherSuite list, and enable SSLHonorCipherOrder.
#   Caveat: by giving precedence to RC4-SHA and AES128-SHA
#   (as in the example below), most connections will no longer
#   have perfect forward secrecy - if the server's key is
#   compromised, captures of past or future traffic must be
#   considered compromised, too.
#SSLCipherSuite RC4-SHA:AES128-SHA:HIGH:MEDIUM:!aNULL:!MD5
#SSLHonorCipherOrder on

#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/letsencrypt/live/virtual.jp/cert.pem

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /etc/letsencrypt/live/virtual.jp/privkey.pem

#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convinience.
SSLCertificateChainFile /etc/letsencrypt/live/virtual.jp/chain.pem

#   Certificate Authority (CA):
#   Set the CA certificate verification path where to find CA
#   certificates for client authentication or alternatively one
#   huge file containing all of them (file must be PEM encoded)
#SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt

#   Client Authentication (Type):
#   Client certificate verification type and depth.  Types are
#   none, optional, require and optional_no_ca.  Depth is a
#   number which specifies how deeply to verify the certificate
#   issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth  10

#   Access Control:
#   With SSLRequire you can do per-directory access control based
#   on arbitrary complex boolean expressions containing server
#   variable checks and other lookup directives.  The syntax is a
#   mixture between C and Perl.  See the mod_ssl documentation
#   for more details.
#<Location />
#SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
#            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
#            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
#            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
#            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
#           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
#</Location>

#   SSL Engine Options:
#   Set various options for the SSL engine.
#   o FakeBasicAuth:
#     Translate the client X.509 into a Basic Authorisation.  This means that
#     the standard Auth/DBMAuth methods can be used for access control.  The
#     user name is the `one line' version of the client's X.509 certificate.
#     Note that no password is obtained from the user. Every entry in the user
#     file needs this password: `xxj31ZMTZzkVA'.
#   o ExportCertData:
#     This exports two additional environment variables: SSL_CLIENT_CERT and
#     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
#     server (always existing) and the client (only existing when client
#     authentication is used). This can be used to import the certificates
#     into CGI scripts.
#   o StdEnvVars:
#     This exports the standard SSL/TLS related `SSL_*' environment variables.
#     Per default this exportation is switched off for performance reasons,
#     because the extraction step is an expensive operation and is usually
#     useless for serving static content. So one usually enables the
#     exportation for CGI and SSI requests only.
#   o StrictRequire:
#     This denies access when "SSLRequireSSL" or "SSLRequire" applied even
#     under a "Satisfy any" situation, i.e. when it applies access is denied
#     and no other module can change it.
#   o OptRenegotiate:
#     This enables optimized SSL connection renegotiation handling when SSL
#     directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
    SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

#   SSL Protocol Adjustments:
#   The safe and default but still SSL/TLS standard compliant shutdown
#   approach is that mod_ssl sends the close notify alert but doesn't wait for
#   the close notify alert from client. When you need a different shutdown
#   approach you can use one of the following variables:
#   o ssl-unclean-shutdown:
#     This forces an unclean shutdown when the connection is closed, i.e. no
#     SSL close notify alert is send or allowed to received.  This violates
#     the SSL/TLS standard but is needed for some brain-dead browsers. Use
#     this when you receive I/O errors because of the standard approach where
#     mod_ssl sends the close notify alert.
#   o ssl-accurate-shutdown:
#     This forces an accurate shutdown when the connection is closed, i.e. a
#     SSL close notify alert is send and mod_ssl waits for the close notify
#     alert of the client. This is 100% SSL/TLS standard compliant, but in
#     practice often causes hanging connections with brain-dead browsers. Use
#     this only for browsers where you know that their SSL implementation
#     works correctly.
#   Notice: Most problems of broken clients are also related to the HTTP
#   keep-alive facility, so you usually additionally want to disable
#   keep-alive for those clients, too. Use variable "nokeepalive" for this.
#   Similarly, one has to force some clients to use HTTP/1.0 to workaround
#   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
#   "force-response-1.0" for this.
BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
CustomLog logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

s66

BIND設定.

ホームネットワーク内でドメイン名で表示する様にBIND を設定します。

[root@www ~]# 66_1vi /etc/named.conf

//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html


options {
        listen-on port 53 { any; };
        listen-on-v6 port 53 { none; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        recursing-file  "/var/named/data/named.recursing";
        secroots-file   "/var/named/data/named.secroots";
        allow-query     { localhost; 192.168.1.1/24; };
        allow-transfer      { localhost; 192.168.1.1/24; };

        /*
         - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
         - If you are building a RECURSIVE (caching) DNS server, you need to enable
           recursion.
         - If your recursive DNS server has a public IP address, you MUST enable access
           control to limit queries to your legitimate users. Failing to do so will
           cause your server to become part of large scale DNS amplification
           attacks. Implementing BCP38 within your network would greatly
           reduce such attack surface
        */
        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";

        pid-file "/run/named/named.pid";
        session-keyfile "/run/named/session.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

view "internal" {
        match-clients {
                localhost;
                192.168.1.1/24;
        };
        zone "." IN {
                type hint;
                file "named.ca";
        };
        zone "fedoraserver.jp" IN {
                type master;
                file "fedoraserver.jp.lan";
                allow-update { none; };
        };
67_1        zone "virtual.jp" IN {
                type master;
                file "virtual.jp.lan";
                allow-update { none; };
        };
        zone "1.168.192.in-addr.arpa" IN {
                type master;
                file "1.168.192.db";
                allow-update { none; };
        };
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
};

s68

ゾーン情報の設定.

内部向け正引き情報ファイルを作成します。

[root@www ~]# 68_1vi /var/named/virtual.jp.lan

69_1$TTL 86400
@   IN  SOA     virtual.jp. root.virtual.jp. (
        2014071001  ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)
        IN  NS      virtual.jp.
        IN  MX 10   virtual.jp.
@       IN  A       192.168.1.3
*       IN  A       192.168.1.3

s70再起動します。

[root@www ~]# 70_1reboot

s71Web作動確認サイトで複数ドメインの作動確認をします。

Free Monitoring Test Tools

複数ドメイン:https://virtual.jp

Fedora:サブドメイン設定

s50

サブドメイン用ディレクトリ作成.

サブドメイン用ディレクトリを作成します。

[root@www ~]# 50_1mkdir /var/www/html/sub.fedoraserver.jp

s51パーミッションを設定します。

[root@www ~]# 51_1chmod 777 /var/www/html/sub.fedoraserver.jp

s52サブドメイン用設定ファイルを作成します。

[root@www ~]# 52_1vi /etc/httpd/conf.d/virtualhost-sub.fedoraserver.jp.conf
52_2<VirtualHost *:80>
    ServerName sub.fedoraserver.jp
    DocumentRoot /var/www/html/sub.fedoraserver.jp
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.sub\.fedoraserver\.jp
    RewriteRule ^(.*)$ http://sub.fedoraserver.jp/$1 [R=301,L]
    ErrorLog logs/sub.fedoraserver.jp-error_log
    CustomLog logs/sub.fedoraserver.jp-access_log combined env=!no_log
</VirtualHost>

s53再起動します。

[root@www ~]# 53_1systemctl restart httpd

s54

テストページ作成.

テストページを作成します。

[root@www ~]# 54_1echo test >> /var/www/html/sub.fedoraserver.jp/index.html

s55Web作動確認サイトでサブドメインの作動確認をします。

Free Monitoring Test Tools

サブドメイン:http://sub.fedoraserver.jp
s56

サーバー証明書取得.

サーバー証明書を取得します。

[root@www ~]# 56_1certbot certonly --webroot -w /var/www/html/sub.fedoraserver.jp -m webmasterfedoraserver.jp -d sub.fedoraserver.jp --agree-tos

s57

メインドメインSSL設定.

ファイルのバックアップを作成します。

[root@www ~]# 57_1cp /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.bk

s58ファイルを設定します。

[root@www ~]# 58_1vi /etc/httpd/conf.d/ssl.conf

s59行番号を非表示にします。

59_1:set nonumber

s60SSLの設定項目をコピーしてメモ帳などに貼り付け、設定変更して保存します。

コピー範囲:<VirtualHost _default_:443>~</VirtualHost>

変更内容:<VirtualHost _default_:443> → <VirtualHost *:443>

<VirtualHost 60_1*:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html"
ServerName fedoraserver.jp:443

# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2

#   SSL Cipher Suite:
#   List the ciphers that the client is permitted to negotiate.
#   See the mod_ssl documentation for a complete list.
SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA

#   Speed-optimized SSL Cipher configuration:
#   If speed is your main concern (on busy HTTPS servers e.g.),
#   you might want to force clients to specific, performance
#   optimized ciphers. In this case, prepend those ciphers
#   to the SSLCipherSuite list, and enable SSLHonorCipherOrder.
#   Caveat: by giving precedence to RC4-SHA and AES128-SHA
#   (as in the example below), most connections will no longer
#   have perfect forward secrecy - if the server's key is
#   compromised, captures of past or future traffic must be
#   considered compromised, too.
#SSLCipherSuite RC4-SHA:AES128-SHA:HIGH:MEDIUM:!aNULL:!MD5
#SSLHonorCipherOrder on

#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/letsencrypt/live/fedoraserver.jp/cert.pem

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /etc/letsencrypt/live/fedoraserver.jp/privkey.pem

#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convinience.
SSLCertificateChainFile /etc/letsencrypt/live/fedoraserver.jp/chain.pem

#   Certificate Authority (CA):
#   Set the CA certificate verification path where to find CA
#   certificates for client authentication or alternatively one
#   huge file containing all of them (file must be PEM encoded)
#SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt

#   Client Authentication (Type):
#   Client certificate verification type and depth.  Types are
#   none, optional, require and optional_no_ca.  Depth is a
#   number which specifies how deeply to verify the certificate
#   issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth  10

#   Access Control:
#   With SSLRequire you can do per-directory access control based
#   on arbitrary complex boolean expressions containing server
#   variable checks and other lookup directives.  The syntax is a
#   mixture between C and Perl.  See the mod_ssl documentation
#   for more details.
#<Location />
#SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
#            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
#            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
#            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
#            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
#           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
#</Location>

#   SSL Engine Options:
#   Set various options for the SSL engine.
#   o FakeBasicAuth:
#     Translate the client X.509 into a Basic Authorisation.  This means that
#     the standard Auth/DBMAuth methods can be used for access control.  The
#     user name is the `one line' version of the client's X.509 certificate.
#     Note that no password is obtained from the user. Every entry in the user
#     file needs this password: `xxj31ZMTZzkVA'.
#   o ExportCertData:
#     This exports two additional environment variables: SSL_CLIENT_CERT and
#     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
#     server (always existing) and the client (only existing when client
#     authentication is used). This can be used to import the certificates
#     into CGI scripts.
#   o StdEnvVars:
#     This exports the standard SSL/TLS related `SSL_*' environment variables.
#     Per default this exportation is switched off for performance reasons,
#     because the extraction step is an expensive operation and is usually
#     exportation for CGI and SSI requests only.
#   o StrictRequire:
#     This denies access when "SSLRequireSSL" or "SSLRequire" applied even
#     under a "Satisfy any" situation, i.e. when it applies access is denied
#     and no other module can change it.
#   o OptRenegotiate:
#     This enables optimized SSL connection renegotiation handling when SSL
#     directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
    SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

#   SSL Protocol Adjustments:
#   The safe and default but still SSL/TLS standard compliant shutdown
#   approach is that mod_ssl sends the close notify alert but doesn't wait for
#   the close notify alert from client. When you need a different shutdown
#   approach you can use one of the following variables:
#   o ssl-unclean-shutdown:
#     This forces an unclean shutdown when the connection is closed, i.e. no
#     SSL close notify alert is send or allowed to received.  This violates
#     the SSL/TLS standard but is needed for some brain-dead browsers. Use
#     this when you receive I/O errors because of the standard approach where
#     mod_ssl sends the close notify alert.
#   o ssl-accurate-shutdown:
#     This forces an accurate shutdown when the connection is closed, i.e. a
#     SSL close notify alert is send and mod_ssl waits for the close notify
#     alert of the client. This is 100% SSL/TLS standard compliant, but in
#     practice often causes hanging connections with brain-dead browsers. Use
#     this only for browsers where you know that their SSL implementation
#     works correctly.
#   Notice: Most problems of broken clients are also related to the HTTP
#   keep-alive facility, so you usually additionally want to disable
#   keep-alive for those clients, too. Use variable "nokeepalive" for this.
#   Similarly, one has to force some clients to use HTTP/1.0 to workaround
#   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
#   "force-response-1.0" for this.
BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
CustomLog logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

s62ファイルを設定します。

[root@www ~]# 62_1vi /etc/httpd/conf.d/virtualhost-00-fedoraserver.jp.conf

s63先に保存したものを最終行に貼り付けます。

<VirtualHost *:80>
    ServerName fedoraserver.jp
    DocumentRoot /var/www/html/fedoraserver.jp
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.fedoraserver\.jp
    RewriteRule ^(.*)$ http://fedoraserver.jp/$1 [R=301,L]
</VirtualHost>

<VirtualHost *:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html"
ServerName fedoraserver.jp:443

# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2

#   SSL Cipher Suite:
#   List the ciphers that the client is permitted to negotiate.
#   See the mod_ssl documentation for a complete list.
SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA

#   Speed-optimized SSL Cipher configuration:
#   If speed is your main concern (on busy HTTPS servers e.g.),
#   you might want to force clients to specific, performance
#   optimized ciphers. In this case, prepend those ciphers
#   to the SSLCipherSuite list, and enable SSLHonorCipherOrder.
#   Caveat: by giving precedence to RC4-SHA and AES128-SHA
#   (as in the example below), most connections will no longer
#   have perfect forward secrecy - if the server's key is
#   compromised, captures of past or future traffic must be
#   considered compromised, too.
#SSLCipherSuite RC4-SHA:AES128-SHA:HIGH:MEDIUM:!aNULL:!MD5
#SSLHonorCipherOrder on

#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/letsencrypt/live/fedoraserver.jp/cert.pem

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /etc/letsencrypt/live/fedoraserver.jp/privkey.pem

#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convinience.
SSLCertificateChainFile /etc/letsencrypt/live/fedoraserver.jp/chain.pem

#   Certificate Authority (CA):
#   Set the CA certificate verification path where to find CA
#   certificates for client authentication or alternatively one
#   huge file containing all of them (file must be PEM encoded)
#SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt

#   Client Authentication (Type):
#   Client certificate verification type and depth.  Types are
#   none, optional, require and optional_no_ca.  Depth is a
#   number which specifies how deeply to verify the certificate
#   issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth  10

#   Access Control:
#   With SSLRequire you can do per-directory access control based
#   on arbitrary complex boolean expressions containing server
#   variable checks and other lookup directives.  The syntax is a
#   mixture between C and Perl.  See the mod_ssl documentation
#   for more details.
#<Location />
#SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
#            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
#            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
#            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
#            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
#           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
#</Location>

#   SSL Engine Options:
#   Set various options for the SSL engine.
#   o FakeBasicAuth:
#     Translate the client X.509 into a Basic Authorisation.  This means that
#     the standard Auth/DBMAuth methods can be used for access control.  The
#     user name is the `one line' version of the client's X.509 certificate.
#     Note that no password is obtained from the user. Every entry in the user
#     file needs this password: `xxj31ZMTZzkVA'.
#   o ExportCertData:
#     This exports two additional environment variables: SSL_CLIENT_CERT and
#     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
#     server (always existing) and the client (only existing when client
#     authentication is used). This can be used to import the certificates
#     into CGI scripts.
#   o StdEnvVars:
#     This exports the standard SSL/TLS related `SSL_*' environment variables.
#     Per default this exportation is switched off for performance reasons,
#     because the extraction step is an expensive operation and is usually
#     useless for serving static content. So one usually enables the
#     exportation for CGI and SSI requests only.
#   o StrictRequire:
#     This denies access when "SSLRequireSSL" or "SSLRequire" applied even
#     under a "Satisfy any" situation, i.e. when it applies access is denied
#     and no other module can change it.
#   o OptRenegotiate:
#     This enables optimized SSL connection renegotiation handling when SSL
#     directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
    SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

#   SSL Protocol Adjustments:
#   The safe and default but still SSL/TLS standard compliant shutdown
#   approach is that mod_ssl sends the close notify alert but doesn't wait for
#   the close notify alert from client. When you need a different shutdown
#   approach you can use one of the following variables:
#   o ssl-unclean-shutdown:
#     This forces an unclean shutdown when the connection is closed, i.e. no
#     SSL close notify alert is send or allowed to received.  This violates
#     the SSL/TLS standard but is needed for some brain-dead browsers. Use
#     this when you receive I/O errors because of the standard approach where
#     mod_ssl sends the close notify alert.
#   o ssl-accurate-shutdown:
#     This forces an accurate shutdown when the connection is closed, i.e. a
#     SSL close notify alert is send and mod_ssl waits for the close notify
#     alert of the client. This is 100% SSL/TLS standard compliant, but in
#     practice often causes hanging connections with brain-dead browsers. Use
#     this only for browsers where you know that their SSL implementation
#     works correctly.
#   Notice: Most problems of broken clients are also related to the HTTP
#   keep-alive facility, so you usually additionally want to disable
#   keep-alive for those clients, too. Use variable "nokeepalive" for this.
#   Similarly, one has to force some clients to use HTTP/1.0 to workaround
#   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
#   "force-response-1.0" for this.
BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
CustomLog logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

s64ファイルを設定します。

[root@www ~]# 64_1vi /etc/httpd/conf.d/ssl.conf

s65<VirtualHost _default_:443>~</VirtualHost>を削除します。

#
# When we also provide SSL we have to listen to the
# the HTTPS port in addition.
#
Listen 443 https

##
##  SSL Global Context
##
##  All SSL configuration in this context applies both to
##  the main server and all SSL-enabled virtual hosts.
##

#   Pass Phrase Dialog:
#   Configure the pass phrase gathering process.
#   The filtering dialog program (`builtin' is a internal
#   terminal dialog) has to provide the pass phrase on stdout.
SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog

#   Inter-Process Session Cache:
#   Configure the SSL Session Cache: First the mechanism
#   to use and second the expiring timeout (in seconds).
SSLSessionCache         shmcb:/run/httpd/sslcache(512000)
SSLSessionCacheTimeout  300

#   Pseudo Random Number Generator (PRNG):
#   Configure one or more sources to seed the PRNG of the
#   SSL library. The seed data should be of good random quality.
#   WARNING! On some platforms /dev/random blocks if not enough entropy
#   is available. This means you then cannot use the /dev/random device
#   because it would lead to very long connection times (as long as
#   it requires to make more entropy available). But usually those
#   platforms additionally provide a /dev/urandom device which doesn't
#   block. So, if available, use this one instead. Read the mod_ssl User
#   Manual for more details.
SSLRandomSeed startup file:/dev/urandom  256
SSLRandomSeed connect builtin
#SSLRandomSeed startup file:/dev/random  512
#SSLRandomSeed connect file:/dev/random  512
#SSLRandomSeed connect file:/dev/urandom 512

#
# Use "SSLCryptoDevice" to enable any supported hardware
# accelerators. Use "openssl engine -v" to list supported
# engine names.  NOTE: If you enable an accelerator and the
# server does not start, consult the error logs and ensure
# your accelerator is functioning properly.
#
SSLCryptoDevice builtin
#SSLCryptoDevice ubsec
#以下を削除

s66

サブドメインSSL設定.

先に保存したものをサブドメイン設定に修正します。

1行目:「_default_」を「*」に変更し、全てのドメインをサブドメインに変更します。

ドメイン:debianserver.jp

サブドメイン:sub.debianserver.jp

<VirtualHost 66_1*:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html66_2/sub.fedoraserver.jp"
ServerName 66_3 sub.fedoraserver.jp:443

# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2

#   SSL Cipher Suite:
#   List the ciphers that the client is permitted to negotiate.
#   See the mod_ssl documentation for a complete list.
SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA

#   Speed-optimized SSL Cipher configuration:
#   If speed is your main concern (on busy HTTPS servers e.g.),
#   you might want to force clients to specific, performance
#   optimized ciphers. In this case, prepend those ciphers
#   to the SSLCipherSuite list, and enable SSLHonorCipherOrder.
#   Caveat: by giving precedence to RC4-SHA and AES128-SHA
#   (as in the example below), most connections will no longer
#   have perfect forward secrecy - if the server's key is
#   compromised, captures of past or future traffic must be
#   considered compromised, too.
#SSLCipherSuite RC4-SHA:AES128-SHA:HIGH:MEDIUM:!aNULL:!MD5
#SSLHonorCipherOrder on

#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/letsencrypt/live/66_4sub.fedoraserver.jp/cert.pem

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /etc/letsencrypt/live/66_5sub.fedoraserver.jp/privkey.pem

#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convinience.
SSLCertificateChainFile /etc/letsencrypt/live/66_6sub.fedoraserver.jp/chain.pem

#   Certificate Authority (CA):
#   Set the CA certificate verification path where to find CA
#   certificates for client authentication or alternatively one
#   huge file containing all of them (file must be PEM encoded)
#SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt

#   Client Authentication (Type):
#   Client certificate verification type and depth.  Types are
#   none, optional, require and optional_no_ca.  Depth is a
#   number which specifies how deeply to verify the certificate
#   issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth  10

#   Access Control:
#   With SSLRequire you can do per-directory access control based
#   on arbitrary complex boolean expressions containing server
#   variable checks and other lookup directives.  The syntax is a
#   mixture between C and Perl.  See the mod_ssl documentation
#   for more details.
#<Location />
#SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
#            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
#            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
#            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
#            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
#           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
#</Location>

#   SSL Engine Options:
#   Set various options for the SSL engine.
#   o FakeBasicAuth:
#     Translate the client X.509 into a Basic Authorisation.  This means that
#     the standard Auth/DBMAuth methods can be used for access control.  The
#     user name is the `one line' version of the client's X.509 certificate.
#     Note that no password is obtained from the user. Every entry in the user
#     file needs this password: `xxj31ZMTZzkVA'.
#   o ExportCertData:
#     This exports two additional environment variables: SSL_CLIENT_CERT and
#     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
#     server (always existing) and the client (only existing when client
#     authentication is used). This can be used to import the certificates
#     into CGI scripts.
#   o StdEnvVars:
#     This exports the standard SSL/TLS related `SSL_*' environment variables.
#     Per default this exportation is switched off for performance reasons,
#     because the extraction step is an expensive operation and is usually
#     useless for serving static content. So one usually enables the
#     exportation for CGI and SSI requests only.
#   o StrictRequire:
#     This denies access when "SSLRequireSSL" or "SSLRequire" applied even
#     under a "Satisfy any" situation, i.e. when it applies access is denied
#     and no other module can change it.
#   o OptRenegotiate:
#     This enables optimized SSL connection renegotiation handling when SSL
#     directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
    SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

#   SSL Protocol Adjustments:
#   The safe and default but still SSL/TLS standard compliant shutdown
#   approach is that mod_ssl sends the close notify alert but doesn't wait for
#   the close notify alert from client. When you need a different shutdown
#   approach you can use one of the following variables:
#   o ssl-unclean-shutdown:
#     This forces an unclean shutdown when the connection is closed, i.e. no
#     SSL close notify alert is send or allowed to received.  This violates
#     the SSL/TLS standard but is needed for some brain-dead browsers. Use
#     this when you receive I/O errors because of the standard approach where
#     mod_ssl sends the close notify alert.
#   o ssl-accurate-shutdown:
#     This forces an accurate shutdown when the connection is closed, i.e. a
#     SSL close notify alert is send and mod_ssl waits for the close notify
#     alert of the client. This is 100% SSL/TLS standard compliant, but in
#     practice often causes hanging connections with brain-dead browsers. Use
#     this only for browsers where you know that their SSL implementation
#     works correctly.
#   Notice: Most problems of broken clients are also related to the HTTP
#   keep-alive facility, so you usually additionally want to disable
#   keep-alive for those clients, too. Use variable "nokeepalive" for this.
#   Similarly, one has to force some clients to use HTTP/1.0 to workaround
#   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
#   "force-response-1.0" for this.
BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
CustomLog logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

s67ファイルを設定します。

[root@www ~]# 67_1vi /etc/httpd/conf.d/virtualhost-sub.fedoraserver.jp.conf

s68先に修正したものを最終行に貼り付けます。

<VirtualHost *:80>
    ServerName sub.fedoraserver.jp
    DocumentRoot /var/www/html/sub.fedoraserver.jp
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.sub\.fedoraserver\.jp
    RewriteRule ^(.*)$ http://sub.fedoraserver.jp/$1 [R=301,L]
    ErrorLog logs/sub.fedoraserver.jp-error_log
    CustomLog logs/sub.fedoraserver.jp-access_log combined env=!no_log
</VirtualHost>

<VirtualHost *:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html/sub.fedoraserver.jp"
ServerName sub.fedoraserver.jp:443

# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2

#   SSL Cipher Suite:
#   List the ciphers that the client is permitted to negotiate.
#   See the mod_ssl documentation for a complete list.
SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA

#   Speed-optimized SSL Cipher configuration:
#   If speed is your main concern (on busy HTTPS servers e.g.),
#   you might want to force clients to specific, performance
#   optimized ciphers. In this case, prepend those ciphers
#   to the SSLCipherSuite list, and enable SSLHonorCipherOrder.
#   Caveat: by giving precedence to RC4-SHA and AES128-SHA
#   (as in the example below), most connections will no longer
#   have perfect forward secrecy - if the server's key is
#   compromised, captures of past or future traffic must be
#   considered compromised, too.
#SSLCipherSuite RC4-SHA:AES128-SHA:HIGH:MEDIUM:!aNULL:!MD5
#SSLHonorCipherOrder on

#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/letsencrypt/live/sub.fedoraserver.jp/cert.pem

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /etc/letsencrypt/live/sub.fedoraserver.jp/privkey.pem

#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convinience.
SSLCertificateChainFile /etc/letsencrypt/live/sub.fedoraserver.jp/chain.pem

#   Certificate Authority (CA):
#   Set the CA certificate verification path where to find CA
#   certificates for client authentication or alternatively one
#   huge file containing all of them (file must be PEM encoded)
#SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt

#   Client Authentication (Type):
#   Client certificate verification type and depth.  Types are
#   none, optional, require and optional_no_ca.  Depth is a
#   number which specifies how deeply to verify the certificate
#   issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth  10

#   Access Control:
#   With SSLRequire you can do per-directory access control based
#   on arbitrary complex boolean expressions containing server
#   variable checks and other lookup directives.  The syntax is a
#   mixture between C and Perl.  See the mod_ssl documentation
#   for more details.
#<Location />
#SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
#            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
#            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
#            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
#            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
#           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
#</Location>

#   SSL Engine Options:
#   Set various options for the SSL engine.
#   o FakeBasicAuth:
#     Translate the client X.509 into a Basic Authorisation.  This means that
#     the standard Auth/DBMAuth methods can be used for access control.  The
#     user name is the `one line' version of the client's X.509 certificate.
#     Note that no password is obtained from the user. Every entry in the user
#     file needs this password: `xxj31ZMTZzkVA'.
#   o ExportCertData:
#     This exports two additional environment variables: SSL_CLIENT_CERT and
#     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
#     server (always existing) and the client (only existing when client
#     authentication is used). This can be used to import the certificates
#     into CGI scripts.
#   o StdEnvVars:
#     This exports the standard SSL/TLS related `SSL_*' environment variables.
#     Per default this exportation is switched off for performance reasons,
#     because the extraction step is an expensive operation and is usually
#     useless for serving static content. So one usually enables the
#     exportation for CGI and SSI requests only.
#   o StrictRequire:
#     This denies access when "SSLRequireSSL" or "SSLRequire" applied even
#     under a "Satisfy any" situation, i.e. when it applies access is denied
#     and no other module can change it.
#   o OptRenegotiate:
#     This enables optimized SSL connection renegotiation handling when SSL
#     directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
    SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

#   SSL Protocol Adjustments:
#   The safe and default but still SSL/TLS standard compliant shutdown
#   approach is that mod_ssl sends the close notify alert but doesn't wait for
#   the close notify alert from client. When you need a different shutdown
#   approach you can use one of the following variables:
#   o ssl-unclean-shutdown:
#     This forces an unclean shutdown when the connection is closed, i.e. no
#     SSL close notify alert is send or allowed to received.  This violates
#     the SSL/TLS standard but is needed for some brain-dead browsers. Use
#     this when you receive I/O errors because of the standard approach where
#     mod_ssl sends the close notify alert.
#   o ssl-accurate-shutdown:
#     This forces an accurate shutdown when the connection is closed, i.e. a
#     SSL close notify alert is send and mod_ssl waits for the close notify
#     alert of the client. This is 100% SSL/TLS standard compliant, but in
#     practice often causes hanging connections with brain-dead browsers. Use
#     this only for browsers where you know that their SSL implementation
#     works correctly.
#   Notice: Most problems of broken clients are also related to the HTTP
#   keep-alive facility, so you usually additionally want to disable
#   keep-alive for those clients, too. Use variable "nokeepalive" for this.
#   Similarly, one has to force some clients to use HTTP/1.0 to workaround
#   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
#   "force-response-1.0" for this.
BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
CustomLog logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

s70再起動します。

[root@www ~]# 70_1systemctl restart httpd

s71Web作動確認サイトでサブドメインの作動確認をします。

Free Monitoring Test Tools

サブドメイン:https://sub.fedoraserver.jp

Fedora32:ログ解析設定

Webアクセスログ解析(AWStats)のインストール

AWStatsをインストールします。

[root@www ~]# dnf -y install awstats

自動作成されているawstats.fedoraserver.jp.conf を設定します。

[root@www ~]# vi /etc/awstats/awstats.fedoraserver.jp.conf 

125行目:変更します。

LogFormat=1

156行目:ホスト名を設定します。

SiteDomain="fedoraserver.jp"

171行目:除外したドメイン名やIPアドレスを追記します。

HostAliases="localhost 127.0.0.1 REGEX[^.*fedoraserver\.jp$] REGEX[^192\.168\.1\.]"

awstats.confを設定します。

[root@www ~]# vi /etc/httpd/conf.d/awstats.conf

30行目:アクセス許可IPを追記します。

        Require ip 192.168.1.1/24

再起動します。

[root@www ~]# systemctl restart httpd

1時間毎に自動更新する設定をします。

[root@www ~]# /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=fedoraserver.jp -update

Web ブラウザを起動し、「http://fedoraserver.jp/awstats/awstats.pl」にアクセスして、作動確認します。

awstats

メールログ解析(Pfiogsumm)のインストール

pflogsumm をインストールします。

[root@www ~]# dnf -y install postfix-perl-scripts

メールログのサマリーを出力します。

[root@www ~]# perl /usr/sbin/pflogsumm -d yesterday /var/log/maillog
Postfix log summaries for Jul 29

Grand Totals
------------
messages

      8   received
      8   delivered
      2   forwarded
      1   deferred  (1  deferrals)
      0   bounced
      0   rejected (0%)
      0   reject warnings
      0   held
      0   discarded (0%)

   2428k  bytes received
   2429k  bytes delivered
      3   senders
      2   sending hosts/domains
      2   recipients
      2   recipient hosts/domains


Per-Hour Traffic Summary
------------------------
    time          received  delivered   deferred    bounced     rejected
    --------------------------------------------------------------------
    0000-0100           0          0          0          0          0
    0100-0200           0          0          0          0          0
    0200-0300           0          0          0          0          0
…

root宛てにメール送信する設定をします。

[root@www ~]# crontab -e

毎日午前1時にメール送信する設定をします。

[root@www ~]# 00 01 * * * perl /usr/sbin/pflogsumm -e -d yesterday /var/log/maillog | mail -s 'Logwatch for Postfix' root

Fedora32:システム監視設定

Nagiosのインストール

Nagiosに必要なgd-develをインストールします。

root@www:~# dnf -y install gd-devel

nagiosユーザーを作成します。

root@www:~# useradd -d /usr/local/nagios/ -M nagios

Nagiosをダウンロードします。

root@www:~# wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.4.6/nagios-4.4.6.tar.gz

Nagiosを展開します。

root@www:~# tar zxvf nagios-4.4.6.tar.gz

Nagios展開先ディレクトリへ移動します。

root@www:~# cd nagios-4.4.6

patchをインストールします。

root@www:~# dnf -y install patch

Nagios日本語化パッチをダウンロードします。

root@www:nagios-4.4.6# wget http://ftp.momo-i.org/pub/security/nagios/patches/nagios-jp-4.4.6.patch.gz

Nagios日本語化パッチを施行します。

root@www:nagios-4.4.6# gzip -dc nagios-jp-4.4.6.patch.gz |patch -p1

Nagiosをインストールします。

root@www:nagios-4.4.6# ./configure && make all && make fullinstall && make install-config

ディレクトリを抜けます。

root@www:nagios-4.4.6# cd

Nagios展開先ディレクトリを削除します。

root@www:~# rm -rf nagios-4.4.6

ダウンロードしたファイルを削除します。

root@www:~# rm -f nagios-4.4.6.tar.gz

Nagiosプラグインインストール

Nagiosプラグインをダウンロードします。

root@www:~# wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.3.3/nagios-plugins-2.3.3.tar.gz

Nagiosプラグインを展開します。

root@www:~# tar zxvf nagios-plugins-2.3.3.tar.gz

Nagiosプラグイン展開先ディレクトリへ移動します。

root@www:~# cd nagios-plugins-2.3.3

Nagiosプラグインをインストールします。

root@www:nagios-plugins-2.3.3# ./configure && make && make install

ディレクトリを抜けます。

root@www:nagios-plugins-2.3.3# cd

Nagiosプラグイン展開先ディレクトリを削除します。

root@www:~# rm -rf nagios-plugins-2.3.3

ダウンロードしたファイルを削除します。

root@www:~# rm -f nagios-plugins-2.3.3.tar.gz

Nagios設定

nagios.cfgを設定します。

root@www:~# vi /usr/local/nagios/etc/nagios.cfg

51行目:行頭の「#」を削除してコメント解除し、サーバー監視設定有効化を設定します。

cfg_dir=/usr/local/nagios/etc/servers

1096:行目:日付書式をYYYY-MM-DD HH:MM:SSにするを設定します。

date_format=iso8601

サーバー監視設定ファイル格納ディレクトリを作成します。

root@www:~# mkdir /usr/local/nagios/etc/servers

contacts.cfgを設定します。

root@www:~# vi /usr/local/nagios/etc/objects/contacts.cfg

32行目:管理者メールアドレスを指定を設定します。

define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user

        email                           root@localhost
        }

localhost.cfgを設定します。

root@www:~# vi /usr/local/nagios/etc/objects/localhost.cfg

144行目:SSH状態変化時に通知するを設定します。

define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           1
        }

158行目:SSH状態変化時に通知するを設定します。

define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           1
        }

commands.cfgを設定します。

root@www:~# vi /usr/local/nagios/etc/objects/commands.cfg

29行目:nkfコマンドのメール本文文字化け対策を設定します。

# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/nkf -j | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

37行目:nkfコマンドのメール本文文字化け対策を設定します。

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/nkf -j | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }

Apache httpd設定

Nagios用Apache httpd設定ファイルを設定します。

root@www:~# vi /etc/httpd/conf.d/nagios.conf

16行目:追記します。

      <RequireAny>

17行目:行頭に「#」を追記してコメント化し、内部からのみアクセス可能にする設定をします。

#         Require all granted

19行目:内部ネットワーク(192.168.1.1/24)からのみアクセス可能にする設定をします。

         Require ip 192.168.1.1/24

20行目:追記します。

      </RequireAny>

49行目:追記します。

      <RequireAny>

50行目:行頭に「#」を追記してコメント化し、内部からのみアクセス可能にする設定をします。

#         Require all granted

52行目:内部ネットワーク(192.168.1.1/24)からのみアクセス可能にする設定をします。

         Require ip 192.168.1.1/24

53行目:追記します。

      </RequireAny>

Webサーバー設定反映を設定します。

root@www:~# systemctl restart httpd

Nagios管理ユーザー(nagiosadmin)を作成します。

root@www:~# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

パスワードを設定します。

New password:
Re-type new password:
Adding password for user nagiosadmin

Nagios起動

起動します。

root@www:~# systemctl restart nagios

Webブラウザを起動し、「http://ubuntuserver.jp/nagios/」にアクセスし、管理ユーザー:nagiosadmin、登録済パスワードでログインして動作確認をします。

nagios