#! /bin/bash ######## HERE HERE HERE HERE HERE HERE #################### ######## HERE HERE HERE HERE HERE HERE #################### ipaddlastnumber=21 ######## HERE HERE HERE HERE HERE HERE #################### ######## HERE HERE HERE HERE HERE HERE #################### ######## HERE HERE HERE HERE HERE HERE #################### ## Run this script on a fresh new compute node. Must specify uniquely the $ipaddlastnumber for each node. The first shall be assigned ipaddlastnumber=21, the second ipaddlastnumber=22, etc. The assignment of ipaddlastnumber must be done at this stage manually ## 1 ### centos_node-1of2.txt. ### Configuring compute nodes (NFS clients) ### reference: https://www.itzgeek.com/how-tos/linux/centos-how-tos/how-to-setup-nfs-server-on-centos-7-rhel-7-fedora-22.html #### default values. dont change ### DNS2=10.202.1.1 DNS3=10.202.1.2 HOSTNAME=compute-0-$ipaddlastnumber hostnamectl set-hostname $HOSTNAME #### default values. dont change ### #2 # Check the identities of the network cards. Select one as the 'eth0' (to guess) and then modify the corresponding /etc/sysconfig/network-scripts/ifcfg-$nc0 IPADDR=192.168.1.$ipaddlastnumber nc0=$(lshw -class network | grep -E 'Ethernet interface|logical name' | grep 'logical name' | awk '{print $3}' | awk '!/vir/' | tail -n1) echo $nc0 'is chosen as the eth0, internal network port. To modify /etc/sysconfig/network-scripts/ifcfg-"$nc0" in the frontend.' echo '' ls /etc/sysconfig/network-scripts/ifcfg-$nc0 # The following code will replace the ifcfg-$nc0 with the desired content. The original ifcfg-$nc0 will be saved as ifcfg-$nc0.orig cp /etc/sysconfig/network-scripts/ifcfg-$nc0 /etc/sysconfig/network-scripts/ifcfg-$nc0.orig ############################################################ ## sample of original /etc/sysconfig/network-scripts/ifcfg-$nc0 ############################################################ ##---- TYPE=Ethernet ##---- PROXY_METHOD=none ##---- BROWSER_ONLY=no ##---- BOOTPROTO=dhcp ##---- DEFROUTE=yes ##---- IPV4_FAILURE_FATAL=no ##---- IPV6INIT=yes ##---- IPV6_AUTOCONF=yes ##---- IPV6_DEFROUTE=yes ##---- IPV6_FAILURE_FATAL=no ##---- IPV6_ADDR_GEN_MODE=stable-privacy ##---- NAME=p6p1 ##---- UUID=263dd108-793c-4871-8d14-2ee236d4efb9 ##---- DEVICE=p6p1 ##---- ONBOOT=no ############################################################ # Apart from the last two lines HWADDR and UUID, the content in /sysconfig/network-scripts/ifcfg-$nc0 should be universal. # The following code will replace the ifcfg-$nc with the desired content. The original ifcfg-$nc0 will be saved as ifcfg-$nc0.orig cp /etc/sysconfig/network-scripts/ifcfg-$nc0 /etc/sysconfig/network-scripts/ifcfg-$nc0.orig # replacement: sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-$nc0 sed -i 's/dhcp/static/g' /etc/sysconfig/network-scripts/ifcfg-$nc0 sed -i 's/IPV6INIT="yes"/IPV6INIT="no"/g' /etc/sysconfig/network-scripts/ifcfg-$nc0 sed -i 's/DHCPCLASS=//g' /etc/sysconfig/network-scripts/ifcfg-$nc0 sed -i 's/ONBOOT=no/ONBOOT="yes"/g' /etc/sysconfig/network-scripts/ifcfg-$nc0 # append echo 'IPADDR='$IPADDR >> /etc/sysconfig/network-scripts/ifcfg-$nc0 echo 'NETMASK=255.255.0.0' >> /etc/sysconfig/network-scripts/ifcfg-$nc0 echo 'PREFIX=16' >> /etc/sysconfig/network-scripts/ifcfg-$nc0 echo 'DNS1=127.0.0.1' >> /etc/sysconfig/network-scripts/ifcfg-$nc0 echo 'DOMAIN=local' >> /etc/sysconfig/network-scripts/ifcfg-$nc0 echo 'NM_CONTROLLED="yes"' >> /etc/sysconfig/network-scripts/ifcfg-$nc0 ############################################################ ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # 4 Configure the default gateway (the IP of the switch) and hostname in /etc/sysconfig/network file in current node #### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ mv /etc/sysconfig/network /etc/sysconfig/network.orig touch /etc/sysconfig/network echo 'NETWORKING=yes' >> /etc/sysconfig/network echo 'GATEWAY=192.168.1.10' >> /etc/sysconfig/network echo 'HOSTNAME='$HOSTNAME >> /etc/sysconfig/network ## 5. Doing NFS configuration in current node # Check NFS Share # Before mounting the NFS share, check the NFS shares available on the NFS server by running the following command on the NFS client. showmount -e 192.168.1.10 # Mount the shared directory in the NFS clients (the share directory in the frontend is supposed to be /export/share mkdir /share mount 192.168.1.10:/export/share /share #Verify the mounted share on the NFS client using mount command. mount | grep nfs #Also, you can use the df -hT command to check the mounted NFS share. df -hT #Create a file on the mounted directory to verify the read and write access on NFS share. touch /share/test_$IPADDR #If the above command returns no error, you have working NFS setup # To mount the shares automatically on every reboot, you would need to modify /etc/fstab file of your NFS client. cp /etc/fstab cp /etc/fstab.orig echo '192.168.1.10:/export/share /share nfs nosuid,rw,sync,hard,intr 0 0' >> /etc/fstab ### replace /etc/hosts file by that shared in /share/cluster/hosts, then add to hosts the identify of current node mv /etc/hosts /etc/hosts.orig ln -s /share/cluster/hosts /etc/ echo 192.168.1.$IPADDR $HOSTNAME.local $HOSTNAME >> /share/cluster/hosts service network restart ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ## 6 generate passwordless ssh for $user to-and-fro the current node and the frontend ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ user=root frontend=192.168.1.10 ### generates a rsa key in the current compute node for $user ssh-keygen -t rsa ### copy the rsa key of the $user in the current compute node to the frontend ssh-copy-id -i $user/.ssh/id_rsa.pub $frontend ### remotely generates the rsa key for the $user in the frontend by ssh-ing from the current compute node. ssh $user@$frontend "ssh-keygen -t rsa" ### remotely asks the rsa key for the $user in the frontend to be copied via ssh to the current compute node. HOSTNAME=$(cat /etc/hostname) ssh $user@$frontend "ssh-copy-id -i $user/.ssh/id_rsa.pub $HOSTNAME" reboot