#! /bin/bash # Run this script on a freshly installed compute-node to establish intranet connection to the frontend via eth0-switch, as well as to the internet via eth1 (if eth1 is present) echo 'Enter ipaddlastnumber for current node manually.' echo 'The values of $ipaddlastnumber should be assigned systematically. Each node should has a unqie $ipaddlastnumber value, begins from the positive integer $ipaddlastnumber=21.' echo 'For example, when installing the first node, set ipaddlastnumber=21. When installing the second node, set ipaddlastnumber=22, etc.' echo 'The node will reboot after you have entered $ipaddlastnumber.' echo ' ' read -p "Enter ipaddlastnumber for current node: " ipaddlastnumber ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # 1 configure "eth1" ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # Check the identities of the network cards. Select one as the 'eth1' (to guess) and then modify the corresponding /etc/sysconfig/network-scripts/ifcfg-$nc1 nc1=$(lshw -class network | grep -E 'Ethernet interface|logical name' | grep 'logical name' | awk '{print $3}' | awk '!/vir/' | awk 'NR==1{print}') echo $nc1 'is chosen as the eth1, external network port. To modify /etc/sysconfig/network-scripts/ifcfg-"$nc1" in the node.' echo ' ' ls /etc/sysconfig/network-scripts/ifcfg-$nc1 # The following code will replace the ifcfg-$nc1 with the desired content. The original ifcfg-$nc1 will be saved as ifcfg-$nc1.orig. cp /etc/sysconfig/network-scripts/ifcfg-$nc1 /etc/sysconfig/network-scripts/ifcfg-$nc1.orig # replacement: sed -i 's/static/dhcp/g' /etc/sysconfig/network-scripts/ifcfg-$nc1 sed -i 's/BOOTPROTO=static/BOOTPROTO=dhcp/g' /etc/sysconfig/network-scripts/ifcfg-$nc1 sed -i 's/ONBOOT=no/ONBOOT="yes"/g' /etc/sysconfig/network-scripts/ifcfg-$nc1 echo 'NM_CONTROLLED="yes"' >> /etc/sysconfig/network-scripts/ifcfg-$nc1 #sed -i 's/IPV6INIT="yes"/IPV6INIT="no"/g' /etc/sysconfig/network-scripts/ifcfg-$nc1 #sed -i 's/DHCPCLASS=//g' /etc/sysconfig/network-scripts/ifcfg-$nc1 ############################################################ ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # 2 configure "eth0" ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # Check the identities of the network cards. Select one as the 'eth0' (to guess) and then modify the corresponding /etc/sysconfig/network-scripts/ifcfg-$nc 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-"$nc".' ls /etc/sysconfig/network-scripts/ifcfg-$nc0 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=192.168.1.$ipaddlastnumber >> /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=192.168.1.10' >> /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 ############################################################ ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # 3 Configure the default gateway (the IP of the switch) and hostname in /etc/sysconfig/network file in the node ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # The following code will replace the /etc/sysconfig/network file with the desired content. The original netowork file will be saved as network.orig mv /etc/sysconfig/network /etc/sysconfig/network.orig touch /etc/sysconfig/network echo 'NETWORKING=yes' >> /etc/sysconfig/network echo 'HOSTNAME='compute-0-$ipaddlastnumber >> /etc/sysconfig/network echo 'GATEWAY='192.168.1.10 >> /etc/sysconfig/network ############################################################ ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ## 4 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 # If you wish to test your script before you reboot run: systemctl start service-network-restart.service ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ reboot