GNU/Linux >> Linux の 問題 >  >> Linux

SSL を使用して CentOS 6.2 にソースから Apache 2.4.2 をインストールする方法

少し前に説明した SSL を使用して Apache をインストールする方法の記事に従おうとすると、Apache 2.4.4 と付属の APR ユーティリティ (Apache Portable Runtime Library) の間のバージョンの互換性のために、「make」中に問題に直面することになります。 CentOS 6 で。

この記事では、この問題を解決して最新の Apache を CentOS または RedHat で動作させる方法を説明しました。

gcc と openssl-devel がインストールされていることを確認してください。

# yum install gcc
# yum install openssl-devel

ソースから Apache をインストールするには、「Apache Portable Runtime Library」APR も必要です。

すでに「apr」および「apr-util」パッケージがインストールされています。 apr-devel および apr-util-devel パッケージをインストールします。

# yum install apr-devel
# yum install apr-util-devel

注:私たちの場合 (バージョンの互換性の問題のため)、これらをダウンロードして後で手動でインストールします。しかし、ここでは流れに沿って、この方法で実行しようとするとどうなるか見てみましょう.

Apache をダウンロード

httpd.apache.org から Apache をダウンロードします。現在の安定版リリースは 2.4.2 です。

Apache の最新の安定バージョンをダウンロードするための直接 URL を取得したら、以下に示すように wget を使用してサーバーに直接ダウンロードします。

cd /usr/src
wget http://mirror.nyi.net/apache//httpd/httpd-2.4.2.tar.gz
tar xvfz httpd-2.4.2.tar.gz

SSL/TLS を使用して Apache をインストールする

以下に示すように、使用可能なすべての Apache インストールおよび構成オプションを表示します。

cd httpd-2.4.2
./configure --help

Apache モジュールをインストールするには、通常、–enable-{module-name} と言います。たとえば、Apache で SSL をインストールするには、–enable-ssl です。 LDAP モジュールをインストールするには、–enable-ldap です。

Apache に付属するデフォルト モジュールをアンインストールするには、通常、–disable-{module-name} とします。たとえば、Apache で基本認証を無効にするには、–disable-auth-basic です

この例では、すべてのデフォルト モジュールを使用して Apache をインストールし、–enable-ssl (SSL サポートのために mod_ssl をインストールするため) と –enable-so を追加して、動的共有を介して実行時に Apache にモジュールをロードするのに役立ちます。再コンパイルを必要としない、オブジェクト (DSO) メカニズム。

./configure --enable-ssl --enable-so
make
make install

注:デフォルトでは、上記は /usr/local/apache2 の下に Apache をインストールします。この場所を変更したい場合は、./configure で –prefix オプションを使用してください。

APR ユーティリティのエラー メッセージの修正

しばらく前に説明したように、古いバージョンの Apache をインストールしているときにこの問題に直面したことはないかもしれません。

「make」を実行すると、「rotatelogs.c:(.text+0x5ed):undefined reference to `apr_file_link'」が発生する場合があります 以下に示すように、CentOS 6.2 でこれを実行している場合のエラー メッセージ。

# make
rotatelogs.c:298: warning: implicit declaration of function âapr_file_linkâ
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -std=gnu99 -pthread
-o rotatelogs  rotatelogs.lo /usr/lib64/libaprutil-1.la -ldb-4.7 -lexpat -ldb-4.7 /usr/lib64/libapr-1.la -lpthread
rotatelogs.o: In function `post_rotate':
rotatelogs.c:(.text+0x5ed): undefined reference to `apr_file_link'
collect2: ld returned 1 exit status
make[2]: *** [rotatelogs] Error 1
make[2]: Leaving directory `/usr/src/httpd-2.4.2/support'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/src/httpd-2.4.2/support'
make: *** [all-recursive] Error 1

これは、CentOS 6 では、以下に示すように、yum インストールで利用できる最新の APR バージョンが 1.3.9 であるためです。

# rpm -qa apr*
apr-1.3.9-3.el6_1.2.x86_64
apr-util-1.3.9-3.el6_0.1.x86_64

ただし、Apache 2.4.2 には APR の最新バージョン (現在は 1.4.6) が必要です。

そこで、APR ダウンロード ページに移動し、apr と apr-util の両方をダウンロードします。

cd /usr/src
wget http://mirror.atlanticmetro.net/apache//apr/apr-1.4.6.tar.gz
wget http://mirror.atlanticmetro.net/apache//apr/apr-util-1.4.1.tar.gz
tar xvfz apr-1.4.6.tar.gz
tar xvfz apr-util-1.4.1.tar.gz

ここで、ダウンロードした apache ソフトウェアを解凍したときに作成された httpd-2.4.2 ディレクトリの下にある「srclib」ディレクトリの下に、この新しいバージョンの apr および apr-util ディレクトリ (ディレクトリ内のバージョン名なし) を配置する必要があります。 /P>

この例では、httpd-2.4.2.tar.gz をダウンロードし、/usr/src で解凍しました。したがって、このディレクトリの下に最新の apr と apr-util を配置する必要があります。

mv apr-1.4.6 /usr/src/httpd-2.4.2/srclib/apr
mv apr-util-1.4.1 /usr/src/httpd-2.4.2/srclib/apr-util

これが完了したら、構成して再度作成する必要があります。 ./configure –help を実行すると、APR に関連する次のオプションが表示されます

# cd /usr/src/httpd-2.4.2
# ./configure --help
  --with-included-apr     Use bundled copies of APR/APR-Util
  --with-apr=PATH         prefix for installed APR or the full path to apr-config
  --with-apr-util=PATH    prefix for installed APU or the full path to apu-config

システムに apr-1.4.6 と apr-util-1.4.1 をインストールする場合は、「–with-apr」と「–with-apr-util」を使用して、これらをインストールしたパスを指定する必要があります。

この例では、それを行いませんでした。つまり、ダウンロードした apr と apr-util をインストールしませんでした。代わりに、httpd-2.4.2/srclib/apr-util の下に配置しました。したがって、./configure で「–with-included-apr」を使用する必要があります。これにより、これらの apr と apr-util は、Apache のコンパイルとインストールにのみ使用されます。

それでは、以下に示すように、(-with-included-apr を使用して) ./configure をやり直し、make と make install を行いましょう。

./configure --enable-ssl --enable-so --with-included-apr
make
make install

これで、make は「rotatelogs.c:(.text+0x5ed):undefined reference to `apr_file_link」エラー メッセージを表示しなくなりました。

httpd.conf で SSL を有効にする

Apache 構成ファイル httpd.conf は /usr/local/apache2/conf の下にあります。

/usr/local/apache2/conf/httpd.conf ファイルの httpd-ssl.conf Include 行と LoadModule ssl_module 行のコメントを外します。

# vi /usr/local/apache2/conf/httpd.conf
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf

httpd-ssl.conf を表示して、デフォルトの SSL 構成をすべて確認します。ほとんどの場合、このファイルを変更する必要はありません。

# vi /usr/local/apache2/conf/extra/httpd-ssl.conf

Apache を起動する前に、SSL 証明書とキーが必要です。先に進む前に、httpd-ssl.conf に記載されている server.crt および server.key ファイルを作成する必要があります。

# cd /usr/local/apache2/conf/extra
# egrep 'server.crt|server.key' httpd-ssl.conf
SSLCertificateFile "/usr/local/apache2/conf/server.crt"
SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"

server.crt と server.key ファイルを作成

まず、openssl を使用して server.key を生成します。

# cd /usr/src
# openssl genrsa -des3 -out server.key 1024

上記のコマンドはパスワードを要求します。このパスワードを忘れないようにしてください。これは後で Apache を起動するときに必要になります。

次に、上記の server.key ファイルを使用して証明書要求ファイル (server.csr) を生成します。

# openssl req -new -key server.key -out server.csr

最後に、上記の server.key と server.csr ファイルを使用して、自己署名 ssl 証明書 (server.crt) を生成します。

# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

上記の手順を完了すると、/usr/src の下に次の 3 つのファイルが表示されます

# ls server*
server.crt  server.csr  server.key

server.key および server.crt ファイルを適切な Apache 構成ディレクトリの場所にコピーします。

cp server.key /usr/local/apache2/conf/
cp server.crt /usr/local/apache2/conf/

Apache を起動

以下のエラー メッセージが表示される場合は、httpd.conf で以下に示す行のコメントを外してください。

# /usr/local/apache2/bin/apachectl start
AH00526: Syntax error on line 51 of /usr/local/apache2/conf/extra/httpd-ssl.conf:
Invalid command 'SSLCipherSuite', perhaps misspelled or defined by a module not included in the server configuration

# vi /usr/local/apache2/conf/httpd.conf
LoadModule ssl_module modules/mod_ssl.so

以下のエラー メッセージが表示される場合は、httpd.conf で以下に示す行のコメントを外してください。

# /usr/local/apache2/bin/apachectl start
AH00526: Syntax error on line 76 of /usr/local/apache2/conf/extra/httpd-ssl.conf:
SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).

# vi /usr/local/apache2/conf/httpd.conf
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so

最後に、Apache を起動する前に、秘密鍵のパスワードを入力するよう求められます。

# /usr/local/apache2/bin/apachectl start
Apache/2.4.2 mod_ssl (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.

Server www.example.com:443 (RSA)
Enter pass phrase:

OK: Pass Phrase Dialog successful.

Apache httpd プロセスがバックグラウンドで実行されていることを確認します

# ps -ef | grep http
root   29529     1  0 13:08 ?     00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 29530 29529  0 13:08 ?     00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 29531 29529  0 13:08 ?     00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 29532 29529  0 13:08 ?     00:00:00 /usr/local/apache2/bin/httpd -k start
root   29616 18260  0 13:09 pts/0 00:00:00 grep http

Apache を停止するには、apachectl stop を使用します。

# /usr/local/apache2/bin/apachectl stop

httpd -l を使用して、Apache httpd デーモン内でコンパイルされたすべてのモジュールを表示します。

# /usr/local/apache2/bin/httpd -l
Compiled in modules:
  core.c
  mod_so.c
  http_core.c
  event.c

デフォルトでは、Apache SSL は 443 ポートで実行されます。 Web ブラウザーを開き、https://{your-ip-address} を使用して Apache にアクセスできることを確認します


Linux
  1. Debian 11 に Let’s Encrypt SSL を Apache でインストールする方法

  2. Linux にソースから Apache 2 をインストールする

  3. Linux に SSL を使用して Apache 2 をインストールする方法 (mod_ssl、openssl を使用)

  1. CentOS7にApacheでLet'sEncryptをインストールする方法

  2. Apacheを使用してCentos7.xにmodセキュリティをインストールするにはどうすればよいですか?

  3. CentOS 6 に Apache CouchDB をインストールする方法 (ソースおよび EPEL から)

  1. CentOS7用のApacheにSSL証明書をインストールする方法

  2. httpdApacheWebサーバーを使用してRHEL8/CentOS8にmod_sslをインストールする方法

  3. CentOS7にApacheを使用してWordPressをインストールする方法