最小化安装Linux系统初始化脚本
目录[*]最小化安装Linux系统初始化脚本
最小化安装Linux系统初始化脚本
注:此脚本适用于centos 7/8、Ubuntu1804,具体需要根据实际情况进行测试调整。
此脚本包含的功能:
[*]允许 root 用户使用 ssh 登录
[*]关闭 selinux
[*]关闭防火墙
[*]设置 ps1
[*]设置默认编辑器为 vim
[*]自定义 vim
[*]自定义历史命令
[*]修改内核参数
[*]设置资源限制
[*]修改软件源
[*]安装常用包
[*]设置时间同步
[*]修改网卡为传统命令格式
[*]设置IP地址等
# cat init_v1.sh#!/bin/bash##**************************************************#Author: Xan_Yum#QQ: 7993167#Email: waluna@qq.com#Version: 1.0#Date: 2021-11-03#FileName: init_v1.sh#Description: system init#URL: https://blog.waluna.top#Copyroght (C): 2021 ALL rights reserved#**************************************************OS=`awk -F'"' '/PRETTY_NAME/{print $2}' /etc/os-release|tr ' ' '-'`#1set_ssh () { if [[ $OS == Ubuntu-18.04* ]];then sed -i.bak '/#PermitRootLogin/a PermitRootLogin yes' /etc/ssh/sshd_config systemctl restart sshd fi echo -e "\e];then sed -i.bak 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config fi echo -e "\e];then echo "PS1='\[\e[\u@\h \W]\\$ \[\e'" >> /etc/profile.d/env.sh . /etc/profile.d/env.sh elif [[ $OS == Ubuntu* ]];then echo 'PS1="\[\e[${debian_chroot:+($debian_chroot)}\u@\h \w]\\$ \[\e"' >> .bashrc . .bashrc fi echo -e "\e];then sed -i.bak '/^pool /c pool time1.aliyun.com iburst' /etc/chrony.conf systemctl restart chronyd && systemctl enable chronyd echo '*/5 * * * * chronyc -a makestep &> /dev/null && hwclock -w' >> /var/spool/cron/root systemctl restart crond elif [[ $OS == Ubuntu-18.04* ]];then echo '*/5 * * * * ntpdate time1.aliyun.com &> /dev/null && hwclock -w' >> /var/spool/cron/root systemctl restart cron fi echo -e "\e];then sed -i.bak '/GRUB_CMDLINE_LINUX/s#"$# net.ifnames=0"#' /etc/default/grub grub2-mkconfig -o /boot/grub2/grub.cfg &> /dev/null elif [[ $OS == Ubuntu-18.04* ]];then sed -i.bak '/GRUB_CMDLINE_LINUX/s#"$#net.ifnames=0"#' /etc/default/grub grub-mkconfig -o /boot/grub/grub.cfg &> /dev/null fi echo -e "\e];then mv /etc/netplan/01-netcfg.yaml{,.bak}cat > /etc/netplan/01-netcfg.yaml
页:
[1]