Skip to content

Commit fb75a00

Browse files
committed
feat(ns-ha): add automatic config script
1 parent 0f6182e commit fb75a00

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

packages/ns-ha/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ define Package/ns-ha/install
4545
$(INSTALL_BIN) ./files/ns-ha-enable $(1)/usr/sbin
4646
$(INSTALL_BIN) ./files/ns-ha-export $(1)/usr/sbin
4747
$(INSTALL_BIN) ./files/ns-ha-import $(1)/usr/sbin
48+
$(INSTALL_BIN) ./files/ns-ha-config $(1)/usr/sbin
4849
$(INSTALL_DATA) ./files/400-network $(1)/etc/hotplug.d/keepalived
4950
$(INSTALL_DATA) ./files/500-nathelpers $(1)/etc/hotplug.d/keepalived
5051
$(INSTALL_DATA) ./files/500-netmap $(1)/etc/hotplug.d/keepalived

packages/ns-ha/README.md

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Limitations:
1414
- WAN must be configured with DHCP
1515
- Extra packages such as NUT are not supported
1616
- rsyslog configuration is not synced: if you need to send logs to a remote server, you must use the controller
17-
- Hotspot is not supported since it requires a new registration when the primary node goes down because the MAC address associated with the hotspot interface will be different
17+
- Hotspot is not supported since it requires a new registration when the main node goes down because the MAC address associated with the hotspot interface will be different
1818

1919
The following features are supported:
2020

@@ -54,12 +54,36 @@ The setup process configures the following:
5454
- Configures conntrackd to sync the connection tracking table
5555

5656
In this example:
57-
- `main` is the primary node, with LAN IP `192.168.100.238` and HA IP `10.12.12.1`
58-
- `backup` is the backup node, with LAN IP `192.168.100.237` and HA IP `10.12.12.2`
57+
- `main_node_ip` is the main node, with LAN IP `192.168.100.238` and HA IP `10.12.12.1`
58+
- `backup_node_ip` is the backup node, with LAN IP `192.168.100.239` and HA IP `10.12.12.2`
5959
- the virtual IP is `192.168.100.240`
6060

61-
1. On the primary node:
62-
- Name the primary firewall `main`
61+
### Automatic configuration
62+
63+
The package provides a script to configure the HA cluster automatically:
64+
```
65+
ns-ha-config <main_ip> <backup_ip> <virtual_ip>
66+
```
67+
68+
The script will:
69+
- configure the main node with the main IP and virtual IP
70+
- read the password and public key from the main node
71+
- configure the backup node with the backup IP and virtual IP using SSH: you may need to enter the password of the backup node
72+
73+
Assumptions:
74+
75+
- the LAN of the main node has a static IP address on the LAN interface already set to `main_node_ip`
76+
- the LAN of the backup node has a static IP address on the LAN interface already set to `backup_node_ip`
77+
78+
Usage example:
79+
```
80+
ns-ha-config 192.168.100.238 192.168.100.239 192.1268.100.240
81+
```
82+
83+
### Manual configuration using APIs
84+
85+
1. On the main node:
86+
- Name the main firewall `main`
6387
- Set `br-lan` (LAN) to static IP: `192.168.100.238/24`
6488
- Set `eth1` (WAN) to DHCP (no PPPoE)
6589
- Reserve `eth2` for HA configuration (it must not configured in the network settings)
@@ -69,7 +93,7 @@ In this example:
6993
```
7094
The command will output something like:
7195
```json
72-
{"password": "5aeab1d8", "pubkey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDF7MYY8vfgE/JgJT8mOejwIhB4UYKS4g/QSA7fwntCbN0LQ3nTA6LO3AzqhUCHd6LBS5P9aefTqDcG+cJQiGbXReqX1z4trQGs7QkBLbjlXb2Vock17UIGbm5ao8jyPsD4ADNdMF8p0S2xDvnfsOh7MXLy5N7QZGp1G3ISB6JVw0mdCn3GXYg1X9XB7Pqu0OJm7+n2SJvA1KXn9fKUDX92U1fGQcid05C3yRBS5QXB7VAAP55KKYp4RmQMCOcJDhDoHGB6Ia/fTxfhnLdXJcAHU2MTtyaEY7NWoPjKZ3769GIu4KLLDPB8aH9emg23Mej+eiMRIg0vFXsaJWVPuZzj root@primary"}
96+
{"password": "5aeab1d8", "pubkey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDF7MYY8vfgE/JgJT8mOejwIhB4UYKS4g/QSA7fwntCbN0LQ3nTA6LO3AzqhUCHd6LBS5P9aefTqDcG+cJQiGbXReqX1z4trQGs7QkBLbjlXb2Vock17UIGbm5ao8jyPsD4ADNdMF8p0S2xDvnfsOh7MXLy5N7QZGp1G3ISB6JVw0mdCn3GXYg1X9XB7Pqu0OJm7+n2SJvA1KXn9fKUDX92U1fGQcid05C3yRBS5QXB7VAAP55KKYp4RmQMCOcJDhDoHGB6Ia/fTxfhnLdXJcAHU2MTtyaEY7NWoPjKZ3769GIu4KLLDPB8aH9emg23Mej+eiMRIg0vFXsaJWVPuZzj root@main"}
7397
```
7498
The `password` and `pubkey` fields must be used in the backup node configuration.
7599
- Apply the configuration:
@@ -82,12 +106,12 @@ In this example:
82106

83107
2. On the backup node:
84108
- Name the backup firewall `backup`
85-
- Set `eth0` (LAN) to static IP: `192.168.100.237/24`
109+
- Set `eth0` (LAN) to static IP: `192.168.100.239/24`
86110
- Set `eth1` (WAN) to DHCP (no PPPoE)
87111
- The `eth2` interface will be used for the HA configuration
88-
- Setup the configuration that will: create the `ha` zone, configure the IP for the HA interface, setup keepalived. Use the `password` and `pubkey` from the primary node:
112+
- Setup the configuration that will: create the `ha` zone, configure the IP for the HA interface, setup keepalived. Use the `password` and `pubkey` from the main node:
89113
```sh
90-
echo '{"role": "backup", "main_node_ip": "192.168.100.238", "backup_node_ip": "192.168.100.239", "virtual_ip": "192.168.100.240/24", "password": "5aeab1d8", "pubkey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDF7MYY8vfgE/JgJT8mOejwIhB4UYKS4g/QSA7fwntCbN0LQ3nTA6LO3AzqhUCHd6LBS5P9aefTqDcG+cJQiGbXReqX1z4trQGs7QkBLbjlXb2Vock17UIGbm5ao8jyPsD4ADNdMF8p0S2xDvnfsOh7MXLy5N7QZGp1G3ISB6JVw0mdCn3GXYg1X9XB7Pqu0OJm7+n2SJvA1KXn9fKUDX92U1fGQcid05C3yRBS5QXB7VAAP55KKYp4RmQMCOcJDhDoHGB6Ia/fTxfhnLdXJcAHU2MTtyaEY7NWoPjKZ3769GIu4KLLDPB8aH9emg23Mej+eiMRIg0vFXsaJWVPuZzj root@primary"}' | /usr/libexec/rpcd/ns.ha call setup
114+
echo '{"role": "backup", "main_node_ip": "192.168.100.238", "backup_node_ip": "192.168.100.239", "virtual_ip": "192.168.100.240/24", "password": "5aeab1d8", "pubkey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDF7MYY8vfgE/JgJT8mOejwIhB4UYKS4g/QSA7fwntCbN0LQ3nTA6LO3AzqhUCHd6LBS5P9aefTqDcG+cJQiGbXReqX1z4trQGs7QkBLbjlXb2Vock17UIGbm5ao8jyPsD4ADNdMF8p0S2xDvnfsOh7MXLy5N7QZGp1G3ISB6JVw0mdCn3GXYg1X9XB7Pqu0OJm7+n2SJvA1KXn9fKUDX92U1fGQcid05C3yRBS5QXB7VAAP55KKYp4RmQMCOcJDhDoHGB6Ia/fTxfhnLdXJcAHU2MTtyaEY7NWoPjKZ3769GIu4KLLDPB8aH9emg23Mej+eiMRIg0vFXsaJWVPuZzj root@main"}' | /usr/libexec/rpcd/ns.ha call setup
91115
uci commit
92116
/etc/init.d/network restart
93117
/etc/init.d/firewall restart
@@ -96,11 +120,11 @@ In this example:
96120

97121
## How it works
98122

99-
The HA cluster consists of two nodes: one is the primary and the other is the backup.
100-
All configurations must be always done on the primary node.
123+
The HA cluster consists of two nodes: one is the main and the other is the backup.
124+
All configurations must be always done on the main node.
101125
The configuration is then automatically synchronized to the backup node.
102126

103-
Keepalived runs a specially crafted rsync script (`/etc/keepalived/scripts/ns-rsync.sh`) on the primary node to:
127+
Keepalived runs a specially crafted rsync script (`/etc/keepalived/scripts/ns-rsync.sh`) on the main node to:
104128
- export WireGuard interfaces, IPsec interfaces, and routes to `/etc/ha`
105129
- synchronize all files listed by `sysupgrade -l` and custom files added with the `add_sync_file` option from scripts inside `/etc/hotplug.d/keepalived` directory;
106130
files are synchronized to the backup node inside the directory `/usr/share/keepalived/rsync/`
@@ -113,16 +137,16 @@ The event is triggered with an `ACTION` parameter that can be:
113137
During this phase, all directories (like `/etc/openvpn` and `/etc/ha`) are synched to the original position.
114138
Also WireGuard interfaces, IPsec interfaces and routes are imported from the `/etc/ha` directory but in disabled state.
115139

116-
- `NOTIFY_MASTER`: the script can be executed both on the primary and on the backup node:
117-
- on the primary node, after keepalived is started: this is the normal startup state
140+
- `NOTIFY_MASTER`: the script can be executed both on the main and on the backup node:
141+
- on the main node, after keepalived is started: this is the normal startup state
118142
- on the backup node, after a switchover has been done: this is the failover state;
119-
all WireGuard interfaces, IPsec interfaces and routes previously imported from the `/etc/ha` are enabled if they were enabled on the primary node
143+
all WireGuard interfaces, IPsec interfaces and routes previously imported from the `/etc/ha` are enabled if they were enabled on the main node
120144

121-
- `NOTIFY_BACKUP`: the script is executed on the backup node, after keepalived is started or if the primary returns up after a downtime
145+
- `NOTIFY_BACKUP`: the script is executed on the backup node, after keepalived is started or if the main returns up after a downtime
122146
All non-required services are disabled, including WireGuard interfaces, IPsec interfaces and routes.
123147

124-
The backup node keeps the configuration in sync with the primary node, but most services, including crontabs, are disabled.
125-
The following cronjobs are disabled on the backup node and enabled on the primary node:
148+
The backup node keeps the configuration in sync with the main node, but most services, including crontabs, are disabled.
149+
The following cronjobs are disabled on the backup node and enabled on the main node:
126150

127151
- subscription heartbeat
128152
- subscription inventory

0 commit comments

Comments
 (0)