<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>other | yukin.net</title>
	<atom:link href="https://yukin.net/category/other/feed/" rel="self" type="application/rss+xml" />
	<link>https://yukin.net</link>
	<description>stay curious</description>
	<lastBuildDate>Fri, 05 Jun 2026 04:06:20 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://yukin.net/wp-content/uploads/2023/10/cropped-yukin.fabicon-e1697637677176-32x32.png</url>
	<title>other | yukin.net</title>
	<link>https://yukin.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>RHEL9におけるkeepalived設定メモ</title>
		<link>https://yukin.net/other/rhel9-keepalived/</link>
		
		<dc:creator><![CDATA[yukin]]></dc:creator>
		<pubDate>Fri, 05 Jun 2026 03:00:45 +0000</pubDate>
				<category><![CDATA[other]]></category>
		<guid isPermaLink="false">https://yukin.net/?p=2002</guid>

					<description><![CDATA[Redhut Enterprise Linux 9を使ってsyslogサーバーを構築しているときに、keepalivedを使って仮想IPの設定をしたいのにうまくいかなかったときのメモ。 目的 syslog形式でログを吐く [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Redhut Enterprise Linux 9を使ってsyslogサーバーを構築しているときに、keepalivedを使って仮想IPの設定をしたいのにうまくいかなかったときのメモ。</p>



<h2 class="wp-block-heading">目的</h2>



<p class="wp-block-paragraph">syslog形式でログを吐く機器があって、別途ログをためるサーバーを構築したかった。</p>



<p class="wp-block-paragraph">linuxも再起動が必要なカーネルアップデートなども必要になることがあるので、ログの取りこぼしを最大限防ぐには冗長設定が必要だった。</p>



<h2 class="wp-block-heading">先に結論</h2>



<p class="wp-block-paragraph">keepalivedというものをつかえば一つのIPアドレスを複数のVMで共有できるらしいぞと聞いて設定したがうまくいかなかった。</p>



<p class="wp-block-paragraph">selinuxを疑ったが、結局はfirewallだった。</p>



<h2 class="wp-block-heading">前提</h2>



<p class="wp-block-paragraph">OS</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; quick-code: false; notranslate">
$ cat /etc/system-release
Red Hat Enterprise Linux release 9.8 (Plow)

$ uname -r
5.14.0-687.12.1.el9_8.x86_64
</pre></div>


<p class="wp-block-paragraph">selinux</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; quick-code: false; notranslate">
$ getenforce
Enforcing
</pre></div>


<p class="wp-block-paragraph">firewall</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; quick-code: false; notranslate">
$ firewall-cmd --state
running
</pre></div>


<p class="wp-block-paragraph">keepalived</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; quick-code: false; notranslate">
$ sudo dnf install keepalived

$ keepalived --version
Keepalived v2.2.8 (04/04,2023), git commit v2.2.7-154-g292b299e+
</pre></div>


<p class="wp-block-paragraph">ip</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
MASTER:    172.16.30.45
BACKUP:    172.16.30.46
VirtualIP: 172.16.30.47
</pre></div>


<h2 class="wp-block-heading">keepalivedの設定</h2>



<p class="wp-block-paragraph">MasterとBackupの両サーバーにおいて、/etc/keepalived/keepalived.confに以下のような設定を入れる。MasterとBackupでstateとpriorityだけ異なる形になる。</p>



<p class="wp-block-paragraph">priorityは数字が大きいほうがMaster。<br>auth_passは8文字以内にしないと警告が出る。</p>



<h4 class="wp-block-heading">Master</h4>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; highlight: [15,18]; title: ; notranslate">
! Configuration File for keepalived

global_defs {
   notification_email {
     notify@example.com
  }
   notification_email_from  notify@example.com
   smtp_server smtp.example.com
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass passwrd
    }
    virtual_ipaddress {
        172.16.30.47
    }
}
</pre></div>


<h4 class="wp-block-heading">BACKUP</h4>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; highlight: [15,18]; title: ; notranslate">
! Configuration File for keepalived

global_defs {
   notification_email {
     notify@example.com
  }
   notification_email_from  notify@example.com
   smtp_server smtp.example.com
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass passwrd
    }
    virtual_ipaddress {
        172.16.30.47
    }
}
</pre></div>


<h3 class="wp-block-heading">keepalivedの起動</h3>



<p class="wp-block-paragraph">systemctlで常時起動する。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
$ sudo systemctl start keepalived
$ sudo systemctl enable keepalived
$ sudo systemctl status keepalived
</pre></div>


<h2 class="wp-block-heading">selinuxの設定</h2>



<p class="wp-block-paragraph">selinuxをpermissiveに変更するという風に書いてある記事も多いので、(結果的には不要だったが)メモ的にenforcingのままkeepalivedを許可する設定を残しておく。</p>



<h4 class="wp-block-heading">ポリシーの確認</h4>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
$ sudo semanage boolean -l | grep keepalived
keepalived_connect_any         (オン   ,   オン)  keepalived が connect any できるようにします
</pre></div>


<h4 class="wp-block-heading">ポリシーの有効化</h4>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
$ sudo setsebool -P keepalived_connect_any on
</pre></div>


<p class="wp-block-paragraph">これで、keepalivedが接続やVIPの管理、ヘルスチェック用のスクリプト実施などができるようになる。はず。<br>-Pは永続化</p>



<h4 class="wp-block-heading">ポートの許可</h4>



<p class="wp-block-paragraph">もしHTTPでのチェックや独自ポートを使う場合は以下の設定も必要とのこと。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
$ sudo semanage port -a -t http_port_t -p tcp 8080
</pre></div>


<h2 class="wp-block-heading">Firewall設定</h2>



<p class="wp-block-paragraph">今回のハマりポイントだったfirewall。rich-ruleで許可したつもりがうまく設定されていなかった。結局はリッチルールは不要で、vrrpプロトコルを許可すればいいだけだった。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
$ sudo firewall-cmd --permanent --add-protocol=vrrp
$ sudo firewall-cmd --reload

$ sudo firewall-cmd --list-all
</pre></div>


<h2 class="wp-block-heading">確認手順など</h2>



<h4 class="wp-block-heading">journalctl</h4>



<p class="wp-block-paragraph">keepalivedの挙動ログが確認できる。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
$ journalctl -u keepalived | grep STATE
</pre></div>

<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
$ journalctl -u keepalived -f
</pre></div>


<h4 class="wp-block-heading">ip</h4>



<p class="wp-block-paragraph">MASTER では物理IPに加えて仮想IPが確認できて、BACKUPは物理IPのみ</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
$ hostname -I

$ ip addr show eth0
</pre></div>


<h4 class="wp-block-heading">tcpdump</h4>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
$ sudo tcpdump -ni eth0 vrrp
</pre></div>


<p class="wp-block-paragraph">vrrpパケットが届いているか（送出されているか）確認できる。</p>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
