|
| 1 | +--- |
| 2 | +title: Clone Node |
| 3 | +--- |
| 4 | + |
| 5 | +# Clone Node |
| 6 | + |
| 7 | +Clone node is a configurable node script that when pointed to another instance of Harper will create a clone of that |
| 8 | +instance's config, databases and setup full replication. If it is run in a location where there is no existing Harper install, |
| 9 | +it will, along with cloning, install Harper. If it is run in a location where there is another Harper instance, it will |
| 10 | +only clone config, databases and replication that do not already exist. |
| 11 | + |
| 12 | +Clone node is triggered when Harper is installed or started with certain environment or command line (CLI) variables set (see below). |
| 13 | + |
| 14 | +**Leader node** - the instance of Harper you are cloning.\ |
| 15 | +**Clone node** - the new node which will be a clone of the leader node. |
| 16 | + |
| 17 | +To start clone run `harperdb` in the CLI with either of the following variables set: |
| 18 | + |
| 19 | +#### Environment variables |
| 20 | + |
| 21 | +- `HDB_LEADER_URL` - The URL of the leader node's operation API (usually port 9925). |
| 22 | +- `HDB_LEADER_USERNAME` - The leader node admin username. |
| 23 | +- `HDB_LEADER_PASSWORD` - The leader node admin password. |
| 24 | +- `REPLICATION_HOSTNAME` - _(optional)_ The clones replication hostname. This value will be added to `replication.hostname` on the clone node. If this value is not set, replication will not be set up between the leader and clone. |
| 25 | + |
| 26 | +For example: |
| 27 | + |
| 28 | +``` |
| 29 | +HDB_LEADER_URL=https://node-1.my-domain.com:9925 REPLICATION_HOSTNAME=node-2.my-domain.com HDB_LEADER_USERNAME=... HDB_LEADER_PASSWORD=... harperdb |
| 30 | +``` |
| 31 | + |
| 32 | +#### Command line variables |
| 33 | + |
| 34 | +- `--HDB_LEADER_URL` - The URL of the leader node's operation API (usually port 9925). |
| 35 | +- `--HDB_LEADER_USERNAME` - The leader node admin username. |
| 36 | +- `--HDB_LEADER_PASSWORD` - The leader node admin password. |
| 37 | +- `--REPLICATION_HOSTNAME` - _(optional)_ The clones clustering host. This value will be added to `replication.hostname` on the clone node. If this value is not set, replication will not be set up between the leader and clone. |
| 38 | + |
| 39 | +For example: |
| 40 | + |
| 41 | +``` |
| 42 | +harperdb --HDB_LEADER_URL https://node-1.my-domain.com:9925 --REPLICATION_HOSTNAME node-2.my-domain.com --HDB_LEADER_USERNAME ... --HDB_LEADER_PASSWORD ... |
| 43 | +``` |
| 44 | + |
| 45 | +Each time clone is run it will set a value `cloned: true` in `harperdb-config.yaml`. This value will prevent clone from |
| 46 | +running again. If you want to run clone again set this value to `false`. If Harper is started with the clone variables |
| 47 | +still present and `cloned` is true, Harper will just start as normal. |
| 48 | + |
| 49 | +Clone node does not require any additional configuration apart from the variables referenced above. |
| 50 | +However, if you wish to set any configuration during clone this can be done by passing the config as environment/CLI |
| 51 | +variables or cloning overtop of an existing `harperdb-config.yaml` file. |
| 52 | + |
| 53 | +More can be found in the Harper config documentation [here](../deployments/configuration). |
| 54 | + |
| 55 | +### Excluding database and components |
| 56 | + |
| 57 | +To set any specific (optional) clone config, including the exclusion of any database and/or replication, there is a file |
| 58 | +called `clone-node-config.yaml` that can be used. |
| 59 | + |
| 60 | +The file must be located in the `ROOTPATH` directory of your clone (the `hdb` directory where you clone will be installed. |
| 61 | +If the directory does not exist, create one and add the file to it). |
| 62 | + |
| 63 | +The config available in `clone-node-config.yaml` is: |
| 64 | + |
| 65 | +```yaml |
| 66 | +databaseConfig: |
| 67 | + excludeDatabases: |
| 68 | + - database: null |
| 69 | + excludeTables: |
| 70 | + - database: null |
| 71 | + table: null |
| 72 | +componentConfig: |
| 73 | + exclude: |
| 74 | + - name: null |
| 75 | +``` |
| 76 | +
|
| 77 | +_Note: only include the configuration that you are using. If no clone config file is provided nothing will be excluded, |
| 78 | +unless it already exists on the clone._ |
| 79 | +
|
| 80 | +`databaseConfig` - Set any databases or tables that you wish to exclude from cloning. |
| 81 | + |
| 82 | +`componentConfig` - Set any components that you do not want cloned. Clone node will not clone the component code, |
| 83 | +it will only clone the component reference that exists in the leader harperdb-config file. |
| 84 | + |
| 85 | +### Cloning configuration |
| 86 | + |
| 87 | +Clone node will not clone any configuration that is classed as unique to the leader node. This includes `replication.hostname`, `replication.url`,`clustering.nodeName`, |
| 88 | +`rootPath` and any other path related values, for example `storage.path`, `logging.root`, `componentsRoot`, |
| 89 | +any authentication certificate/key paths. |
| 90 | + |
| 91 | +### Cloning system database |
| 92 | + |
| 93 | +Harper uses a database called `system` to store operational information. Clone node will only clone the user and role |
| 94 | +tables from this database. It will also set up replication on this table, which means that any existing and future user and roles |
| 95 | +that are added will be replicated throughout the cluster. |
| 96 | + |
| 97 | +Cloning the user and role tables means that once clone node is complete, the clone will share the same login credentials with |
| 98 | +the leader. |
| 99 | + |
| 100 | +### Replication |
| 101 | + |
| 102 | +If clone is run with the `REPLICATION_HOSTNAME` variable set, a fully replicating clone will be created. |
| 103 | + |
| 104 | +If any databases are excluded from the clone, replication will not be set up on these databases. |
| 105 | + |
| 106 | +### JWT Keys |
| 107 | + |
| 108 | +If cloning with replication, the leader's JWT private and public keys will be cloned. To disable this, include `CLONE_KEYS=false` in your clone variables. |
| 109 | + |
| 110 | +### Cloning overtop of an existing Harper instance |
| 111 | + |
| 112 | +Clone node will not overwrite any existing config, database or replication. It will write/clone any config database or replication |
| 113 | +that does not exist on the node it is running on. |
| 114 | + |
| 115 | +An example of how this can be useful is if you want to set Harper config before the clone is created. To do this you |
| 116 | +would create a harperdb-config.yaml file in your local `hdb` root directory with the config you wish to set. Then |
| 117 | +when clone is run it will append the missing config to the file and install Harper with the desired config. |
| 118 | + |
| 119 | +Another useful example could be retroactively adding another database to an existing instance. Running clone on |
| 120 | +an existing instance could create a full clone of another database and set up replication between the database on the |
| 121 | +leader and the clone. |
| 122 | + |
| 123 | +### Cloning steps |
| 124 | + |
| 125 | +Clone node will execute the following steps when ran: |
| 126 | + |
| 127 | +1. Look for an existing Harper install. It does this by using the default (or user provided) `ROOTPATH`. |
| 128 | +1. If an existing instance is found it will check for a `harperdb-config.yaml` file and search for the `cloned` value. If the value exists and is `true` clone will skip the clone logic and start Harper. |
| 129 | +1. Clone harperdb-config.yaml values that don't already exist (excluding values unique to the leader node). |
| 130 | +1. Fully clone any databases that don't already exist. |
| 131 | +1. If classed as a "fresh clone", install Harper. An instance is classed as a fresh clone if there is no system database. |
| 132 | +1. If `REPLICATION_HOSTNAME` is set, set up replication between the leader and clone. |
| 133 | +1. Clone is complete, start Harper. |
| 134 | + |
| 135 | +### Cloning with Docker |
| 136 | + |
| 137 | +To run clone inside a container add the environment variables to your run command. |
| 138 | + |
| 139 | +For example: |
| 140 | + |
| 141 | +``` |
| 142 | +docker run -d \ |
| 143 | + -v <host directory>:/home/harperdb/hdb \ |
| 144 | + -e HDB_LEADER_PASSWORD=password \ |
| 145 | + -e HDB_LEADER_USERNAME=admin \ |
| 146 | + -e HDB_LEADER_URL=https://1.123.45.6:9925 \ |
| 147 | + -e REPLICATION_HOSTNAME=1.123.45.7 \ |
| 148 | + -p 9925:9925 \ |
| 149 | + -p 9926:9926 \ |
| 150 | + harperdb/harperdb |
| 151 | +``` |
| 152 | + |
| 153 | +Clone will only run once, when you first start the container. If the container restarts the environment variables will be ignored. |
0 commit comments