CentOS7 reset脚本,用于初始化新的虚拟机
能用,有待完善
CentOS7测试
哈哈
#!/bin/bash
#**************************************************************
#Author: 9527
#QQ: 5ssssssss
#Date: 2019-08-01
#FileName: reset.sh
#URL: https://cnblogs.com
#Description: The test script
#Copyright (C): 2019 Copyright © 站点名称 版权所有
#************************************************************
#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.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -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.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
}
# vim
# vimrc复制过来
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 © 站点名称 版权所有")
call setline(10,"#************************************************************")
call setline(11,"")
endif
endfunc
autocmd BufNewFile * normal G
EOF
}
# 关闭selinux和firewalld
iptables_selinux_stop() {
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
systemctl stop firewalld
systemctl 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 ];then
release="centos"
version=`sed -r 's/.* ([0-9]+)\..*/\1/' /etc/redhat-release`
if [ "$version" = "7" ];then
echo "Current release: CentOS7."
else {
echo -e "[${RED}Error${NO_COLOR}] This script can only be running on CentOS7."
exit 1
}
fi
else {
echo -e "[${RED}Error${NO_COLOR}] This script can only be running on CentOS7."
exit 1
}
fi
}
########################时区调整########################
timezone_adjust(){
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
}
#修改网卡为eth0
modify_eth_card() {
ip a | grep -q eth0
if [ "$?" -eq 1 ];then
sed -ri '/^GRUB_CMDLINE/s/(.*)"/\1 net.ifnames=0"/' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
fi
}
#自动补全
bash-completion() {
yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
}
main() {
judge_root
Check_release
replace_yum
install_software
iptables_selinux_stop
modify_alias
modify_vimrc
timezone_adjust
modify_PS1
modify_eth_card
bash_completion
}
main
CentOS7 reset脚本,用于初始化新的虚拟机的更多相关文章
- 在VMware 虚拟机中配置 windows2003系统的NLB负载均衡;0x800706D5错误的解决方法;没有接口可用于安装新的群集
首先在VM里面 我装了3个2003的系统, 分别为 webservice01 ,webservice 02 , 以及 webview 这3台. 前面两台用于配置负载均衡,后面的webview就是 ...
- Centos7 搭建KVM并创建Linux Windows虚拟机
一.安装KVM 查看系统版本 cat /etc/redhat-release 关闭防火墙及selinux systemctl disable firewalld.service 查看防 ...
- 如何将 MFC ActiveX 控件标记为安全,脚本和初始化
MSDN原文.ActiveX控件标记安全(可以不仅仅是MFC ActiveX) 概要 默认情况下,MFC ActiveX 控件未标记为对脚本编写是安全的和对初始化是安全的.控制运行在 Internet ...
- VMware12创建新的虚拟机及设置硬件环境
一.安装VMware虚拟机 http://jingyan.baidu.com/article/215817f78879c21edb142379.html?qq-pf-to=pcqq.group 二.创 ...
- CentOS7系统安装及环境初始化
操作系统安装: 将网卡名称设置为eth*,不使用CentOS 7默认的网卡命名规则.所以需要在安装的时候,增加内核参数.1. 光标选择“Install CentOS 7” 2. 点击Tab,打开 ...
- VMware 如何通过现有虚拟机克隆新的虚拟机 (图文)
本文做的是克隆主机,并重命名主机名,做好主机名与IP的对应关系,并可以通过主机名访问对方的主机. 首先说一下克隆虚拟机的作用 克隆虚拟机的作用 因工作需要,需要用到多个虚拟机环境时,再新建几个比较麻烦 ...
- Centos7.3 搭建KVM 命令安装VM虚拟机
操作系统:centos7.3 一.安装KVM 1. 验证CPU是否支持KVM:如果结果中有vmx(Intel)或svm(AMD)字样,就说明CPU的支持的. egrep '(vmx|svm)' ...
- Oracle VM VirtualBox(一) 快速拷贝一个新的虚拟机
快速拷贝一个新的虚拟机 一 找到虚拟机vdi文件,复制一份并重命名. 二 修改新虚拟机的UUID 注:不修改创建不了虚拟机,会抛出Oracle VM VirtualBox UUID already e ...
- Centos7 启动脚本
Centos7 启动脚本 启动脚本.如果进程已存在,输出错误信息后退出: #! /bin/bash PIDS=`ps -ef | grep '/usr/bin/node ./index.js' | g ...
随机推荐
- Failure to transfer org.springframework:spring-jcl:jar:5.0.7.RELEASE from
错误信息: Failure to transfer org.springframework.boot:spring-boot-maven-plugin:pom:1.5.4.RELEASE from h ...
- session与cookie,django中间件
0819自我总结 一.session与cookie 1.django设置session request.session['name'] = username request.session['age' ...
- 【RT-Thread】线程的基本知识
什么是线程? 人们在生活中处理复杂问题时,惯用的方法就是分而治之,即把一个大问题分解成多个相对简单.比较容易解决的小问题,小问题逐个被解决了,大问题也就随之解决了.同样,在设计一个较为复杂的应用程序时 ...
- 浅谈Mysql索引
文章原创于公众号:程序猿周先森.本平台不定时更新,喜欢我的文章,欢迎关注我的微信公众号. 我们都知道,数据库索引可以帮助我们更加快速的找出符合的数据,但是如果不使用索引,Mysql则会从第一条开始查询 ...
- JVM 中发生内存溢出的 8 种原因及解决办法
1. Java 堆空间 2. GC 开销超过限制 3. 请求的数组大小超过虚拟机限制 4. Perm gen 空间 5. Metaspace 6. 无法新建本机线程 7. 杀死进程或子进程 8. 发生 ...
- Github 高级搜索功能
参考文章链接:https://zhuanlan.zhihu.com/p/55294261 GitHub 提供高级搜索方式. 一.明确搜索仓库标题.仓库描述.README 1.只想查找仓库名称包含XX的 ...
- 移动端前端常见的触摸相关事件touch、tap、swipe
前端的很多事件在PC端和浏览器端可公用,但有些事件却只在移动端产生,如触摸相关的事件 本文整理了移动端常见的一些事件,包括原生支持的click.touch.tap.swipe事件,也有定义型的gest ...
- python中函数定义与调用顺序问题
def main(): try: mtd(3) except Exception as e: print("程序出现异常:", e) mtd(3) def mtd(a): if a ...
- 05jmeter-responses中有多组json数据,提取同一条json数据的两个字段
某接口返回结果如上图,取id和groupNo 1.读取确定的某条json数据:如取第一条,一个JSON Extractor即可实现 2.随机读取某条json数据: 需要两个JSON Extractor ...
- Mysql分表的一个考虑
今天看到一篇博客,讲述的是Mysql的分表方案,内容比较简单,不过有个思路倒是挺好的,记录下,后续分表可以参考 作者主要是说到两种分表,一个是取模,另一个是范围分表 取模:比如用户ID%10,分10张 ...