Updated on 2024-10-21 GMT+08:00

Preparations

Preparing a CSV File

Create a CSV file and write the source server information in the following format to file. Ensure that the file can be accessed.
username,ip,port,password
  • username: indicates the username for logging in to the source server. To ensure that the scripts have sufficient permissions to perform the modification, you need to run them as a user with administrator permissions, such as root.
  • ip: indicates the private IP address of the source server.
  • port: indicates the listening port of the SSH service. By default, port 22 is used on Linux. If the SSH service of the source server is running on another port, specify the port correctly.
  • password: indicates the password for logging in to the source server. The scripts use this password to automatically connect to the source server through SSH.
  • The first line in the CSV file is the title line and will not be parsed by the scripts.
  • Each line in the CSV file contains the information for a single server, with each piece of information separated by a comma.
  • Ensure the format is correct and the information is accurate, avoiding any extra spaces, commas, or invalid IP addresses.
For example:
username,ip,port,password
root,192.168.1.10,xx,examplePass123
root,192.168.1.11,xx,examplePass456

Preparing the Hosts File

Create a text file that contains the content to be added to the /etc/hosts file on the source servers. Ensure that the file can be accessed. Write the API domain names mappings for the related cloud services into the file, and start with #Migration-proxy-start and end with #Migration-proxy-end. The API domain name mappings of related cloud services depend on the actual environment. Contact the environment contact person of the corresponding site to obtain the mappings.

For example:
#Migration-proxy-start
xxx.xxx.xxx.xxx  iam.xxx.com
xxx.xxx.xxx.xxx  ecs.xxx.com
xxx.xxx.xxx.xxx  evs.xxx.com
xxx.xxx.xxx.xxx  ims.xxx.com
xxx.xxx.xxx.xxx  obs.xxx.com
xxx.xxx.xxx.xxx  eps.xxx.com
xxx.xxx.xxx.xxx  vpc.xxx.com
#Migration-proxy-end

Preparing a Log Directory

  • Configure a log directory. The scripts use /var/log/update_hosts as the default log storage directory. If the directory cannot be found, the scripts automatically create it. To change the log storage directory, change the value of LOG_DIR in the script.
  • Check the permissions for the log directory. Ensure that the current user has the write permission for the log directory. If the permissions are insufficient, modify the directory permissions or use another directory.

Checking the Connectivity of the Source Servers

  • Check the network connection. Ensure that the server where the scripts are executed can access all source servers over the network.
  • Check whether the SSH port is reachable. Ensure that the SSH port (22 by default) on the source servers is reachable from the server where the scripts are executed.

Checking the SSH Configuration

  • Configure the SSH service. Ensure that the SSH service has been enabled and is running properly on all source servers. The SSH service is enabled by default on most Linux distributions.
  • Enable SSH password authentication. Ensure that the SSH service on all source servers is configured to accept password authentication so that the scripts can use the password provided in the CSV file for automatic login.

Configuring the Script Executor

Ensure that the following tools and commands are installed on the Linux server where the scripts are executed:

  • SSH: used to establish secure connections to remote source servers.
  • sed: used to edit and modify the /etc/hosts file.
  • setsid: used to avoid interaction during SSH connections, typically to prevent prompts during password input.
  • mktemp: used to create temporary files or directories.

Configuring the Execution and User Permissions

  • Configure user permissions. Ensure that the user who executes the scripts has the read and write permissions for the log directory, CSV file, and hosts file.
  • Assign execute permission to the scripts. Ensure that the update_hosts_linux.sh and rollback_hosts_linux.sh scripts are executable. Run the chmod +x update_hosts_linux.sh and chmod +x rollback_hosts_linux.sh commands to add the execute permission to the scripts.