Pound

更新日2015-08-29 (土) 09:25:13

Webサーバのロードバランサ(バックProxyとしても)として利用できる。

ここからDownlaodしてくる。

構成図

---------------                ----------------
|             |                |              |
| Pound       |                | Web          |
| 10.3.1.50   |================| 10.3.1.51    |
|             |        |       |              |
|             |        |       |              |
---------------        |       ----------------
                       |                       
                       |       ----------------
                       |       |              |
                       |       | Web          |
                       ========| 10.3.1.52    |
                               |              |
                               ----------------

インストール

$ tar zxvf Pound-2.1.6.tgz
$ cd Pound-2.1.6
$ ./configure --with-ssl=/usr (--with-ssl=ssl_dir OpenSSL home directory)
(openssl-develも必要)
$ make
$ su
# make install

設定

pound-1xと-2xではpound.cfgの書式が異なる。今回は-2xで試してみる。

/usr/local/etc/pound.cfgを編集(作成)

単純なリバースプロキシの設定(2台のマシンにプライオリティの差をつける)

User        "nobody"  <--起動ユーザの指定
Group       "nobody"  <--起動グループの指定
ListenHTTP
  Address 10.3.1.50   <---PoundのIPアドレス
  Port    80          <---Poundの受信ポート

  Service
    BackEnd
      Address 10.3.1.51
      Port 80
      Priority 9    <---デフォルトは1 1-9で指定で9がプライオリティが高い
    End

    BackEnd
      Address 10.3.1.52
      Port 80
      Priority 1
    End
  End
End

設定ファイルの確認

# /usr/local/sbin/pound -cv
Config file /usr/local/etc/pound.cfg is OK

起動

#/usr/local/sbin/pound
# ps ax

15268 ?        S      0:00 /usr/local/sbin/pound
15269 ?        S      0:00 /usr/local/sbin/pound
15270 ?        S      0:00 /usr/local/sbin/pound
15271 ?        S      0:00 /usr/local/sbin/pound
15272 ?        S      0:00 /usr/local/sbin/pound

/var/log/messagesにlogが出るので起動失敗では確認する

HTTPS

poundでSSL接続させるためにサーバキー、公開キーを作成する。Vineの場合すでにApacheで利用されているのでそれを利用する。

サーバキー(秘密キー)

# cp /etc/httpd/conf/ssl.key/server.key server-key.pem

公開キー(証明書)

# cp /etc/httpd/conf/ssl.crt/server.crt  pound.pem

二つのキーをマージしてpoundでは利用するのでマージする。

# cat server-key.pem >> pound.pem

自分でサーバキー(秘密キー)、公開キー(証明書)を作成するとき

サーバキー(秘密キー)

# openssl genrsa -des3 -out server-key.pem 1024
Generating RSA private key, 1024 bit long modulus
.........++++++
.......++++++
e is 65537 (0x10001)
Enter pass phrase for server-key.pem:*****
Verifying - Enter pass phrase for server-key.pem:*****

サーバキーのパスワードを聞かれることをなくす

# openssl rsa -in server-key.pem -days 365 -out server-key.pem
Enter pass phrase for server-key.pem:*****
writing RSA key

公開キー(証明書)

# openssl req -new -key server-key.pem -x509 -days 365 -out pound.pem
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) [AU]:JP
State or Province Name (full name) [Some-State]:Mie Pref
Locality Name (eg, city) []:Matsusaka
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MCU
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:localhost
Email Address []:student@localhost

二つのキーをマージしてpoundでは利用するのでマージする。

# cat server-key.pem >> pound.pem

設定

以下の内容をpound.cfgに追加すると10.3.1.50にssl接続しに来たら10.3.1.51の ポート80に投げる。

ListenHTTPS
    Address 10.3.1.50
      Port    443
      Cert    "/usr/local/etc/pound.pem"
      Service
          BackEnd
              Address 10.3.1.51
              Port    80
          End
      End
End

設定(指定ディレクトリを指定ホストに転送)

http://10.3.1.50/51/http://10.3.1.51/51/をアクセスし、http://10.3.1.50/52/http://10.3.1.52/52/をアクセスする。

以下の内容を「単純なリバースプロキシの設定」の前に追加する。 Servceはパターンに合ったものから処理し、先に記入されたものが優先される

 Service
   URL "/51/.*"
   BackEnd
     Address 10.3.1.51
     Port 80
     Priority 1
   End
 End

 Service
   URL "/52/.*"
   BackEnd
     Address 10.3.1.52
     Port 80
     Priority 1
   End
 End

アクセスURLにより異なるマシンへの振り分け

アクセスURLを変えてアクセスすると異なるマシンへのアクセスを実現する方法が不明 出来きるのか?

Poundはpound.cfgに記載順に実行されるので、先に指定ディレクトリに転送する方法で記載し、その後デフォルトの転送さきとして以下の指定をする。

(指定ディレクトリの内容)

 Service
   Redirect "http://10.3.1.50:8080"
 End

アクセスポートにより振り分け

アクセスするポートによりサーバとポートを指定する
192.yyy.yyy.yyy:8088にアクセスすると192.xxx.xxx.xxx:80にフォワード
ポート8089アクセスすると10.zzz.zzz.zzzz:8080にフォワード
これで一つのマシンがグローバルでアクセスできたらポート指定で 内部サーバにもアクセス可能。

pound.cfg

User        "nobody"
Group       "nobody"

# 8088ポートの転送先アドレスポート指定
ListenHTTP
  Address 192.yyy.yyy.yyy
  Port    8088

  Service
    BackEnd
      Address 192.xxx.xxx.xxx
      Port 80
      Priority 9
    End
  End
End
# 8089ポートの転送先アドレスポート指定
ListenHTTP
  Address 192.yyy.yyy.yyy
  Port    8089

  Service
    BackEnd
      Address 10.zzz.zzz.zzz
      Port 8080
      Priority 9
    End
  End
End

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS