CloudStackでLVS(Linux Virtual Server) -Ldirectordを利用編

概要

前回、CloudStackのVMを使ってLVS(Linux Virtual Server)を構成してみました。

CloudStackでLVS(Linux Virtual Server) - mukkun0824’s blog

LPIC304の勉強がてらということで、今回はLdirectordを利用してみます。これもCentos7の記事があまりないので、導入時だけ少し苦労しますが、設定方法はCentos6と変わりません。

参考

https://enterprisezine.jp/iti/detail/228

http://etom.hatenablog.com/entry/2013/08/23/022656

https://thinkit.co.jp/story/2011/07/21/2201?nopaging=1

構成

構成は全く前回と同じですが、ipvsadmのコマンドを利用せず、Ldirectordの設定だけで行います。負荷状況があまりなければ、どっちを使うかは好みのレベルかもしれませんが、Ldirectordの方が設定は楽です。

                         (internet)
                             |
                             | グローバルIP
                   +---------+-----------+
                   |  Virtual Router     |
                   +---------+-----------+
                             | 192.168.0.1/24 GW
                             |
                             |
                             |
                         eth0|192.168.0.223/24
                      eth0:0 |192.168.0.100/24
                       +-----------+
                       |    LVS    |
                       | Ldirectord|
                       +-----+-----+
                             |
+------------+               |                 +------------+
|  Backend01 |192.168.0.62/24| 192.168.0.243/24|  Backend02 |
| Web Server +------------+--------------------+ Web Server |
|            |eth0                        eth0 |            |
+------------+                                 +------------+

lvsサーバー:インストール・設定

cloudStackでの操作

(1) 事前にセカンダリIP192.168.0.100を付けておく。

(2) グローバルIPのNATの設定で、セカンダリIP 192.168.0.100へNAT設定しておく(送信元NATのグローバルIPではなく、別で用意する)

VIPつける

ip addr add 192.168.0.100/24 dev eth0

firewalld 止める

systemctl status firewalld.service
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service

Ldirectordの設定

rpmパッケージをサーバーに入れます なぜかWebからしかダウンロードできないので、webからダウンロードします。 https://ja.osdn.net/projects/linux-ha/downloads/71663/pacemaker-repo-1.1.21-1.1.el7.x86_64.rpm/

rpmファイルをインストール

[root@mukkun-lvs ~]# rpm -ivh pacemaker-repo-1.1.21-1.1.el7.x86_64.rpm
準備しています...              ################################# [100%]
更新中 / インストール中...
   1:pacemaker-repo-1.1.21-1.1.el7    ################################# [100%]

heartbeat-ldirectordをインストール(ipvsadmも入っていなければ入れてください。)

yum -y install ipvsadm #入ってなければ
yum -y install heartbeat-ldirectord

バージョン確認

[root@mukkun-lvs ~]# ldirectord --version
Linux Director v1.186-ha
1999-2006 Jacob Rief, Horms and others
<http://www.vergenet.net/linux/ldirectord/>

ldirectord comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the GNU General Public Licence for details.

コンフィグファイルコピー

cp /usr/share/doc/ldirectord-4.3.0/ldirectord.cf /etc/ha.d/ldirectord.cf

コンフィグファイル記述

[root@mukkun-lvs ~]# cat /etc/ha.d/ldirectord.cf | grep -v ^#

checktimeout=3
checkinterval=1
autoreload=yes
logfile="/var/log/ldirectord.log"

virtual=192.168.0.100:80
        real=192.168.0.62:80 gate
        real=192.168.0.243:80 gate
        service=http
        scheduler=rr
        protocol=tcp
        checktype=negotiate
        checkport=80
        request="index.html"

サービス起動

[root@mukkun-lvs ~]# systemctl start ldirectord.service

設定確認

IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.0.100:80 rr
  -> 192.168.0.62:80              Route   1      0          0
  -> 192.168.0.243:80             Route   1      0          1

BackEndServer:設定

BackEnd(リアルサーバー)側の設定は前回と変更なしです。

これで前回と同じようにグローバルIPでWebアクセスすると2台に負荷分散されます。