1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| #!/bin/bash
rocky_reset () { swapoff -a sed -i '/swap/d' /etc/fstab
setenforce 0 sed -i '/^SELINUX=/s/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \ -i.bak \ /etc/yum.repos.d/[Rr]ocky-*.repo yum -y install epel-release yum -y install sshpass autofs bash-completion psmisc lrzsz tree \ man-pages redhat-lsb-core zip unzip bzip2 wget tcpdump ftp \ rsync vim lsof gcc make gcc-c++ glibc glibc-devel pcre pcre-devel\ openssl openssl-devel systemd-devel zlib-devel tmux tcpdump \ net-tools iotop bc nfs-utils httpd-tools chrony postfix mailx
sed -ri 's/^(pool.*)/#\1/g' /etc/chrony.conf sed -i '4iserver ntp.aliyun.com iburst' /etc/chrony.conf
systemctl enable --now postfix systemctl enable --now autofs systemctl restart chronyd systemctl enable chronyd systemctl disable --now firewalld } ssh_key () { PASS=000000 END=254 IP=`ifconfig ens160 | awk 'NR==2{print $2}' ` NET=`echo $IP | awk -v FS="." -v OFS="." '{print $1,$2,$3}'`.
. /etc/os-release
rm -f /root/.ssh/id_rsa [ -e ./SCANIP.log ] && rm -f SCANIP.log
for((i=3;i<="$END";i++));do ping -c 1 -w 1 ${NET}$i &> /dev/null && echo "${NET}$i" >> SCANIP.log & done wait ssh-keygen -P "" -f /root/.ssh/id_rsa
if [[ $ID =~ centos|rocky|rhel ]];then rpm -q sshpass || yum -y install sshpass else dpkg -i sshpass &> /dev/null ||{ apt update; apt -y install sshpass; } fi
sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no $IP AliveIP=(`cat SCANIP.log`) for n in ${AliveIP[*]};do sshpass -p $PASS scp -o StrictHostKeyChecking=no -r /root/.ssh root@${n}: done
for n in ${AliveIP[*]};do scp /root/.ssh/known_hosts ${n}:.ssh/ done
} rocky_reset ssh_key
|