#! /bin/bash ## Run this script on a fresh new compute node, which should have established ssh connection to the frontend (or internet, but this is optional) ## 1 ### nfs_node.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 ### HOSTNAME=$(cat /etc/sysconfig/network | grep HOSTNAME | awk -F "=" '{print $2}') hostnamectl set-hostname $HOSTNAME #### default values. dont change ### ## 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_$HOSTNAME #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 /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/ ipaddlastnumber=$(cat /etc/sysconfig/network | grep HOSTNAME | awk -F "=" '{print $2}' | awk -F "-" '{print $3}') echo 192.168.1.$ipaddlastnumber $HOSTNAME.local $HOSTNAME c$ipaddlastnumber >> /share/cluster/hosts cat /share/cluster/hosts | uniq > temp mv temp /share/cluster/hosts # do auto exec network service restart in current noe # see https://linuxconfig.org/how-to-automatically-execute-shell-script-at-startup-boot-on-systemd-linux for How to automatically execute shell script at startup boot on systemd Linux # execute as su ## create /etc/systemd/system/network-service-restart.sh echo '#!/bin/bash' > /usr/local/bin/network-service-restart.sh echo 'service NetworkManager restart' >> /usr/local/bin/network-service-restart.sh echo 'service network restart' >> /usr/local/bin/network-service-restart.sh chmod 744 /usr/local/bin/network-service-restart.sh ## create /etc/systemd/system/service-network-restart.service cat << EOF > /etc/systemd/system/service-network-restart.service [Unit] After=mysql.service [Service] ExecStart=/usr/local/bin/network-service-restart.sh [Install] WantedBy=default.target EOF # Next, install systemd service unit and enable it so it will be executed at the boot time: chmod 664 /etc/systemd/system/service-network-restart.service systemctl daemon-reload systemctl enable service-network-restart.service #edit /etc/resolv.conf, so that it reads 'search local \ nameserver 192.168.1.10'. This line could be overwritten when setting the eth0 using NetworkManager. #### end of customize /etc/ssh in a fresh node # If you wish to test your script before you reboot, run: systemctl start service-network-restart.service service network restart ### customize the root for the present node mkdir -p /state/partition1 chmod -R 755 /state/partition1 if [[ -e $HOME/.ssh/id_rsa.pub ]]; then echo "pub rsa exists. Will not create any."; else yes '' | ssh-keygen -t rsa; fi ### if the nfs mount has been successful at this stage, the node should be able to see the shared directory /share/apps/local/bin/ sh /share/apps/local/bin/gen_bashrc.txt source ~/.bashrc ## Check if the frontend is ssh-reachable checkping=$(ping -q -c1 -W 1 192.168.1.10 | awk 'NR==4 {print $4}') if [ $checkping -eq 0 ] then echo The frontend is not responding to ping after 1 second. ssh to frontend is not yet established. fi if [ $checkping -eq 1 ] then echo $i is responding to ping within 1 second echo 'To establish passwordless ssh into frontend from current node' ssh-copy-id -i $HOME/.ssh/id_rsa.pub $USER@192.168.1.10 fi # need sshpass # yum install -y epel-release yum install -y sshpass #### customize /etc/ssh in a fresh node, so that ssh can work seamlessly # edit /etc/ssh/ssh_config, so that it reads 'GSSAPIAuthentication no' # edit /etc/ssh/sshd_config, so that it reads 'GSSAPIAuthentication no \ UseDNS no' ##### modify /etc/ssh/sshd_config cp /etc/ssh/sshd_config /etc/ssh/sshd_config.orig sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config cp /etc/ssh/ssh_config /etc/ssh/ssh_config.orig sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/ssh_config