• bash-1 初始化CentOS系统的初始化脚本


    初始化CentOS系统的初始化脚本

    #!/bin/bash
    #
    #********************************************************************
    #Author:			kjAlbert
    #Date:				2019-10-11
    #FileName: 		sysinit.sh
    #Description:		Init CentOS Linux system
    #Copyright (C): 	2019 All rights reserved
    #********************************************************************
    #
    #检测root权限
    if [ $UID -ne 0 ];then
    	echo "没有root权限,无法执行!"
    	exit 1
    fi
    #检测version
    if [ -e /etc/redhat-release ];then
    	VER=`sed -nr 's@.* ([0-9]).*@1@p' /etc/redhat-release`
    else
    	echo '这不是redhat和centos系列的系统,请使用其他脚本!!'
    	exit 10
    fi
    bak=bak`date +%F_%T`
    #cenos6:
    case $VER in
    6)
    #firewalld
    	service iptalbes stop &>/dev/null
    	chkconfig iptables off &>/dev/null
    	echo "关闭防火墙完成"
    #selinux
    	sed -i 's@SELINUX=enforcing@SELINUX=disabled@' /etc/selinux/config &>/dev/null
    	echo "关闭SELINUX完成"
    #PS1
    	echo 'PS1="33[1;33m[u@h 	 W]$33[0m"' >>/etc/profile
    	echo "命令提示符颜色修改完成,当前颜色:黄色"
    #init 3
    	sed -i 's/(^[^#].*)[0-9](.*)/132/' /etc/inittab
    	echo "修改启动级别为3完成"
    #yum.repos
    	ping mirrors.aliyun.com -c 1 &>/dev/null
    	if [ $? -eq 0 ];then
    		mkdir -p /etc/yum.repos.d/$bak &>/dev/null
    		mv /etc/yum.repos.d/* /etc/yum.repos.d/$bak/ &>/dev/null
    		echo -e "[centos$VER]
    name=centos$VER
    baseurl=https://mirrors.aliyun.com/centos/6/os/x86_64/
    gpgcheck=0
    enabled=1
    
    [epel]
    name=aliyunEPEL
    baseurl=https://mirrors.aliyun.com/epel/6/x86_64/
    gpgcheck=0
    enabled=1" >/etc/yum.repos.d/aliyun.repo
    		echo "yum源配置完成"
    		echo "yum源列表"
    		echo -e "***************************************
    "
    		yum repolist
    		echo -e "
    ***************************************"
    	else
    		echo '网络不通,请检查网络!'
    	fi
    #autofs
    	rpm -q autofs &>/dev/null
    	if [ $? -eq 0 ];then
    		echo 1 &>/dev/null
    	else 
    		yum -y install autofs &>/dev/null
    	fi
    	service autofs start &>/dev/null
    	chkconfig autofs on &>/dev/null
    	echo "已具有自动挂载光盘功能"
    #.vimrc和.bashrc的配置
    	echo -e 'set autoindent
    set nu
    syntax on
    autocmd BufNewFile *.sh exec ":call SetTitle()"
    func SetTitle()
    if expand("%:e") == "sh"
    	 call setline(1,"#!/bin/bash") 
    	 call setline(2,"#") 
    	 call setline(3,"#********************************************************************") 
    	 call setline(4,"#Author:		kjAlbert") 
    	 call setline(5,"#Date:			".strftime("%Y-%m-%d"))
    	 call setline(6,"#FileName: 		".expand("%"))
    	 call setline(7,"#Description:		The test script") 
    	 call setline(8,"#Copyright (C): 	".strftime("%Y")." All rights reserved")
    	 call setline(9,"#********************************************************************") 
    	 call setline(10,"#") 
    	 call setline(11,"") 
    endif
    endfunc
    autocmd BufNewFile * normal G' >~/.vimrc
    	;;
    #cenos7:
    7)
    #firewalld
    	systemctl disable --now firewalld.service &>/dev/null
    	echo "关闭防火墙完成"
    #selinux
    	sed -i 's@SELINUX=enforcing@SELINUX=disabled@' /etc/selinux/config &>/dev/null
    	echo "关闭SELINUX完成"
    #PS1
    	echo 'PS1="33[1;36m[u@h 	 W]\$33[0m"' >>/etc/profile
    	echo "命令提示符颜色修改完成,当前颜色:青色"
    #init 3
    	systemctl set-default multi-user.target &>/dev/null
    	echo "修改启动级别为3完成"
    #yum.repo
    	mkdir /etc/yum.repos.d/$bak &>/dev/mull
    	mv /etc/yum.repos.d/* /etc/yum.repos.d/$bak/ &>/dev/null
    	echo -e "[centos$VER]
    name=centos$VER
    baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/
    gpgcheck=0
    enabled=1
    
    [epel]
    name=aliyunEPEL
    baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
    gpgcheck=0
    enabled=1" >/etc/yum.repos.d/aliyun.repo
    	echo "yum源配置完成"
    	echo "yum源列表"
    	echo -e "***************************************
    "
    	yum repolist
    	echo -e "
    ***************************************"
    #autofs
    	rpm -q autofs &>/dev/null
    	if [ $? -eq 0 ];then
    		echo 222 &>/dev/null
    	else 
    		yum -y install autofs &>/dev/null
    	fi
    	systemctl enable --now autofs &>/dev/null
    	echo "已具有自动挂载光盘功能"
    #network网卡改名为eth
    	grep "<net.ifnames=0>" /etc/default/grub
    	if [ $? -ne 0 ];then
    		sed -i 's@quiet@quiet net.ifnames=0@' /etc/default/grub
    		grub2-mkconfig -o /etc/grub2.cfg &>/dev/null
    		echo "网卡名称修改完成"
    	fi
    #.vimrc和.bashrc的配置
    	echo -e 'set autoindent
    set nu
    syntax on
    autocmd BufNewFile *.sh exec ":call SetTitle()"
    func SetTitle()
    if expand("%:e") == "sh"
    	 call setline(1,"#!/bin/bash") 
    	 call setline(2,"#") 
    	 call setline(3,"#********************************************************************") 
    	 call setline(4,"#Author:		kjAlbert") 
    	 call setline(5,"#Date:			".strftime("%Y-%m-%d"))
    	 call setline(6,"#FileName: 		".expand("%"))
    	 call setline(7,"#Description:		The test script") 
    	 call setline(8,"#Copyright (C): 	".strftime("%Y")." All rights reserved")
    	 call setline(9,"#********************************************************************") 
    	 call setline(10,"#") 
    	 call setline(11,"") 
    endif
    endfunc
    autocmd BufNewFile * normal G' >~/.vimrc
    	;;
    #cenos8:
    8)
    #firewalld
    	systemctl disable --now firewalld.service &>/dev/null
    	echo "关闭防火墙完成"
    #selinux
    	sed -i 's@SELINUX=enforcing@SELINUX=disabled@' /etc/selinux/config &>/dev/null
    	echo "关闭SELINUX完成"
    #PS1
    	echo 'PS1="33[1;32m[u@h 	 W]\$33[0m"' >>/etc/profile
    	echo "命令提示符颜色修改完成,当前颜色:绿色"
    #init 3
    	systemctl set-default multi-user.target &>/dev/null
    	echo "修改启动级别为3完成"
    #yum.repo
    	mkdir /etc/yum.repos.d/$bak &>/dev/null
    	mv /etc/yum.repos.d/* /etc/yum.repos.d/$bak/ &>/dev/null
    	echo -e "[centos$VER]
    name=centos$VER
    baseurl=https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/
    gpgcheck=0
    enabled=1
    
    [cenos8base]
    name=centos8Base
    baseurl=https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/
    gpgcheck=0
    enabled=1
    
    [epel]
    name=aliyunEPEL
    baseurl=https://mirrors.aliyun.com/epel/8/Everything/x86_64/
    gpgcheck=0
    enabled=1" >/etc/yum.repos.d/aliyun.repo
    	echo "yum源配置完成"
    	echo "yum源列表"
    	echo -e "***************************************
    "
    	yum repolist
    	echo -e "
    ***************************************"
    #autofs
    	rpm -q autofs &>/dev/null
    	if [ $? -eq 0 ];then
    		echo 333 &>/dev/null
    	else 
    		yum -y install autofs &>/dev/null
    	fi
    	systemctl enable --now autofs &>/dev/null
    	echo "已具有自动挂载光盘功能"
    #network网卡改名为eth
    	grep "<net.ifnames=0>" /etc/default/grub
    	if [ $? -ne 0 ];then
    		sed -i 's@quiet@quiet net.ifnames=0@' /etc/default/grub
    		grub2-mkconfig -o /etc/grub2.cfg &>/dev/null
    		echo "网卡名称修改完成"
    	fi
    #.vimrc和.bashrc的配置
    	echo -e 'set autoindent
    set nu
    syntax on
    autocmd BufNewFile *.sh exec ":call SetTitle()"
    func SetTitle()
    if expand("%:e") == "sh"
    	 call setline(1,"#!/bin/bash") 
    	 call setline(2,"#") 
    	 call setline(3,"#********************************************************************") 
    	 call setline(4,"#Author:		kjAlbert") 
    	 call setline(5,"#Date:			".strftime("%Y-%m-%d"))
    	 call setline(6,"#FileName: 		".expand("%"))
    	 call setline(7,"#Description:		The test script") 
    	 call setline(8,"#Copyright (C): 	".strftime("%Y")." All rights reserved")
    	 call setline(9,"#********************************************************************") 
    	 call setline(10,"#") 
    	 call setline(11,"") 
    endif
    endfunc
    autocmd BufNewFile * normal G' >~/.vimrc
    	;;
    *)
    	echo '垓版本开发中,敬请期待!'
    	exit 10
    	;;
    esac
    echo -e "***************************************
    "
    echo '初始化完成感谢使用!!'
    echo -e "
    ***************************************"
    #echo -n "配置完成需要重启CentOS(立即重启Y/稍后手动重启n):"
    #REBOOT=Y
    #read REBOOT
    #if [[ $REBOOT =~ [Nn][Oo]? ]];then
    #	echo "选择稍后手动重启..."
    #	exit 0
    #fi
    reboot
    

    执行方式

    将脚本放在局域网中的一台http服务器上

    curl http://xxx.xxx.xxx.xxx/sysinit.sh |bash
    

    即可执行,完成后自动重启
    关于.bashrc中环境变量,别名等内容可根据自己喜好添加

  • 相关阅读:
    SQL群集多实例卸载、安装
    Java 数组的 12 个方法
    Java 容器
    RDA 升级
    DVB条件接收系统多密技术的设计与实现
    perl数组的长度与元素个数
    TS流解析 四
    Python中操作myslq的方法
    DVB-subtitle解析流程浅
    JAVA回调机制(CallBack)详解
  • 原文地址:https://www.cnblogs.com/kjalbert/p/11673650.html
Copyright © 2020-2023  润新知