#! /bin/bash HOSTNAME=chakra IPADDR=10.205.18.133 DNS1=10.202.1.1 DNS2=10.202.1.2 DOMAIN=usm.my GATEWAY=10.205.19.254 ### centos_frontend-1of2.txt # 1a #reference: https://www.rosehosting.com/blog/how-to-configure-and-use-openssh-on-centos-7/ # enable ssh # yum -y install openssh openssh-server openssh-clients openssl-libs systemctl restart sshd.service # 1b Check the SELINUX mode. Need to set SELINUX to permissive mode. # reference: https://www.rootusers.com/how-to-enable-or-disable-selinux-in-centos-rhel-7/ getenforce ## to check the mode of SELINUX sestatus ## to check the mode of SELINUX cp /etc/sysconfig/selinux /etc/sysconfig/selinux.bk sed -i 's/SELINUX=/#SELINUX=/g' /etc/sysconfig/selinux echo 'SELINUX=permissive' >> /etc/sysconfig/selinux ## 1c Installation of some software and packages yum install -y epel-release yum -y install lshw.x86_64 install firefox yum install -y python-devel.x86_64 ##needed by lammps yum install -y seamonkey yum install -y libjpeg-turbo-devel.x86_64 yum groups mark convert yum groupinstall -y "Development Tools" yum install -y glib.x86_64 yum install -y vim yum install -y zlib-devel.x86_64 yum install -y python36 python36-devel.x86_64 python36-pip.noarch python34-pip.noarch python34-devel.x86_64 ### Install google chrome ### wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm; yum install -y libappindicator-gtk3-devel.* # libappindicator-gtk3-devel.x86_6 yum install -y liberation-fonts.noarch yum -y install redhat-lsb libXScrnSaver rpm -ivh google-chrome-stable_current_x86_64.rpm yum -y reinstall google-chrome ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # 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" in the frontend.' echo '' ls /etc/sysconfig/network-scripts/ifcfg-$nc0 ############################################################ ## 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=192.168.1.10' >> /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 ############################################################ ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # 3 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 ############################################################ ## sample of original /etc/sysconfig/network-scripts/ifcfg-$nc1 ############################################################ ##---- 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="enp0s25" ##---- UUID="70a3084d-8b06-4081-9f04-5cc2e8f4f6a7" ##---- DEVICE="enp0s25" ##---- ONBOOT="yes" ############################################################ 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 frontend.' 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/dhcp/static/g' /etc/sysconfig/network-scripts/ifcfg-$nc1 sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' /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 sed -i 's/ONBOOT=no/ONBOOT="yes"/g' /etc/sysconfig/network-scripts/ifcfg-$nc1 # append echo 'IPADDR='$IPADDR >> /etc/sysconfig/network-scripts/ifcfg-$nc1 echo 'NETMASK=255.255.255.0' >> /etc/sysconfig/network-scripts/ifcfg-$nc1 echo 'PREFIX=23' >> /etc/sysconfig/network-scripts/ifcfg-$nc1 echo 'DNS1='$DNS1 >> /etc/sysconfig/network-scripts/ifcfg-$nc1 echo 'DNS2='$DNS2 >> /etc/sysconfig/network-scripts/ifcfg-$nc1 echo 'DOMAIN="usm.my"' >> /etc/sysconfig/network-scripts/ifcfg-$nc1 echo 'NM_CONTROLLED="yes"' >> /etc/sysconfig/network-scripts/ifcfg-$nc1 echo 'GATEWAY='$GATEWAY >> /etc/sysconfig/network-scripts/ifcfg-$nc1 ############################################################ ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # 4 Configure the default gateway (the IP of the switch) and hostname in /etc/sysconfig/network file in frontend ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # 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='$HOSTNAME >> /etc/sysconfig/network echo 'GATEWAY='$GATEWAY >> /etc/sysconfig/network ############################################################ ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ## 5 Configure the DNS entry for the frontend. The DNS is defined in the /etc/resolv.conf file. ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ # A typical content of /etc/resolv.conf of a frontend looks something like ############################################################ #search local usm.my #nameserver 10.202.1.2 #nameserver 10.202.1.1 #nameserver 127.0.0.1 ############################################################ # The following code will replace the /etc/resolv.conf file of the frontend with the desired content. The original netowork file, if exist, will be saved as /etc/resolv.conf.orig. ############################################################ mv /etc/resolv.conf /etc/resolv.conf.orig touch /etc/resolv.conf echo 'search local usm.my' >> /etc/resolv.conf echo 'nameserver 127.0.0.1' >> /etc/resolv.conf echo 'nameserver '$DNS1 >> /etc/resolv.conf echo 'nameserver '$DNS2 >> /etc/resolv.conf ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ## 6 generate a rsa key for root in the frontend ##### $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ssh-keygen -t rsa #rsa key generated for su in .ssh/id_rsa.pub in the frontend reboot