Smartkit安装Ubuntu OS系统后,执行脚本批量配置网络和更新软件
#!/bin/bash #--------------------- # system init config #--------------------- # enable root login sed -i.bak '31 a\PermitRootLogin yes' /etc/ssh/sshd_config /etc/init.d/ssh restart # enable offline huaweicloud sources.list cat>/etc/apt/sources.list<<EOF deb http://168.7.10.14/mirror/repo.huaweicloud.com/ubuntu-ports/ focal main restricted deb http://168.7.10.14/mirror/repo.huaweicloud.com/ubuntu-ports/ focal-updates main restricted deb http://168.7.10.14/mirror/repo.huaweicloud.com/ubuntu-ports/ focal universe deb http://168.7.10.14/mirror/repo.huaweicloud.com/ubuntu-ports/ focal-updates universe deb http://168.7.10.14/mirror/repo.huaweicloud.com/ubuntu-ports/ focal multiverse deb http://168.7.10.14/mirror/repo.huaweicloud.com/ubuntu-ports/ focal-updates multiverse deb http://168.7.10.14/mirror/repo.huaweicloud.com/ubuntu-ports/ focal-backports main restricted universe multiverse deb http://168.7.10.14/mirror/repo.huaweicloud.com/ubuntu-ports/ focal-security main restricted deb http://168.7.10.14/mirror/repo.huaweicloud.com/ubuntu-ports/ focal-security universe deb http://168.7.10.14/mirror/repo.huaweicloud.com/ubuntu-ports/ focal-security multiverse EOF cat>/root/iplist.csv<<EOF #SN..................ctl_nic....ctl_ip...ctl_vlan...bondname...nic01_name..nic02_name..bond_mode...bond_ip...gw_ip...dns_ip 2102312PRN10L1000352,enp133s0,168.31.0.14/24,10,bond4,enp131s0,enp132s0,802.3ad,168.17.0.2/24,168.17.0.1,127.0.0.1,0 2102312PRN10L1000361,enp133s0,168.31.0.15/24,10,bond4,enp131s0,enp132s0,802.3ad,168.17.0.3/24,168.17.0.1,127.0.0.1,0 2102312PRN10L1000358,enp133s0,168.31.0.16/24,10,bond4,enp131s0,enp132s0,802.3ad,168.17.0.4/24,168.17.0.1,127.0.0.1,0 2102312PRN10L1000357,enp133s0,168.31.0.17/24,10,bond4,enp131s0,enp132s0,802.3ad,168.17.0.5/24,168.17.0.1,127.0.0.1,0 2102312PRN10L1000354,enp133s0,168.31.0.18/24,10,bond4,enp131s0,enp132s0,802.3ad,168.17.0.6/24,168.17.0.1,127.0.0.1,0 EOF sleep 3 sn=$(dmidecode -t system|grep -i serial|awk '{print $3}') ips=$(cat /root/iplist.csv|grep -i $sn) ctl_nic=$(echo $ips|awk -F"," '{print $2}') ctl_ip=$(echo $ips|awk -F"," '{print $3}') ctl_vlan=$(echo $ips|awk -F"," '{print $4}') bondname=$(echo $ips| awk -F"," '{print $5}') nic01_name=$(echo $ips|awk -F "," '{print $6}') nic02_name=$(echo $ips|awk -F "," '{print $7}') bond_mode=$(echo $ips| awk -F"," '{print $8}') bond_ip=$(echo $ips|awk -F "," '{print $9}') gw_ip=$(echo $ips|awk -F "," '{print $10}') dns_ip=$(echo $ips|awk -F "," '{print $11}') #--------------------------------------------------------- rm -rf /etc/netplan/*.yaml cat>/etc/netplan/$bondname.yaml<<EOF network: ethernets: $nic01_name: addresses: [] dhcp4: true dhcp6: true $nic02_name: addresses: [] dhcp4: true dhcp6: true bonds: $bondname: addresses: [ $bond_ip ] gateway4: $gw_ip nameservers: addresses: [ $dns_ip ] interfaces: - $nic01_name - $nic02_name parameters: lacp-rate: fast mode: $bond_mode transmit-hash-policy: layer2 EOF cat>/etc/netplan/mgmt-storage.yaml<<EOF network: version: 2 ethernets: $ctl_nic: dhcp4: no vlans: ${ctl_nic}.vlan${ctl_vlan}: id: $ctl_vlan link: ${ctl_nic} addresses: ["${ctl_ip}"] nameservers: addresses: [ 8.8.8.8,127.0.0.1 ] EOF netplan apply # config hostname mapping cat>/etc/hosts<<EOF 168.17.0.2 master01 168.17.0.3 master02 168.17.0.4 agent01 168.17.0.5 agent02 168.17.0.6 agent03 EOF cat>/root/init.sh<<EOF cat>>/etc/security/limits.conf<<EOFB * soft memlock unlimited * hard memlock unlimited * soft stack unlimited * hard stack unlimited * soft nofile 1000000 * hard nofile 1000000 * hard nproc 1000000 * soft nproc 1000000 EOFB EOF # DonauScheduler User and group groupadd -g 60001 donau_guest useradd -g 60001 -m -u 60001 -s /bin/bash donau_guest echo "donau_guest:huawei@123" | chpasswd groupadd -g 60002 ccs_master useradd -g 60002 -m -u 60002 -s /bin/bash ccs_master echo "ccs_master:huawei@123" | chpasswd groupadd -g 60003 ccs_agent useradd -g 60003 -m -u 60003 -s /bin/bash ccs_agent echo "ccs_agent:huawei@123" | chpasswd groupadd -g 60004 ccs_auth useradd -g 60004 -m -u 60004 -s /bin/bash ccs_auth echo "ccs_auth:huawei@123" | chpasswd groupadd -g 60005 ccs_ignite useradd -g 60005 -m -u 60005 -s /bin/bash ccs_ignite echo "ccs_ignite:huawei@123" | chpasswd groupadd -g 60006 ccs_cli useradd -g 60006 -m -u 60006 -s /bin/bash ccs_cli echo "ccs_cli:huawei@123" | chpasswd groupadd -g 60007 postgres useradd -g 60007 -m -u 60007 -s /bin/bash postgres echo "postgres:huawei@123" | chpasswd groupadd -g 60008 ccs_etcd useradd -g 60008 -m -u 60008 -s /bin/bash ccs_etcd echo "ccs_etcd:huawei@123" | chpasswd # DonauPortal User and group groupadd -g 60009 ccp_sysadmin useradd -g 60009 -m -u 60009 -s /bin/bash ccp_sysadmin echo "ccp_sysadmin:huawei@123" | chpasswd groupadd -g 60010 ccp_audadmin useradd -g 60010 -m -u 60010 -s /bin/bash ccp_audadmin echo "ccp_audadmin:huawei@123" | chpasswd groupadd -g 60013 ccp_secadmin useradd -g 60013 -m -u 60013 -s /bin/bash ccp_secadmin echo "ccp_secadmin:huawei@123" | chpasswd useradd -g 60002 -m -u 60011 -s /bin/bash ccp_master echo "ccp_master:huawei@123" | chpasswd share_dir=workspace mkdir -p /${share_dir}/donau chown root:root /${share_dir}/donau chmod 755 /${share_dir}/donau -R mkdir -p /${share_dir}/license chown ccs_master:ccs_master /${share_dir}/license chmod 770 /${share_dir}/license -R mkdir -p /${share_dir}/data chown ccs_master:ccs_master /${share_dir}/data chmod 750 /${share_dir}/data -R mkdir -p /${share_dir}/dataupload chown ccp_master:root /${share_dir}/dataupload chmod 700 /${share_dir}/dataupload -R mkdir -p /${share_dir}/jobdata chown root:root /${share_dir}/jobdata chmod 755 /${share_dir}/jobdata -R mkdir -p /${share_dir}/portal_data chown root:root /${share_dir}/portal_data chmod 755 /${share_dir}/portal_data -R mkdir -p /${share_dir}/scheduler_db chown root:root /${share_dir}/scheduler_db chmod 755 /${share_dir}/scheduler_db -R mkdir -p /${share_dir}/portal_db chown root:root /${share_dir}/portal_db chmod 755 /${share_dir}/portal_db -R mkdir -p /${share_dir}/backup chown root:root /${share_dir}/backup chmod 755 /${share_dir}/backup -R mkdir -p /${share_dir}/scheduler_agent chown root:root /${share_dir}/scheduler_agent chmod 755 /${share_dir}/scheduler_agent -R mkdir -p /${share_dir}/storage chown ccp_master:root /${share_dir}/storage chmod 755 /${share_dir}/storage -R mkdir -p /${share_dir}/mpi chown root:root /${share_dir}/mpi chmod 755 /${share_dir}/mpi -R mkdir -p /opt/donau/1.2.1/ chmod 755 /opt/donau/1.2.1 /etc/init.d/ssh restart #--------------------------------------------------- date >> /root/file apt clean || echo starting_clean>>/root/file apt -y update || echo starting_update>>/root/file date >> /root/file apt-mark hold linux-image-4.15.0-112-generic || echo "update kernel">>/root/file apt-mark hold linux-headers-4.15.0-112-generic || echo "update kernel">>/root/file apt-mark hold linux-image-generic linux-headers-generic || echo "update kernel generic" >>/root/file apt-mark hold linux-headers-generic || echo "update kernel generic" >>/root/file DEBIAN_FRONTEND=noninteractive apt -y upgrade || echo upgradeFaild >>/root/file echo huawei >> /root/file #---------------------------------------------------