CentOSにPoundをインストールしてみる

CentOSにPoundをインストールしてみる。


VagrantでWebサーバを2台用意し、
同じくVagrantでPoundのサーバを構築して、
分散してみる。

VagrantにCentOS6.5が入ってなければ追加しておく。

$ vagrant box add centos65 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box

Webサーバ

まずはWebサーバを用意する。

VagrantCentOSの環境を構築する。

$ mkdir web1
$ cd web1
$ vagrant init centos65
$ vi Vagrantfile
  config.vm.network "private_network", ip: "192.168.33.11"
$ vagrant up
$ vagrant ssh

Apacheをインストールする。

web1$ sudo yum -y install httpd
web1$ sudo service httpd start
web1$ sudo chkconfig httpd on

index.htmlを作成する。

web1$ sudo vi /var/www/html/index.html
<html><body>Web1</body></html>

ブラウザで
http://192.168.33.11/
アクセスすると、「Web1」が表示される。

web2のサーバも同様に構築する。
web2のIPアドレスは「192.168.33.12」にして、HTMLの内容は「Web2」にする。

Pound

Poundのサーバを用意する。

VagrantCentOSの環境を構築する。

$ mkdir lb
$ cd lb
$ vagrant init centos65
$ vi Vagrantfile
  config.vm.network "private_network", ip: "192.168.33.10"
$ vagrant up
$ vagrant ssh

Poundをインストールする。
※poundは標準のリポジトリにないのでepelが必要だが、このboxには最初から入っている。

lb$ sudo yum -y install Pound

Poundの設定をする。
HTTPSは今回使わないので、コメントアウトしておき、
Webサーバの1と2の設定をする。

lb$ sudo vi /etc/pound.cfg
・・・
ListenHTTP
    Address 0.0.0.0
    Port 80
End

#ListenHTTPS
#    Address 0.0.0.0
#    Port    443
#    Cert    "/etc/pki/tls/certs/pound.pem"
#End

Service
    BackEnd
        Address 192.168.33.11
        Port    80
    End

    BackEnd
        Address 192.168.33.12
        Port    80
    End
End

poundを起動し、自動起動の設定もしておく。

lb$ sudo service pound start
lb$ sudo chkconfig pound on

確認

以上で、
http://192.168.33.10/
にアクセスすると、
アクセスするたびに「Web1」と「Web2」が切り替わる。


(おまけ)ポート指定で特定のサーバーにアクセスさせたい場合

pound.cfgを下記にように書くと、

ListenHTTP
    Address 0.0.0.0
    Port 80

    Service
        BackEnd
            Address 192.168.33.11
            Port    80
        End

        BackEnd
            Address 192.168.33.12
            Port    80
        End
    End
End

ListenHTTP
    Address 0.0.0.0
    Port 8081

    Service
        BackEnd
            Address 192.168.33.11
            Port    80
        End
    End
End

ListenHTTP
    Address 0.0.0.0
    Port 8082

    Service
        BackEnd
            Address 192.168.33.12
            Port    80
        End
    End
End
http://192.168.33.10/			→Web1またはWeb2
http://192.168.33.10:8081/	→Web1
http://192.168.33.10:8082/	→Web2

にアクセスするようになった。