diff --git a/os/get-os-init.sh b/os/get-os-init.sh index ea92c8c..c48e61b 100644 --- a/os/get-os-init.sh +++ b/os/get-os-init.sh @@ -1,6 +1,6 @@ #!/usr/bin/bash -set -e +#set -e color(){ unset c declare -A c=([Error]=31 [Success]=32 [Warning]=33 [Info]=34) diff --git a/os/get-os-init9.sh b/os/get-os-init9.sh new file mode 100644 index 0000000..9bea651 --- /dev/null +++ b/os/get-os-init9.sh @@ -0,0 +1,99 @@ +#!/usr/bin/bash + +set -e +color(){ + unset c + declare -A c=([Error]=31 [Success]=32 [Warning]=33 [Info]=34) + printf "\033[${c[$1]}m%-10s%-10s %-30s\033[0m\n" "[`date +%T`]" "($1)" "$2" + sleep 0.5 +} + +static_addr(){ +ifname=$(ip -f inet a | awk '/^2/{print $2}') +ifname=$(echo ${ifname/:/}) +ipaddr=$(ip -f inet a show dev $ifname | awk '/inet/{print $2}' | awk -F'/' '{print $1}') +prefix=$(ip -f inet a show dev $ifname | awk '/inet/{print $2}' | awk -F'/' '{print $2}') +gateway=$(ip r |awk '/default/{print $3}') +cat > /etc/sysconfig/network-scripts/ifcfg-$ifname </dev/null && \ +return 10 || \ +return 20 +} + + +init(){ + # 系统信息采集 + color Info "当前用户 $USER" + color Info "当前时间 `date "+%F %X"`" + echo 3 >/proc/sys/vm/drop_caches + color Info "当前内存 $(free |awk 'NR==2{print $4/1024}')M" + color Info "当前核心 $(grep -E '^processor' /proc/cpuinfo|wc -l)个" + color Info "核心品牌 $(grep -E '^model name' /proc/cpuinfo |head -n 1 |awk -F: '{print $2}')" + color Info "启动时长 $(uptime |awk -F',' '{print $1}')" + color Success "开始配置静态ip" +cat >>/etc/security/limits.conf <> /etc/sysctl.conf + color Success "已经开启系统路由转发" + static_addr + if [ $? -eq 10 ];then + color Success "静态ip配置并检测完成" + else + color Error "静态ip配置异常" + fi + color Info "正在关闭防火墙、selinux" + color Warning "注意,这将降低服务器安全性" + systemctl disable firewalld --now + if [ `getenforce` = 'Enforcing' ];then + setenforce 0 + fi + sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config && \ + color Success "配置完成" || color Error "配置异常,请检查" + dnf install -y epel-release + dnf makecache + dnf install -y wget unzip vim yum-utils httpd-tools psacct net-tools nc jq htop bash-completion lrzsz ntpsec && \ + color Success "安装完成" || color Warning "部分包可能失败" + color Info "开始进行时间校准" + ntpdate ntp.aliyun.com && \ + # 修改时间到硬件 + clock -w + #保存时间到硬件 + hwclock -s + color Success "时间校准完成" + echo {"time": "`date +'%F %T'`"} > /tmp/.init +} +if [ -f /tmp/.init ];then + color Success "检测到此前已进行初始化,如需重新执行,请删除: rm -f /tmp/.init" + exit 0 +fi +init +color Success "初始化完成"