I've found that in my cluster I needed to update these and others; etc/hosts /etc/hostname /etc/postfix/main.cf /etc/pve/corosync.conf /etc/pve/storage.cfg /etc/pve/user.cfg /etc/pve/ceph.conf /etc/pve/priv/known_hosts /etc/pve/ha/groups.cfg
Please read through the entire post before you execute anything
I wrote a one-liner that changes all found occurrences of the old hostname and changes it to the new one:
Bash:
#!/bin/bash
exit 1
OLDNODE="name"
NEWNODE="name"
grep -rnw /etc -e '$OLDNODE' | awk -F ':' '{print $1}' | sort | uniq | xargs -I {} sed -i 's|$OLDNODE|$NEWNODE|g' {}
mv /etc/pve/nodes/$OLDNODE /root/$OLDNODE.backup
postalias /etc/aliases
pvecm updatecerts -f
reboot
Here's a detailed breakdown of each part of the script:
### Updating References in Configuration Files
Bash:
grep -rnw /etc -e '$OLDNODE' | awk -F ':' '{print $1}' | sort | uniq | xargs -I {} sed -i 's|$OLDNODE|$NEWNODE|g' {}
- This pipeline of commands updates references from `$OLDNODE` to `$NEWNODE` in files within the `/etc` directory:
- `grep -rnw /etc -e '$OLDNODE'`: Searches recursively (`-r`) in the `/etc` directory for the exact match (`-w`) of the string `$OLDNODE`, including line numbers (`-n`). Note that single quotes might prevent variable expansion, treating `$OLDNODE` as a literal string. Double quotes should be used if `$OLDNODE` is a variable.
- `awk -F ':' '{print $1}'`: Processes each line from `grep`, using `:` as a field separator, and prints the first field, which corresponds to the file path.
- `sort | uniq`: Sorts the file paths and removes any duplicates, ensuring each file is processed only once.
- `xargs -I {} sed -i 's|$OLDNODE|$NEWNODE|g' {}`: For each unique file path, `xargs` invokes `sed` to replace all occurrences of `$OLDNODE` with `$NEWNODE` in-place (`-i`). The `{}` is a placeholder for the file path. Note that using `|` as a delimiter in the `sed` command allows using paths without escaping `/`.
### Updating Postfix Aliases Database
- Updates the Postfix alias database. Postfix uses `/etc/aliases` (and its corresponding database file, usually `/etc/aliases.db`) to redirect mail for local recipients. The `postalias` command creates or updates the alias database (`/etc/aliases.db`) from the text file `/etc/aliases`. The hostname (`myhostname`) in the Postfix configuration is updated, and `/etc/aliases.db` might contain the old hostname, necessitating this update.
### Updating Proxmox VE Cluster Certificates
- This command updates the certificates used by the Proxmox VE cluster. `pvecm` is a command-line tool for Proxmox VE cluster management, and `updatecerts` is the command used to update the cluster's certificates. The `-f` flag forces the update without asking for confirmation. This might be necessary if the node's hostname or other critical information has changed.
### Rebooting the System
- This command reboots the system.
### General Notes
- The script assumes that `$OLDNODE` and `$NEWNODE` are defined and exported in the environment where the script runs, or they should be replaced with actual values or passed to the script as arguments.
- It's critical to use this script with caution, especially the parts that modify system configurations and reboot the system, as they can have significant effects on the system's operation and accessibility.
- Before running such a script, especially on a production system, it's highly recommended to have a backup and a recovery plan in place.
- Use at your own risk.
- Dont forget to change the /etc/hosts on the other nodes in the cluster to reflect the made changes.
- I first migrated all my nodes to the other nodes in the cluster so that /etc/pve/nodes/$OLDNODE/qemu-server/ was empty, even templates, after the reboot when everything was fine, I migrated the VMs back to the new node. (remove the mds entry for the node your changing the name on first from /etc/pve/ceph.conf before manually recreating).
- Only thing that remained was manually deleting and recreating the CEPH metadata, monitor and managers referencing the old names as in mgr.$OLDNAME, mon.$OLDNAME and mds,$OLDNAME