2012年1月9日月曜日

CentOS 6.2 (64bit) apache 2 mod_ssl インストールの手順

CentOS 6.2 (64bit) apache 2 mod_ssl インストールの手順のメモです。

こちらは、あくまでも私的なメモです (再インストールの際などに役立てるため)

■重要■

  • このページは「http://kajuhome.com/apache_ssl.shtml」から手順を参考に (というよりもそっくりそのまま真似て) インストールを行なっています。
  • まるっきり Web ページをそのままコピーペーストでは、著作権侵害であり、上のページの製作者の方へ大変失礼になりますし、私自身のメモとしては役に立ちません。
  • このページでは、実際に自分が行った作業をそのまま記録して、自分自身で今後の参考にする目的で載せていますが、手順自体は上のページとほとんど同じです。
  • Apache2 mod_ssl インストールをされる方は、このページよりも、ぜひ上のページをご参考にするようお願いします。手順ごとに説明がついていてわかりやすいです。
  • 「CentOS 6 apache2 mod_ssl」のインストール手順書を Web で検索しましたが、(私が探した中では) 上のページの手順書が最もわかりやすいと思っています。ページ製作者の方に感謝を申し上げます。
  • 上のページとこのページが違うのは、このページでは「私自身が行った作業の結果を載せている」点と、「★特定のディレクトリでのみ SSL を利用する (他のディレクトリでは通常の http で通信を行う)」という項目を追加したことです。

yum にて、mod_ssl をインストール

yum -y install mod_ssl

[root@pc101 ~]# yum -y install mod_ssl
Loaded plugins: downloadonly, fastestmirror, priorities, refresh-packagekit
Determining fastest mirrors
epel/metalink                                                    | 3.6 kB     00:00
 * base: www.ftp.ne.jp
 * epel: ftp.iij.ad.jp
 * extras: www.ftp.ne.jp
 * rpmforge: fr2.rpmfind.net
 * updates: www.ftp.ne.jp
base                                                             | 3.7 kB     00:00
extras                                                           | 3.5 kB     00:00
google-chrome                                                    |  951 B     00:00
rpmforge                                                         | 1.1 kB     00:00
updates                                                          | 3.5 kB     00:00
2683 packages excluded due to repository priority protections
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mod_ssl.x86_64 1:2.2.15-15.el6.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
 Package          Arch            Version                           Repository     Size
========================================================================================
Installing:
 mod_ssl          x86_64          1:2.2.15-15.el6.centos            base           87 k

Transaction Summary
========================================================================================
Install       1 Package(s)

Total download size: 87 k
Installed size: 183 k
Downloading Packages:
mod_ssl-2.2.15-15.el6.centos.x86_64.rpm                          |  87 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 1:mod_ssl-2.2.15-15.el6.centos.x86_64                                1/1

Installed:
  mod_ssl.x86_64 1:2.2.15-15.el6.centos

Complete!
[root@pc101 ~]#

CA用秘密鍵(ca.key)の作成

[root@pc161 ~]# openssl genrsa -des3 -out /etc/httpd/conf/ca.key -rand rand.dat 1024
0 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
........................................................++++++
.......++++++
e is 65537 (0x10001)
Enter pass phrase for /etc/httpd/conf/ca.key:
Verifying - Enter pass phrase for /etc/httpd/conf/ca.key:
[root@pc161 ~]#

CA用証明書(ca.crt)の作成

[root@pc101 ~]# openssl genrsa -des3 -out /etc/httpd/conf/ca.key -rand rand.dat 1024
0 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
........................................................++++++
.......++++++
e is 65537 (0x10001)
Enter pass phrase for /etc/httpd/conf/ca.key:
Verifying - Enter pass phrase for /etc/httpd/conf/ca.key:
[root@pc101 ~]# openssl req -new -x509 -days 365 -key /etc/httpd/conf/ca.key -out /etc/httpd/conf/ca.crt
Enter pass phrase for /etc/httpd/conf/ca.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:Chiyoda
Organization Name (eg, company) [Default Company Ltd]:Private_CA
Organizational Unit Name (eg, section) []:Admin
Common Name (eg, your name or your server's hostname) []:www123456.dyndns.info
Email Address []:xxx@yyyy.zz.jp
[root@pc101 ~]# 

サーバ用秘密鍵(server.key)の作成

[root@pc101 ~]# openssl genrsa -des3 -out /etc/httpd/conf/server.key -rand rand.dat 1024 0 semi-random bytes loaded Generating RSA private key, 1024 bit long modulus ..++++++ ..........................................................++++++ e is 65537 (0x10001) Enter pass phrase for /etc/httpd/conf/server.key: Verifying - Enter pass phrase for /etc/httpd/conf/server.key: [root@pc101 ~]#

署名要求書(server.csr)の作成

[root@pc101 ~]# openssl genrsa -des3 -out /etc/httpd/conf/server.key -rand rand.dat 1024
0 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
..++++++
..........................................................++++++
e is 65537 (0x10001)
Enter pass phrase for /etc/httpd/conf/server.key:
Verifying - Enter pass phrase for /etc/httpd/conf/server.key:
[root@pc101 ~]# openssl req -new -key /etc/httpd/conf/server.key -out /etc/httpd/conf/server.csr
Enter pass phrase for /etc/httpd/conf/server.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:Shinjuku
Organization Name (eg, company) [Default Company Ltd]:abcdefg_company
Organizational Unit Name (eg, section) []:it_dept
Common Name (eg, your name or your server's hostname) []:www123456.dyndns.info
Email Address []:xxx@yyyy.zz.jp

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@pc101 ~]#

サーバ用秘密鍵(server.key)からのパスフレーズ削除

[root@pc101 ~]# openssl rsa -in /etc/httpd/conf/server.key.bak -out /etc/httpd/conf/server.key
Enter pass phrase for /etc/httpd/conf/server.key.bak:
writing RSA key
[root@pc101 ~]#

★特定のディレクトリでのみ SSL を利用する (他のディレクトリでは通常の http で通信を行う)

[root@pc161 ssl]# mkdir ssl
[root@pc101 ssl]# vi /etc/httpd/conf/httpd.conf

以下のように変更する

変更前

# ===== changed 2011/01/09 =====
<Directory "/var/www/html">

(中略)

</Directory>

# ===== changed 2011/01/09 =====

変更後

<Directory "/var/www/html">

(中略)

</Directory>



# ===== changed 2011/01/09 =====
<Location "/ssl">
  SSLRequireSSL
</Location>
# ===== changed 2011/01/09 =====

参考文献

2012年1月3日火曜日

PostgrSQL のユーザー作成と DB 作成

PostgreSQL インストール (CentOS 6.2、yum)」が完了したら、次は、PostgrSQL のユーザー作成と DB 作成を行います。

  1. ユーザー作成

    先に、CentOS (Linux) にて、ユーザーを追加しておきます。

    [root@pc101 ~]# adduser testuser
    [root@pc101 ~]# passwd testuser
    ユーザー testuser のパスワードを変更。
    新しいパスワード:
    新しいパスワードを再入力してください:
    passwd: 全ての認証トークンが正しく更新できました。
    

    つぎに、postgres にログインします。

    [root@pc101 ~]# su - postgres
    -bash-4.1$ psql
    psql (8.4.9)
    "help" でヘルプを表示します.
    
    postgres=# 
    

    次に、ユーザー作成を実行します。

    postgres=# CREATE USER "testuser" CREATEDB PASSWORD 'thisisthepassword' LOGIN;
    CREATE ROLE
    postgres=#
    
    postgres=# \q
    -bash-4.1$ 
    
    
    -bash-4.1$ exit
    logout
    [root@pc101 ~]#
    
  2. DB 作成
    [root@pc101 ~]# su - testuser
    [testuser@pc101 ~]$ createdb testdb01
    [testuser@pc101 ~]$
    
  3. DB が作成されていることを確認します。
    [root@pc101 ~]# su - postgres
    
    -bash-4.1$ psql -l
                                             データベース一覧
       名前    |  所有者  | エンコーディング |  照合順序   | Ctype(変換演算子) |      アクセ
    ス権
    -----------+----------+------------------+-------------+-------------------+------------
    -----------
     postgres  | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       |
     template0 | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres
                                                                               : postgres=CT
    c/postgres
     template1 | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres
                                                                               : postgres=CT
    c/postgres
     testdb01  | testuser | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       |
    (4 行)
    
    -bash-4.1$
    

    「testdb01」という名前のデータベースが作成されていることが確認できました。

PostgreSQL インストール (CentOS 6.2、yum)

CentOS 6.2 にて、PostgreSQL を yum でインストールする手順。



  1. yum でインストール
    以下を実行する
    yum -y install postgresql postgresql-libs postgresql-server

    以下、実行例です。
    [root@testpc101 ~]# yum -y install postgresql postgresql-libs postgresql-server
    Loaded plugins: downloadonly, fastestmirror, refresh-packagekit
    Loading mirror speeds from cached hostfile
     * base: ftp.iij.ad.jp
     * extras: ftp.iij.ad.jp
     * updates: ftp.iij.ad.jp
    base                                                             | 3.7 kB     00:00
    extras                                                           | 3.5 kB     00:00
    google-chrome                                                    |  951 B     00:00
    updates                                                          | 3.5 kB     00:00
    updates/primary_db                                               | 654 kB     00:00
    Setting up Install Process
    Package postgresql-8.4.9-1.el6_1.1.x86_64 already installed and latest version
    Package postgresql-libs-8.4.9-1.el6_1.1.x86_64 already installed and latest version
    Resolving Dependencies
    --> Running transaction check
    ---> Package postgresql-server.x86_64 0:8.4.9-1.el6_1.1 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ========================================================================================
     Package                   Arch           Version                    Repository    Size
    ========================================================================================
    Installing:
     postgresql-server         x86_64         8.4.9-1.el6_1.1            base         3.3 M
    
    Transaction Summary
    ========================================================================================
    Install       1 Package(s)
    
    Total download size: 3.3 M
    Installed size: 14 M
    Downloading Packages:
    postgresql-server-8.4.9-1.el6_1.1.x86_64.rpm                     | 3.3 MB     00:00
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing : postgresql-server-8.4.9-1.el6_1.1.x86_64                             1/1
    
    Installed:
      postgresql-server.x86_64 0:8.4.9-1.el6_1.1
    
    Complete!
    [root@testpc101 ~]#
    



  2. PostgreSQL 初期設定

    PostgreSQL インストール直後、SELinux が enabled になっている状態で、
    「service postgresql start」
    を実行すると、エラーメッセージが表示されます。


    [root@testpc101 ~]# service postgresql start
    
    /var/lib/pgsql/data is missing. Use "service postgresql initdb" to initialize the cluster first.
    
                                                               [失敗]
    [root@testpc101 ~]# 
    

  3. エラーメッセージを読んでみると、親切にもエラーの対処方法を教えてくれています。
    "Use "service postgresql initdb" to initialize the cluster first."



  4. その通りに入力して、Enter キーを押下します。
    [root@testpc101 ~]# service postgresql initdb



  5. Enter キーを押下した後、「データベースを初期化中」と表示されます。フリーズしているかのように見えますが、そのまま待ちます。
    [root@testpc101 ~]# service postgresql initdb
    データベースを初期化中:
    
    




  6. しばらく待つと [ OK ] のメッセージが表示されます。(私が実行した環境では 30 秒程度でした)

    [root@testpc101 ~]# service postgresql initdb
    データベースを初期化中:                                    [  OK  ]
    [root@testpc101 ~]#
    




  7. poqstgresql のサービスを開始します。
    [root@testpc101 ~]# service postgresql start
    postgresql サービスを開始中:                               [  OK  ]
    





  8. PostgreSQL が動作しているかを確認するため、PostgreSQL にログインします。
    [root@testpc101 ~]# su - postgres
    -bash-4.1$
    




  9. 同じく、動作確認のために、データベースの一覧を表示してみます。
    -bash-4.1$ psql -l
                                             データベース一覧
       名前    |  所有者  | エンコーディング |  照合順序   | Ctype(変換演算子) |      アクセ
    ス権
    -----------+----------+------------------+-------------+-------------------+------------
    -----------
     postgres  | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       |
     template0 | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres
                                                                               : postgres=CT
    c/postgres
     template1 | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres
                                                                               : postgres=CT
    c/postgres
    (3 行)
    -bash-4.1$ 
    



  10. PostgreSQL からログアウトします。
    -bash-4.1$ logout
    [root@testpc101 ~]#
    






  11. OS起動時に、PostgreSQL サービスも自動起動 (自動的に開始) するように設定します。
    [root@testpc101 ~]# chkconfig postgresql on
    [root@testpc101 ~]# chkconfig --list postgresql
    postgresql      0:off   1:off   2:on    3:on    4:on    5:on    6:off
    [root@testpc101 ~]#
    








参考