CentOS7 reset脚本,用于初始化新的虚拟机
生活随笔
收集整理的這篇文章主要介紹了
CentOS7 reset脚本,用于初始化新的虚拟机
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
能用,有待完善
CentOS7測試
哈哈
#!/bin/bash #************************************************************** #Author: 28 #QQ: 599503252 #Date: 2019-08-01 #FileName: reset.sh #URL: https://blog.51cto.com/14012942 #Description: The test script #Copyright (C): 2019 Copyright ? 站點(diǎn)名稱 版權(quán)所有 #************************************************************ #set -e RED="\033[0;31m" GREEN="\033[0;32m" NO_COLOR="\033[0m"# 修改別名 modify_alias() { cat >> ~/.bashrc <<EOF alias cdnet='cd /etc/sysconfig/network-scripts/' alias editnet='vim /etc/sysconfig/network-scripts/ifcfg-ens33' alias rm='rm -i' alias scandisk="echo ' - - - ' > /sys/class/scsi_host/host0/scan;echo ' - - - ' > /sys/class/scsi_host/host1/scan;echo ' - - - ' > /sys/class/scsi_host/host2/scan" EOF }# 修改命令提示符 modify_PS1() {echo 'PS1="\[\e[1;34m\][\u@\h \W]\\$\[\e[0m\] "' >> /etc/profile.d/env.sh }# 安裝基本軟件 install_software() {yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree screen lsof tcpdump wget ntpdate net-tools iotop bc zip unzip nfs-utils -y }# 替換yum源 replace_yum() {#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repocurl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.reposed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repocurl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repoyum makecache }# vim # vimrc復(fù)制過來 modify_vimrc() { cat > ~/.vimrc <<EOF set ignorecase set cursorline set autoindent set ai autocmd BufNewFile *.sh exec ":call SetTitle()"func SetTitle()if expand("%:e") == 'sh'call setline(1,"#!/bin/bash")call setline(2,"#**************************************************************")call setline(3,"#Author: Linus")call setline(4,"#QQ: 599503252")call setline(5,"#Date: ".strftime("%Y-%m-%d"))call setline(6,"#FileName: ".expand("%"))call setline(7,"#URL: https://blog.51cto.com/14012942")call setline(8,"#Description: Initialize the new server") call setline(9,"#Copyright (C): ".strftime("%Y")." Copyright ? 站點(diǎn)名稱 版權(quán)所有")call setline(10,"#************************************************************")call setline(11,"")endif endfunc autocmd BufNewFile * normal G EOF }# 關(guān)閉selinux和firewalld iptables_selinux_stop() {sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/configsetenforce 0systemctl stop firewalldsystemctl disable firewalld }# 判斷是不是root judge_root() {[ $(id -u) != "0" ] && { echo -e "${RED}Error:${NO_COLOR} You must be root to run this script."; exit 1; } }# 判斷是不是CentOS7 Check_release() {if [ -f /etc/redhat-release ];thenrelease="centos"version=`sed -r 's/.* ([0-9]+)\..*/\1/' /etc/redhat-release`if [ "$version" = "7" ];thenecho "Current release: CentOS7."else {echo -e "[${RED}Error${NO_COLOR}] This script can only be running on CentOS7."exit 1}fielse {echo -e "[${RED}Error${NO_COLOR}] This script can only be running on CentOS7."exit 1}fi }########################時(shí)區(qū)調(diào)整######################## timezone_adjust(){ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime }#修改網(wǎng)卡為eth0 modify_eth_card() {ip a | grep -q eth0if [ "$?" -eq 1 ];thensed -ri '/^GRUB_CMDLINE/s/(.*)"/\1 net.ifnames=0"/' /etc/default/grubgrub2-mkconfig -o /boot/grub2/grub.cfgfi }#自動補(bǔ)全 bash-completion() {yum install bash-completion -ysource /usr/share/bash-completion/bash_completion }main() {judge_rootCheck_releasereplace_yuminstall_softwareiptables_selinux_stopmodify_aliasmodify_vimrctimezone_adjustmodify_PS1modify_eth_cardbash_completion }main轉(zhuǎn)載于:https://www.cnblogs.com/uscWIFI/p/11322562.html
總結(jié)
以上是生活随笔為你收集整理的CentOS7 reset脚本,用于初始化新的虚拟机的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: llinux 调整swap方法
- 下一篇: 排序算法之——选择排序