CHANGING THE AHV and CVM HOSTNAME WITHOUT DOWNTIME

Advertisements

CHANGING THE AHV AND CVM HOSTNAME WITHOUT DOWNTIME

Following procedure will explain How to change the AHV and CVM hostname in production

If you have already provided internet connectivity for the Nutanix portal you can download the script from this URL :-

https://download.nutanix.com/kbattachments/2925/update_hostname_el6el7_v2.sh

If internet connectivity is not there you can download this file in your system and upload or create file with update_hostname_e16e17_v2.sh in /tmp directory.

Requirement :-

Compatible software version(s): AHV 20170830. X, 20190916. X or later.

CHANGING THE AHV AND CVM HOSTNAME WITHOUT DOWNTIME

AHV using script

Please follow this steps to change the hostname of AHV host :-

  1. Take the Putty of the AHV host whose hostname you want to change.
  2. Change working directory to
root@NTNX-2hxk999-A ]# :- cd /tmp
  1. Using native Linux wget utility download the update hostname script from the Nutanix download portal.
root@NTNX-2hxk999-A tmp]# wget https://download.nutanix.com/kbattachments/2925/update_hostname_el6el7_v1.sh
 --2020-08-26 08:34:05--  https://download.nutanix.com/kbattachments/2925/update_hostname_el6el7_v1.sh
 Resolving download.nutanix.com… 54.192.183.44, 54.192.183.71, 54.192.183.61, …
 Connecting to download.nutanix.com|54.192.183.44|:443… connected.
 HTTP request sent, awaiting response… 200 OK
 Length: 7531 (7.4K) [text/x-sh]
 Saving to: “update_hostname_el6el7_v1.sh”
 0% [                                                                                                                               ] 0           --.-K/s              
 100%[==============================================================================================================================>] 7,531       --.-K/s   in 0s      
 2020-08-26 08:34:11 (548 MB/s) - “update_hostname_el6el7_v1.sh” saved [7531/7531]
  1. You can verify the downloaded script file using “ls ” command.Now run the script with the bash command to update new AHV hostname.
root@NTNX-2hxk999-A tmp]# bash update_hostname_el6el7_v1.sh NodeA
OS Distribution: el6
 Hostname: NTNX-2hxk999-A
 update hostname from 'NTNX-2hxk999-A' to 'NodeA' … ok
 restart service rsyslog … ok
 restart service lldpd … ok
 reload service auditd's config … ok
 update config file: /etc/hosts … ok
 update config file: /etc/hostname … ok
 update config file: /etc/sysconfig/network … ok
 update ovsdb-server database … skipped

Replace NodeA with the new hostname of the AHV host.

AHV hostname limitation

1) The maximum length is 64 characters.
2) Allowed characters are uppercase and lowercase letters (A-Z and a-z), decimal digits (0-9), dots (.), and hyphens (-).
3) The entity name must start and end with a number or letter.

5. Open new putty with same AHV host and after login, new AHV host name will prompt in terminal.

root@NodeA ]# 
  1. Take the Putty of the CVM running on the host whose hostname you changed.
nutanix@NTNX-2hxk999-A-CVM:X.X.1.18:~$ cluster status --- Make sure all services are running
nutanix@NTNX-2hxk999-A-CVM:X.X.1.18:~$ genesis stop acropolis; cluster start
2020-08-26 08:36:03.999096: Stopping acropolis (pids [13574, 13634, 13635, 13636])
 2020-08-26 08:36:07.809146: Services running on this node:
   cassandra: [11820, 11859, 11860, 11874, 12251]
   cerebro: [13002, 13081, 13082, 13222]
   snmp_manager: []
   delphi: [15000, 15075, 15076, 15077]
   aplos_engine: [14604, 14655, 14656, 14657]
   stargate: [12669, 12700, 12701, 12702, 12703]
   curator: [13043, 13165, 13166, 13228]
   sys_stat_collector: [13622, 13730, 13731, 13732]
   nutanix_guest_tools: [13762, 13826, 13827, 13836]
   tunnel_manager: []
   cluster_config: [14537, 14596, 14597, 14598]
   mantle: [12384, 12467, 12468, 12505]
   genesis: [7551, 7629, 7652, 7653, 9179, 9180]
   uhura: [13598, 13688, 13689, 13691]
   catalog: [13497, 13781, 13782, 13783]
   xtrim: [15319, 15440, 15441, 15442]
   minerva_cvm: [14529, 14566, 14567, 14568, 15034]
   secure_file_sync: [11381, 11415, 11416, 11417]
   lazan: [14966, 15031, 15032, 15033]
   prism: [13408, 13442, 13443, 13492, 13494, 13496, 13532, 13533, 13534]
   chronos: [13032, 13123, 13124, 13177]
   pithos: [12379, 12439, 12440, 12469]
   athena: [13097, 13282, 13283, 13285]
   mercury: [14569, 14627, 14628, 14658]
   insights_server: [12963, 12998, 12999, 13044]
   scavenger: [9089, 9120, 9121, 9122]
   foundation: []
   janus: []
   flow: [15039, 15205, 15206, 15207]
   acropolis: []
   cluster_health: [15403, 15512, 15653, 15654, 15658, 15709, 15710, 15713, 15717, 15718, 15730, 15731, 15733, 15735, 15736, 15738, 15804, 15805, 15828, 15829, 15830, 15831, 26480, 26481, 26483, 26484, 26486, 26487, 26491, 26492, 26494, 26495, 26496, 26497, 26499, 26500, 29448, 29449, 29749, 29750]
   aplos: [14817, 14995, 14996, 14997, 15525, 15530]
   insights_data_transfer: [12967, 13028, 13029, 13037, 13038, 13039, 13040]
   alert_manager: [13446, 13678, 13679, 13737]
   arithmos: [13481, 13566, 13567, 13693]
   ergon: [12972, 13210, 13211, 13212]
   dynamic_ring_changer: [12375, 12413, 12414, 12479]
   cim_service: [13417, 13476, 13477, 13487]
   ssl_terminator: [11378, 11462, 11463, 11464]
   zookeeper: [7998, 8035, 8036, 8037, 8047, 8065]
   anduril: [15310, 15444, 15445, 15447]

Once this is done after 5 -10 min a new hostname will be display in Prism Console.

AHV Hostname change Using Manual

If you are running with incompatible AHV version follow this following steps to rename the hostname of ahv host.

CHANGING THE AHV AND CVM HOSTNAME WITHOUT DOWNTIME

  1. Take the Putty of the AHV host whose hostname you want to change.
  2. These steps are the same as Linux host name change . Use VI editor to change the hostname in the sysconfig network file.
root@NTNX-2hxk999-A]#vi /etc/sysconfig/network
HOSTNAME=NodeA

3. Use the VI editor to replace the host name in the /etc/hostname file

root@NTNX-2hxk999-A]vi /etc/hostname
NodeA

4. Change the host name displayed by the hostname command

root@NTNX-2hxk999-A]hostname NodeA

5. Open new putty with same AHV host and after login, new AHV host name will prompt in terminal.

root@NodeA ]# 

6. Take the Putty of the CVM running on the host whose hostname you changed.

nutanix@NTNX-2hxk999-A-CVM:X.X.1.18:~$ cluster status --- Make sure all services are running
nutanix@NTNX-2hxk999-A-CVM:X.X.1.18:~$ genesis stop acropolis; cluster start

Once this is done after 5 -10 min a new hostname will be display in Prism Console.

How to change the CVM hostname

To change the hostname of Nutanix controller virtual machine or CVM is very easy using the change_cvm_hostname utility ,this utility is the part of the CVM no need to download it from Nutanix support portal.

nutanix@NTNX-2hxk999-A-CVM:X.X.1.18:~$sudo /usr/local/nutanix/cluster/bin/change_cvm_hostname NTNX-NodeA-CVM
Changing hostname to NTNX-NodeA-CVM. This will reboot the CVM. Do you want to proceed? (Y/N): Y
 2020-08-26 08:49:39 INFO hostname_utils.py:72 Did not find the local SVM hostname NTNX-NodeA-CVM in the host look uptable /etc/hosts
 2020-08-26 08:49:39 INFO hostname_utils.py:97 Found that the SVM hostname in /etc/sysconfig/network does not match NTNX-NodeA-CVM
 2020-08-26 08:49:39 INFO hostname_utils.py:137 Setting display name to NTNX-NodeA-CVM
 2020-08-26 08:49:39 INFO hostname_utils.py:156 Writing custom hostname marker
 2020-08-26 08:49:39 INFO change_cvm_hostname:86 Forwarding storage traffic to another CVM


disconnect SSH or restart the putty session, You will see the new hostname 
nutanix@NTNX-NodeA-CVM

Changing CVM hostname
It is highly recommended changing the hostname using the above step.
Don’t use manual hostname change in CVM.

Hope this port is helpful.

The update_hostname_el6el7_v2.sh script content following coding do not change anything if internet is not there upload the following content.

Disclaimer: Usage of this tool must be under guidance of Nutanix Support or an authorised partner
 Summary: This script automates steps that need to be run on AHV host during host rename procedure
 Version of the script: Version 2
 Compatible software version(s): AHV 20170830.X, 20190916.X
 Brief syntax usage: bash /tmp/update_hostname_el6el7_v2.sh 
 Caveats: The aforementioned syntax usage assumes that the script has already been downloaded in the recommended location, namely, the /tmp folder.
 Once script is executed on AHV host, acropolis service should be restarted on CVM running on the same host.
 Check "CHANGING THE ACROPOLIS HOST NAME" chapter in "AHV Administration Guide" on Nutanix portal for complete description of the procedure
 !/bin/bash
 debug off
 set +x
 usage() {
   local _script=$(basename $1)
   local _exit_code=$2
 echo "Usage: "
   echo " $_script "
   echo "     - the new name of the hots"
   echo
   exit $_exit_code
 }
 check_rc() {
   if [ $? -ne 0 ]; then
     echo "error"
   else
el6_update_hostname() {
   hostname $1
   check_rc
 }
 el7_update_hostname() {
         hostnamectl set-hostname $1 --static
   check_rc
 }
 update_hostname() {
   local _crt=$1
   local _new=$2
   local _distro=$3
 echo -n "update hostname from '$_crt' to '$_new' … "
   case $_distro in
     "el6") el6_update_hostname $_new ;;
     "el7") el7_update_hostname $_new ;;
   esac
 }
 el6_restart_rsyslog() {
   service rsyslog restart > /dev/null 2>&1
   check_rc
 }
 el7_restart_rsyslog() {
   systemctl restart rsyslog
   check_rc
 }
 restart_rsyslog() {
   local _distro=$1
 echo -n "restart service rsyslog … "
   case $_distro in
     "el6") el6_restart_rsyslog ;;
     "el7") el7_restart_rsyslog ;;
   esac
 }
 el6_restart_lldpd() {
   service lldpd restart > /dev/null 2>&1
   check_rc
 }
 el7_restart_lldpd() {
   systemctl restart lldpd
   check_rc
 }
 restart_lldpd() {
   local _distro=$1
 echo -n "restart service lldpd … "
   case $_distro in
     "el6") el6_restart_lldpd ;;
     "el7") el7_restart_lldpd ;;
   esac
 }
 reload_auditd_config() {
   echo -n "reload service auditd's config … "
   pkill -SIGHUP auditd -x
   check_rc
 }
 update_etc_hostname() {
   local _crt=$1
   local _new=$2
 echo -n "update config file: $ETC_HOSTNAME_F … "
   if [ -w $ETC_HOSTNAME_F ]; then
     echo $_new > $ETC_HOSTNAME_F
     check_rc
   else
     echo "skipped (file missing or read-only)"
   fi
 }
 update_etc_hosts() {
   local _crt=$1
   local _new=$2
 echo -n "update config file: $ETC_HOSTS_F … "
   sed -i -r "s/^(127.0.0.1[[:blank:]]+)$_crt$/\1$_new/" $ETC_HOSTS_F
   check_rc
 }
 update_etc_sysconfig_network() {
   local _crt=$1
   local _new=$2
 echo -n "update config file: $ETC_SYSCONFIG_NETWORK_F … "
   if [ -w $ETC_SYSCONFIG_NETWORK_F ]; then
     sed -i -r "s/^(HOSTNAME[[:blank:]]=[[:blank:]])$_crt$/\1$_new/" $ETC_SYSCONFIG_NETWORK_F
     check_rc
   else
     echo "skipped (file missing or read-only)"
   fi
 }
 el7_update_ovsdb_server_database() {
   local _new=$1
   if [ -r $VAR_RUN_OVSDB_SERVER_PID_F ]; then
     ovs-vsctl set Open_vSwitch . external_ids:hostname=$_new
     check_rc
   else
     echo "not running"
   fi
 }
 update_ovsdb_server_database() {
   _new=$1
   _distro=$2
 echo -n "update ovsdb-server database … "
   case "$_distro" in
     "el6") echo "skipped" ;;
     "el7") el7_update_ovsdb_server_database $_new ;;
   esac
 }
 el6_get_hostname() {
   local _el6_hostname=
 if [ -r $ETC_SYSCONFIG_NETWORK_F ]; then
     _el6_hostname=$(grep ^HOSTNAME $ETC_SYSCONFIG_NETWORK_F | tail -n 1 | tr -d ' \t' | cut -d '=' -f 2)
   else
     echo "error: static hostname source ($ETC_SYSCONFIG_NETWORK_F) is missing"
     logger "error: static hostname source ($ETC_SYSCONFIG_NETWORK_F) is missing"
     exit $ERR_MISSING_CONFIG
   fi
   echo $_el6_hostname
 }
 el7_get_hostname() {
   local _el7_hostname=
 if [ -r $ETC_HOSTNAME_F ]; then
     _el7_hostname=$(grep -v ^# /etc/hostname | tail -n 1)
   else
     echo "error: static hostname source ($ETC_HOSTNAME_F) is missing"
     logger "error: static hostname source ($ETC_HOSTNAME_F) is missing"
     exit $ERR_MISSING_CONFIG
   fi
   echo $_el7_hostname
 }
 get_hostname() {
   local _distro=$1
   local _crt_hostname=$2
   local _transient_hostname=$(hostname)
 case "$_distro" in
     "el6")
       local _static_hostname=$(el6_get_hostname) ;;
     "el7")
       local _static_hostname=$(el7_get_hostname) ;;
   esac
 if [ "$_transient_hostname" != "$_static_hostname" ]; then
     echo "warning: transient hostname [$_transient_hostname] and static hostname [$_static_hostname] differ"
     logger "warning: transient hostname [$_transient_hostname] and static hostname [$_static_hostname] differ"
   fi
   eval $_crt_hostname="'$_static_hostname'"
 }
 if [ $# -lt 1 ]; then
   usage $0 $ERR_INVALID_PARAMS
 fi
 generate_report() {
   local _distro=$1
   local _old_hostname=$2
   local _new_hostname=$3
   local _stage=$4
   local _log="/var/log/update_hostname.${_distro}.${_stage}.log"
   local _hostname=$(hostname)
   local _lldpd_status=$(lldpcli show chassis)
   local _etc_hosts_content=$(cat $ETC_HOSTS_F)
   local _ovsdb_server_db=$(ovs-vsctl get Open_vSwitch . external-ids)
 if [ "$_stage" == "ini" ]; then
     local _syslog_audispd=$(grep -E -m 10 "^.$_old_hostname audispd.$" /var/log/messages)
   else
     local _syslog_audispd=$(grep -E -A 10 "^.$_new_hostname audispd.Starting reconfigure.*$" /var/log/messages)
   fi
 rm -f $_log
 echo -e "* OS Distro:\n$_distro\n" >> $_log   echo -e "* Old Hostname:\n$_old_hostname\n" >> $_log
   echo -e "* Current Hostname:\n${_hostname}\n" >> $_log   echo -e "* New Hostname:\n${_new_hostname}\n" >> $_log
   echo -e "* LLDPD:\n${_lldpd_status}\n" >> $_log   echo -e "* $ETC_HOSTS_F:\n${_etc_hosts_content}\n" >> $_log
 if [ -r $ETC_HOSTNAME_F ]; then
     local _etc_hostname_content=$(cat $ETC_HOSTNAME_F)
     echo -e "*** $ETC_HOSTNAME_F:\n${_etc_hostname_content}\n" >> $_log
   fi
 if [ -r $ETC_SYSCONFIG_NETWORK_F ]; then
     local _etc_sysconfig_network_content=$(cat $ETC_SYSCONFIG_NETWORK_F)
     echo -e "*** $ETC_SYSCONFIG_NETWORK_F:\n${_etc_sysconfig_network_content}\n" >> $_log
   fi
 if [ "$DISTRO" == "el7" ]; then
     echo -e "* Open_vSwitch:\n${_ovsdb_server_db}\n" >> $_log   fi   echo -e "* Syslog/Audispd:\n${_syslog_audispd}\n" >> $_log
 }
 ERR_INVALID_PARAMS=1
 ERR_UNKNOWN_DISTRO=2
 ERR_MISSING_CONFIG=3
 ETC_HOSTS_F=/etc/hosts
 ETC_HOSTNAME_F=/etc/hostname
 ETC_SYSCONFIG_NETWORK_F=/etc/sysconfig/network
 VAR_RUN_OVSDB_SERVER_PID_F=/var/run/openvswitch/ovsdb-server.pid
 DISTRO=$(cat /etc/nutanix-release | cut -d '.' -f 1)
 check the distribution right from the begining
 if [ "$DISTRO" != "el6" ] && [ "$DISTRO" != "el7" ]; then
   echo "error: unknown Linux distribution -> $DISTRO"
   logger "error: unknown Linux distribution -> $DISTRO"
   exit $ERR_UNKNOWN_DISTRO
 fi
 echo "OS Distribution: $DISTRO"
 NEW_HOSTNAME=$1
 if echo "$NEW_HOSTNAME" | grep -q -E '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-][a-zA-Z0-9]).)([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$' && [ ${#NEW_HOSTNAME} -le 64 ]
 then
     echo "Hostname valid."
 else
     echo -e "Hostname is invalid.\nThe maximum length is 64 characters.\nAllowed characters are uppercase and lowercase letters (A-Z and a-z), decimal digits (0-9), dots (.), and hyphens (-).\nThe name must start and end with a number or letter."
     exit 1
 fi
 get_hostname $DISTRO CRT_HOSTNAME
 echo "Hostname: $CRT_HOSTNAME"
 STAGE="ini"
 generate_report $DISTRO $CRT_HOSTNAME $NEW_HOSTNAME $STAGE
 update_hostname $CRT_HOSTNAME $NEW_HOSTNAME $DISTRO
 restart_rsyslog $DISTRO
 restart_lldpd $DISTRO
 reload_auditd_config
 update_etc_hosts $CRT_HOSTNAME $NEW_HOSTNAME
 update_etc_hostname $CRT_HOSTNAME $NEW_HOSTNAME
 update_etc_sysconfig_network $CRT_HOSTNAME $NEW_HOSTNAME
 update_ovsdb_server_database $NEW_HOSTNAME $DISTRO
 STAGE="fini"
 generate_report $DISTRO $CRT_HOSTNAME $NEW_HOSTNAME $STAGE

See also :- Nutanix Foundation Platform

Leave a Reply