Once the instances are created, set a hostname for each node and then add an entry to /etc/hosts file so that the nodes can locate each other. You can also use DNS if it’s available in your environment.
- use hostnamectl command to set a hostname:
$ sudo su - # hostname ip-10-20-1-10.us-west-2.compute.internal # hostnamectl set-hostname node-a
- If a DNS server is available, register your hostname(s) using the server. If there is not a DNS server available, using /etc/hosts is recommended to resolve the hostnames.
# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- Add the following lines to the /etc/hosts file so that node-a and node-b can be resolved to an IP address(es).
10.20.1.10 node-a 10.20.2.10 node-b 10.20.3.10 node-c
- Create a backup of /etc/hosts, edit the file and confirm the changes.
# cp -p /etc/hosts /etc/hosts.org # vi /etc/hosts # cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost4 localhost4.localdomain4 10.20.1.10 node-a 10.20.2.10 node-b 10.20.3.10 node-c
- Make sure you can ping these nodes by name.
# ping node-b PING node-b (10.20.2.10) 56(84) bytes of data. 64 bytes from node-b (10.20.2.10): icmp_seq=1 ttl=64 time=0.868 ms 64 bytes from node-b (10.20.2.10): icmp_seq=1 ttl=64 time=0.892 ms ^C
Post your comment on this topic.