NGINX Plus 冗長構成

0. 事前作業

NGINX Install

冗長構成とするため、 ubuntu02 に対しNGINXをインストールします。 NGINX Plusインストール済みの ubuntu02-nginx もご利用いただけます。

Windows Jump Hostへログインいただくと、SSHClientのショートカットがありますので、そちらをダブルクリックし ubuntu02 もしくは ubuntu02-nginx へ接続ください

  • ../../_images/putty_icon.jpg
  • ../../_images/putty_menu.jpg
以下のページの内容を参考にNGINX Plus及びモジュールをインストールします

1. 冗長構成

../../_images/nginx-ha-slide.jpg

詳細は以下のページを参照してください

モジュールのインストール

ubuntu01ubuntu02 もしくは ubuntu01-nginxubuntu02-nginx の双方で以下のモジュールをインストールしてください

sudo apt-get install nginx-ha-keepalived  nginx-sync

インストール結果を確認してください

dpkg-query -l | grep -e nginx-ha-keepalived -e nginx-sync
実行結果サンプル
1ii  nginx-ha-keepalived                2.2.7-4~focal                         amd64        Tools for creating and managing NGINX Plus HA cluster
2ii  nginx-sync                         1.1                                   all          nginx configs synchronization script

スクリプトを用いた初期設定

双方のホストで nginx-ha-setup コマンドを利用しセットアップを行います。実行するホストに注意してください

ubuntu01 もしくは ubuntu01-nginx で以下の内容を実行してください。 MASTER としてセットアップします

sudo nginx-ha-setup
実行結果サンプル
 1Thank you for using NGINX Plus!
 2
 3This script is intended for use with RHEL/CentOS/SLES/Debian/Ubuntu-based systems.
 4It will configure highly available NGINX Plus environment in Active/Passive pair.
 5
 6NOTE: you will need the following in order to continue:
 7 - 2 running systems (nodes) with static IP addresses
 8 - one free IP address to use as Cluster IP endpoint
 9
10It is strongly recommended to run this script simultaneously on both nodes,
11e.g. use two terminal windows and switch between them step by step.
12
13It is recommended to run this script under screen(1) in order to allow
14installation process to continue in case of unexpected session disconnect.
15
16Press <Enter> to continue...  << ENTER を入力
17
18Step 1: configuring internal management IP addresses.
19
20In order to communicate with each other, both nodes must have at least one IP address.
21
22The guessed primary IP of this node is: 10.1.1.7/24
23
24Do you want to use this address for internal cluster communication? (y/n)  << y を入力
25IP address of this host is set to: 10.1.1.7/24
26Primary network interface: ens5
27
28Now please enter IP address of a second node: 10.1.1.6  << 10.1.1.6もしくは10.1.1.12(対向のNGINX) を入力
29You entered: 10.1.1.6
30Is it correct? (y/n)  << y を入力
31IP address of the second node is set to: 10.1.1.6
32
33Press <Enter> to continue...  << ENTER を入力
34
35Step 2: creating keepalived configuration
36
37Now you have to choose cluster IP address.
38This address will be used as en entry point to all your cluster resources.
39The chosen address must not be one already associated with a physical node.
40
41Enter cluster IP address: 10.1.1.100  << 10.1.1.100(HA IP) を入力
42You entered: 10.1.1.100
43Is it correct? (y/n) << y を入力
44
45You must choose which node should have the MASTER role in this cluster.
46
47Please choose what the current node role is:
481) MASTER
492) BACKUP
50
51(on the second node you should choose the opposite variant)
52
53Press 1 or 2.  << 1(MASTER) を入力
54This is the MASTER node.
55
56Step 3: starting keepalived
57
58Starting keepalived...
59keepalived has been successfully started.
60
61Press <Enter> to continue... << ENTER を入力
62
63Step 4: configuring cluster
64
65Enabling keepalived and nginx at boot time...
66Initial configuration complete!
67
68keepalived logs are written to syslog and located here:
69/var/log/syslog
70
71Further configuration may be required according to your needs
72and environment.
73Main configuration file for keepalived can be found at:
74 /etc/keepalived/keepalived.conf
75
76To control keepalived, use 'service keepalived' command:
77 service keepalived status
78
79keepalived documentation can be found at:
80http://www.keepalived.org/
81
82NGINX-HA-keepalived documentation can be found at:
83/usr/share/doc/nginx-ha-keepalived/README
84
85Thank you for using NGINX Plus!

ubuntu02 もしくは ubuntu02-nginx で以下の内容を実行してください。 BACKUP としてセットアップします

sudo nginx-ha-setup
実行結果サンプル
 1Thank you for using NGINX Plus!
 2
 3This script is intended for use with RHEL/CentOS/SLES/Debian/Ubuntu-based systems.
 4It will configure highly available NGINX Plus environment in Active/Passive pair.
 5
 6NOTE: you will need the following in order to continue:
 7 - 2 running systems (nodes) with static IP addresses
 8 - one free IP address to use as Cluster IP endpoint
 9
10It is strongly recommended to run this script simultaneously on both nodes,
11e.g. use two terminal windows and switch between them step by step.
12
13It is recommended to run this script under screen(1) in order to allow
14installation process to continue in case of unexpected session disconnect.
15
16Press <Enter> to continue...  << ENTER を入力
17
18Step 1: configuring internal management IP addresses.
19
20In order to communicate with each other, both nodes must have at least one IP address.
21
22The guessed primary IP of this node is: 10.1.1.6/24
23
24Do you want to use this address for internal cluster communication? (y/n)  << y を入力
25IP address of this host is set to: 10.1.1.6/24
26Primary network interface: ens5
27
28Now please enter IP address of a second node: 10.1.1.7  << 10.1.1.7もしくは10.1.1.11(対向のNGINX) を入力
29You entered: 10.1.1.7
30Is it correct? (y/n)  << y を入力
31IP address of the second node is set to: 10.1.1.7
32
33Press <Enter> to continue...  << ENTER を入力
34
35Step 2: creating keepalived configuration
36
37Now you have to choose cluster IP address.
38This address will be used as en entry point to all your cluster resources.
39The chosen address must not be one already associated with a physical node.
40
41Enter cluster IP address: 10.1.1.100  << 10.1.1.100(HA IP) を入力
42You entered: 10.1.1.100
43Is it correct? (y/n) << y を入力
44
45You must choose which node should have the MASTER role in this cluster.
46
47Please choose what the current node role is:
481) MASTER
492) BACKUP
50
51(on the second node you should choose the opposite variant)
52
53Press 1 or 2.  << 2(BACKUP) を入力
54This is the BACKUP node.
55
56Step 3: starting keepalived
57
58Starting keepalived...
59keepalived has been successfully started.
60
61Press <Enter> to continue... << ENTER を入力
62
63Step 4: configuring cluster
64
65Enabling keepalived and nginx at boot time...
66Initial configuration complete!
67
68keepalived logs are written to syslog and located here:
69/var/log/syslog
70
71Further configuration may be required according to your needs
72and environment.
73Main configuration file for keepalived can be found at:
74 /etc/keepalived/keepalived.conf
75
76To control keepalived, use 'service keepalived' command:
77 service keepalived status
78
79keepalived documentation can be found at:
80http://www.keepalived.org/
81
82NGINX-HA-keepalived documentation can be found at:
83/usr/share/doc/nginx-ha-keepalived/README
84
85Thank you for using NGINX Plus!

確認

keepalived の 設定ファイルの内容を確認します。双方のホストで実行した結果を確認します

cat /etc/keepalived/keepalived.conf
実行結果サンプル
 1## ubuntu01 もしくは ubuntu01-nginx の出力結果
 2global_defs {
 3        vrrp_version 3
 4}
 5
 6vrrp_script chk_manual_failover {
 7        script "/usr/lib/keepalived/nginx-ha-manual-failover"
 8        interval 10
 9        weight 50
10}
11
12vrrp_script chk_nginx_service {
13        script "/usr/lib/keepalived/nginx-ha-check"
14        interval 3
15        weight 50
16}
17
18vrrp_instance VI_1 {
19        interface ens5
20        priority 101
21        virtual_router_id 51
22        advert_int 1
23        accept
24        garp_master_refresh 5
25        garp_master_refresh_repeat 1
26        unicast_src_ip 10.1.1.7/24
27        unicast_peer {
28                10.1.1.6
29        }
30        virtual_ipaddress {
31                10.1.1.100
32        }
33        track_script {
34                chk_nginx_service
35                chk_manual_failover
36        }
37        notify "/usr/lib/keepalived/nginx-ha-notify"
38}
  • 18-38行目が、冗長構成の主要な設定となります

  • 19行目が、VRRPで利用するインタフェースです

  • 20行目が、Priorityを指定し MASTER101 となります

  • 26行目が自ホストのIPアドレス、28行目が対向ホストのIPアドレス、31行目が冗長構成で利用する VIrtual IP(VIP) となります

実行結果サンプル
 1## ubuntu02 もしくは ubuntu02-nginx の出力結果
 2global_defs {
 3        vrrp_version 3
 4}
 5
 6vrrp_script chk_manual_failover {
 7        script "/usr/lib/keepalived/nginx-ha-manual-failover"
 8        interval 10
 9        weight 50
10}
11
12vrrp_script chk_nginx_service {
13        script "/usr/lib/keepalived/nginx-ha-check"
14        interval 3
15        weight 50
16}
17
18vrrp_instance VI_1 {
19        interface ens5
20        priority 100
21        virtual_router_id 51
22        advert_int 1
23        accept
24        garp_master_refresh 5
25        garp_master_refresh_repeat 1
26        unicast_src_ip 10.1.1.6/24
27        unicast_peer {
28                10.1.1.7
29        }
30        virtual_ipaddress {
31                10.1.1.100
32        }
33        track_script {
34                chk_nginx_service
35                chk_manual_failover
36        }
37        notify "/usr/lib/keepalived/nginx-ha-notify"
38}
  • 18-38行目が、冗長構成の主要な設定となり、基本的な記述は ubuntu01(MASTER) もしくは ubuntu01-nginx(MASTER) となります

  • 20行目が、Priorityを指定し BACKUP100 となります

冗長構成のStateを確認します。双方のホストで実行した結果を確認します

cat /var/run/nginx-ha-keepalived.state
実行結果サンプル
1## ubuntu01 もしくは ubuntu01-nginx の出力結果
2STATE=MASTER
3
4## ubuntu02  もしくは ubuntu02-nginx の出力結果
5STATE=BACKUP

出力結果よりホストのステータスが確認できます

セットアップ後のインタフェースを確認します。双方のホストで実行した結果を確認します

ip addr show ens5
実行結果サンプル
 1## ubuntu01 もしくは ubuntu01-nginx の出力結果
 22: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
 3    link/ether 06:b4:8c:4d:47:0d brd ff:ff:ff:ff:ff:ff
 4    altname enp0s5
 5    inet 10.1.1.7/24 brd 10.1.1.255 scope global dynamic ens5
 6       valid_lft 2830sec preferred_lft 2830sec
 7    inet 10.1.1.100/32 scope global ens5
 8       valid_lft forever preferred_lft forever
 9    inet6 fe80::4b4:8cff:fe4d:470d/64 scope link
10       valid_lft forever preferred_lft forever
11
12## ubuntu02 もしくは ubuntu02-nginx の出力結果
132: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
14    link/ether 06:f7:7d:74:47:55 brd ff:ff:ff:ff:ff:ff
15    inet 10.1.1.6/24 brd 10.1.1.255 scope global dynamic ens5
16       valid_lft 2750sec preferred_lft 2750sec
17    inet6 fe80::4f7:7dff:fe74:4755/64 scope link
18       valid_lft forever preferred_lft forever
  • 各ホストのインタフェースが確認できます

  • MASTER である ubuntu01 もしくは ubuntu01-nginx の結果を確認すると、7-8行目に VIP が割り当てられることが確認できます

VRRPにより、冗長構成が動作していることが確認できます

2. 動作確認

疎通を確認します

ubuntu01 もしくは ubuntu01-nginx で以下の操作を行ってください

curl localhost; echo; curl 10.1.1.7; echo; curl 10.1.1.6; echo; curl 10.1.1.100; echo
または
curl localhost; echo; curl 10.1.1.11; echo; curl 10.1.1.12; echo; curl 10.1.1.100; echo

Note

F5 Lab環境では、VIPを持つホスト以外からVIPへのアクセスはエラーとなります VIPを持つホストから疎通を確認してください

実行結果サンプル
1Dest: 127.0.0.1:80 Response from ip-10-1-1-7
2Dest: 10.1.1.7:80 Response from ip-10-1-1-7
3Dest: 10.1.1.6:80 Response from ip-10-1-1-6
4Dest: 10.1.1.100:80 Response from ip-10-1-1-7
  • ubuntu01 である ip-10-1-1-7 もしくは ubuntu01-nginx である ip-10-1-1-11ubuntu02 である ip-10-1-1-6 もしくは ubuntu02-nginx である ip-10-1-1-12 からの応答が確認できます

  • VIP である 10.1.1.100 の結果を確認すると ubuntu01 もしくは ubuntu01-nginx から応答されていることが確認できます

以下コマンドで Failover を実施します

sudo systemctl stop keepalived
もしくはnginxを停止する場合
sudo systemctl stop nginx

Failover の結果を確認します

sudo systemctl status keepalived
実行結果サンプル
 1 keepalived.service - LVS and VRRP High Availability Monitor
 2     Loaded: loaded (/lib/systemd/system/keepalived.service; enabled; vendor preset: enabled)
 3     Active: inactive (dead) since Wed 2022-09-28 20:14:05 JST; 20s ago
 4   Main PID: 2588 (code=exited, status=0/SUCCESS)
 5
 6Sep 28 19:09:06 ip-10-1-1-7 Keepalived_vrrp[2589]: (VI_1) received lower priority (200) advert from 10.1.1.6 - discarding
 7Sep 28 19:09:07 ip-10-1-1-7 Keepalived_vrrp[2589]: (VI_1) received lower priority (200) advert from 10.1.1.6 - discarding
 8Sep 28 19:09:07 ip-10-1-1-7 Keepalived_vrrp[2589]: (VI_1) Entering MASTER STATE
 9Sep 28 20:14:04 ip-10-1-1-7 systemd[1]: Stopping LVS and VRRP High Availability Monitor...
10Sep 28 20:14:04 ip-10-1-1-7 Keepalived[2588]: Stopping
11Sep 28 20:14:04 ip-10-1-1-7 nginx-ha-keepalived[33420]: Transition to state 'STOP' on VRRP instance 'VI_1'.
12Sep 28 20:14:05 ip-10-1-1-7 Keepalived_vrrp[2589]: Stopped
13Sep 28 20:14:05 ip-10-1-1-7 Keepalived[2588]: Stopped Keepalived v2.2.7 (01/16,2022)
14Sep 28 20:14:05 ip-10-1-1-7 systemd[1]: keepalived.service: Succeeded.
15Sep 28 20:14:05 ip-10-1-1-7 systemd[1]: Stopped LVS and VRRP High Availability Monitor.

出力の内容から keepalived が停止していることが確認できます

以下コマンドを用いてステータスを確認します

cat /var/run/nginx-ha-keepalived.state
実行結果サンプル
1STATE=STOP

keepalived が停止したためステータスが STOP となっていることが確認できます

インタフェースの状態を確認します

ip addr show ens5
実行結果サンプル
12: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
2    link/ether 06:b4:8c:4d:47:0d brd ff:ff:ff:ff:ff:ff
3    altname enp0s5
4    inet 10.1.1.7/24 brd 10.1.1.255 scope global dynamic ens5
5       valid_lft 2491sec preferred_lft 2491sec
6    inet6 fe80::4b4:8cff:fe4d:470d/64 scope link
7       valid_lft forever preferred_lft forever

インタフェースでは、 VIP が表示されていないことが確認できます

ubuntu02 もしくは ``ubuntu02-nginx``のステータスを確認します

sudo systemctl status keepalived
実行結果サンプル
 1 keepalived.service - LVS and VRRP High Availability Monitor
 2     Loaded: loaded (/lib/systemd/system/keepalived.service; enabled; vendor preset: enabled)
 3     Active: active (running) since Wed 2022-09-28 19:06:28 JST; 1h 8min ago
 4    Process: 15162 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 5   Main PID: 15170 (keepalived)
 6      Tasks: 2 (limit: 2333)
 7     Memory: 1.6M
 8     CGroup: /system.slice/keepalived.service
 9             ├─15170 /usr/sbin/keepalived
10             └─15172 /usr/sbin/keepalived
11
12Sep 28 19:06:28 ip-10-1-1-6 Keepalived_vrrp[15172]: (VI_1) Changing effective priority from 150 to 200
13Sep 28 19:06:29 ip-10-1-1-6 Keepalived_vrrp[15172]: (VI_1) received lower priority (151) advert from 10.1.1.7 - discarding
14Sep 28 19:06:30 ip-10-1-1-6 Keepalived_vrrp[15172]: (VI_1) received lower priority (151) advert from 10.1.1.7 - discarding
15Sep 28 19:06:31 ip-10-1-1-6 Keepalived_vrrp[15172]: (VI_1) received lower priority (151) advert from 10.1.1.7 - discarding
16Sep 28 19:06:32 ip-10-1-1-6 Keepalived_vrrp[15172]: (VI_1) Entering MASTER STATE
17Sep 28 19:06:32 ip-10-1-1-6 nginx-ha-keepalived[15194]: Transition to state 'MASTER' on VRRP instance 'VI_1'.
18Sep 28 19:09:07 ip-10-1-1-6 Keepalived_vrrp[15172]: (VI_1) Master received advert from 10.1.1.7 with higher priority 201, ours 200
19Sep 28 19:09:07 ip-10-1-1-6 Keepalived_vrrp[15172]: (VI_1) Entering BACKUP STATE
20Sep 28 19:09:07 ip-10-1-1-6 nginx-ha-keepalived[15482]: Transition to state 'BACKUP' on VRRP instance 'VI_1'.
21Sep 28 20:14:04 ip-10-1-1-6 Keepalived_vrrp[15172]: (VI_1) Entering MASTER STATE

21行目で MASTER となっていることが確認できます

cat /var/run/nginx-ha-keepalived.state
実行結果サンプル
1STATE=MASTER
ip addr show ens5
実行結果サンプル
12: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
2    link/ether 06:f7:7d:74:47:55 brd ff:ff:ff:ff:ff:ff
3    inet 10.1.1.6/24 brd 10.1.1.255 scope global dynamic ens5
4       valid_lft 2442sec preferred_lft 2442sec
5    inet 10.1.1.100/32 scope global ens5
6       valid_lft forever preferred_lft forever
7    inet6 fe80::4f7:7dff:fe74:4755/64 scope link
8       valid_lft forever preferred_lft forever

ubuntu02 もしくは ubuntu02-nginx 上で疎通を確認します

curl localhost; echo; curl 10.1.1.7; echo; curl 10.1.1.6; echo; curl 10.1.1.100; echo
または
curl localhost; echo; curl 10.1.1.11; echo; curl 10.1.1.12; echo; curl 10.1.1.100; echo

Note

F5 Lab環境では、VIPを持つホスト以外からVIPへのアクセスはエラーとなります VIPを持つホストから疎通を確認してください

Dest: 127.0.0.1:80 Response from ip-10-1-1-6
Dest: 10.1.1.7:80 Response from ip-10-1-1-7
Dest: 10.1.1.6:80 Response from ip-10-1-1-6
Dest: 10.1.1.100:80 Response from ip-10-1-1-6
  • ubuntu01 である ip-10-1-1-7 もしくは ubuntu01-nginx である ip-10-1-1-11ubuntu02 である ip-10-1-1-6 もしくは ubuntu02-nginx である ip-10-1-1-12 からの応答が確認できます

  • VIP である 10.1.1.100 の結果を確認すると ubuntu02 もしくは ubuntu02-nginx から応答されていることが確認できます

ubuntu01 もしくは ubuntu01-nginx へ切り戻しを行います

以下コマンドで Failover を実施します

sudo systemctl start keepalived

Failover の結果を確認します

sudo systemctl status keepalived
実行結果サンプル
 1 keepalived.service - LVS and VRRP High Availability Monitor
 2     Loaded: loaded (/lib/systemd/system/keepalived.service; enabled; vendor preset: enabled)
 3     Active: active (running) since Wed 2022-09-28 20:36:35 JST; 4s ago
 4    Process: 33640 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 5   Main PID: 33641 (keepalived)
 6      Tasks: 7 (limit: 2327)
 7     Memory: 2.3M
 8     CGroup: /system.slice/keepalived.service
 9             ├─33641 /usr/sbin/keepalived
10             ├─33642 /usr/sbin/keepalived
11             ├─33656 /bin/sh /usr/lib/keepalived/nginx-ha-notify INSTANCE VI_1 MASTER 201
12             └─33658 systemctl start nginx.service
13
14Sep 28 20:36:35 ip-10-1-1-7 Keepalived[33641]: Startup complete
15Sep 28 20:36:35 ip-10-1-1-7 Keepalived_vrrp[33642]: VRRP_Script(chk_manual_failover) succeeded
16Sep 28 20:36:35 ip-10-1-1-7 Keepalived_vrrp[33642]: (VI_1) Changing effective priority from 101 to 151
17Sep 28 20:36:35 ip-10-1-1-7 nginx-ha-keepalived[33646]: Transition to state 'BACKUP' on VRRP instance 'VI_1'.
18Sep 28 20:36:35 ip-10-1-1-7 Keepalived_vrrp[33642]: VRRP_Script(chk_nginx_service) succeeded
19Sep 28 20:36:35 ip-10-1-1-7 Keepalived_vrrp[33642]: (VI_1) Changing effective priority from 151 to 201
20Sep 28 20:36:36 ip-10-1-1-7 Keepalived_vrrp[33642]: (VI_1) received lower priority (200) advert from 10.1.1.6 - discarding
21Sep 28 20:36:37 ip-10-1-1-7 Keepalived_vrrp[33642]: (VI_1) received lower priority (200) advert from 10.1.1.6 - discarding
22Sep 28 20:36:38 ip-10-1-1-7 Keepalived_vrrp[33642]: (VI_1) received lower priority (200) advert from 10.1.1.6 - discarding
23Sep 28 20:36:39 ip-10-1-1-7 Keepalived_vrrp[33642]: (VI_1) Entering MASTER STATE

ステータスが MASTER となっていることが確認できます。

ステータス、インタフェースの状態を確認します

ステータス確認結果サンプル
 1$ cat /var/run/nginx-ha-keepalived.state
 2STATE=MASTER
 3
 4$ ip addr show ens5
 52: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
 6    link/ether 0a:2d:6d:00:fb:c5 brd ff:ff:ff:ff:ff:ff
 7    altname enp0s5
 8    inet 10.1.1.7/24 brd 10.1.1.255 scope global dynamic ens5
 9       valid_lft 3438sec preferred_lft 3438sec
10    inet 10.1.1.100/32 scope global ens5
11       valid_lft forever preferred_lft forever
12    inet6 fe80::82d:6dff:fe00:fbc5/64 scope link
13       valid_lft forever preferred_lft forever

3. 設定同期

../../_images/nginx-ha-configsync-slide.jpg

詳細は以下のページを参照してください

設定

設定の同期は、ある指定のホストからその他ホスト(郡)へ同期する機能となります。 ubuntu01 もしくは ubuntu01-nginx から ubuntu02 もしくは ubuntu02-nginx に同期する設定を行います。

ubuntu01 もしくは ubuntu01-nginx で以下の操作を行ってください

# ubuntu01-nginx を使用する場合
vi ~/f5j-nginx-plus-lab2-conf/lab/ha-nginx-sync.conf
NODES="10.1.1.6" から NODES="10.1.1.12"に変更してください。

# 設定同期に関する設定をコピー
sudo cp ~/f5j-nginx-plus-lab2-conf/lab/ha-nginx-sync.conf /etc/nginx-sync.conf

# 不要な設定を削除
sudo rm -rf /etc/nginx/conf.d/*

# 必要な設定ファイルをコピー&反映
sudo cp ~/f5j-nginx-plus-lab2-conf/lab/api.conf /etc/nginx/conf.d/
sudo cp ~/f5j-nginx-plus-lab2-conf/lab/ha-demo.conf /etc/nginx/conf.d/default.conf
sudo touch /etc/nginx/conf.d/dummy.conf
sudo nginx -s reload

配置したファイルが存在すること確認します

ls /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/dummy.conf
実行結果サンプル
1/etc/nginx/conf.d/default.conf  /etc/nginx/conf.d/dummy.conf

以下コマンドを実行し、設定ファイルを同期します。 なお、コマンドは root で実行ください。

nginx-sync.sh

Note

SSH証明書認証を行っている場合、 ~/.ssh/id_rsa というファイル名で鍵を配置する必要があります

以下URLを参考に設定ください

Configuring root SSH Access to the Peers

実行結果サンプル
 1 * Synchronization started at Wed Sep 28 10:53:40 UTC 2022
 2
 3 * Checking prerequisites
 4
 5 * Testing local nginx configuration file
 6
 7nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
 8nginx: configuration file /etc/nginx/nginx.conf test is successful
 9Connection to 10.1.1.6 closed.
10Connection to 10.1.1.6 closed.
11Connection to 10.1.1.6 closed.
12 * Backing up configuration on ubuntu@10.1.1.6
13
14Connection to 10.1.1.6 closed.
15Connection to 10.1.1.6 closed.
16Connection to 10.1.1.6 closed.
17Connection to 10.1.1.6 closed.
18Connection to 10.1.1.6 closed.
19 * Updating configuration on ubuntu@10.1.1.6
20
21Connection to 10.1.1.6 closed.
22Connection to 10.1.1.6 closed.
23 * Testing nginx config on ubuntu@10.1.1.6
24
25nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
26nginx: configuration file /etc/nginx/nginx.conf test is successful
27Connection to 10.1.1.6 closed.
28Connection to 10.1.1.6 closed.
29Connection to 10.1.1.6 closed.
30
31 * Synchronization ended at Wed Sep 28 10:53:52 UTC 2022

正しくファイルが同期されているか確認します。

ubuntu02 もしくは ubuntu02-nginx で以下の操作を行ってください

ls /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/dummy.conf
実行結果サンプル
1ls: cannot access '/etc/nginx/conf.d/dummy.conf': No such file or directory
2/etc/nginx/conf.d/default.conf

default.conf は正しくファイルが存在しますが、 dummy.conf は同期の対象外のため ubuntu02 もしくは ubuntu02-nginx には存在しないことがわかります

4. その他冗長構成

その他冗長構成に関する要件については以下の記事を参照してください