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="\033[1;33m[\u@\h \t \W]\$\033[0m"' >>/etc/profile
echo "命令提示符颜色修改完成,当前颜色:黄色"
#init 3
sed -i 's/\(^[^#].*\)[0-9]\(.*\)/\13\2/' /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]\nname=centos$VER\nbaseurl=https://mirrors.aliyun.com/centos/6/os/x86_64/\ngpgcheck=0\nenabled=1\n\n[epel]\nname=aliyunEPEL\nbaseurl=https://mirrors.aliyun.com/epel/6/x86_64/\ngpgcheck=0\nenabled=1" >/etc/yum.repos.d/aliyun.repo
echo "yum源配置完成"
echo "yum源列表"
echo -e "***************************************\n"
yum repolist
echo -e "\n***************************************"
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="\033[1;36m[\u@\h \t \W]\\$\033[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]\nname=centos$VER\nbaseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/\ngpgcheck=0\nenabled=1\n\n[epel]\nname=aliyunEPEL\nbaseurl=https://mirrors.aliyun.com/epel/7/x86_64/\ngpgcheck=0\nenabled=1" >/etc/yum.repos.d/aliyun.repo
echo "yum源配置完成"
echo "yum源列表"
echo -e "***************************************\n"
yum repolist
echo -e "\n***************************************"
#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="\033[1;32m[\u@\h \t \W]\\$\033[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]\nname=centos$VER\nbaseurl=https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/\ngpgcheck=0\nenabled=1\n\n[cenos8base]\nname=centos8Base\nbaseurl=https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/\ngpgcheck=0\nenabled=1\n\n[epel]\nname=aliyunEPEL\nbaseurl=https://mirrors.aliyun.com/epel/8/Everything/x86_64/\ngpgcheck=0\nenabled=1" >/etc/yum.repos.d/aliyun.repo
echo "yum源配置完成"
echo "yum源列表"
echo -e "***************************************\n"
yum repolist
echo -e "\n***************************************"
#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 "***************************************\n"
echo '初始化完成感谢使用!!'
echo -e "\n***************************************"
#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中环境变量,别名等内容可根据自己喜好添加
bash-1 初始化CentOS系统的初始化脚本的更多相关文章
- centos系统将shell脚本改成systemctl启动的形式
说明: CentOS 7的服务systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之分,像需要开机不登陆就能运行的程序,就将程序存在系统服务里,即 ...
- Ubuntu 系统服务器初始化配置、安全加固、内核优化和常用软件安装的Shell脚本分享
转载自:https://www.bilibili.com/read/cv13875402?spm_id_from=333.999.0.0 描述: 适用于企业内部 Ubuntu 操作服务器初始化.系统安 ...
- CentOS7 系统服务器初始化配置、安全加固、内核升级优化常用软件安装的Shell脚本分享
转载自:https://www.bilibili.com/read/cv13875630?spm_id_from=333.999.0.0 描述: 适用于企业内部 CentOS7 系列操作服务器初始化. ...
- centos系统初始化流程及实现系统裁剪
Linux系统的初始化流程: POST:ROM+RAM BIOS: Boot Sequence MBR: 446:bootloader 64: 分区表 2: 5A kernel文件:基本磁盘分区 /s ...
- centos 系统初始化
centos 系统初始化 #!/bin/bash # author cfwl create date of 2012-10-21 # blog http://cfwlxf.blog.51cto.com ...
- linux基础-第十单元 系统的初始化和服务
第十单元 系统的初始化和服务 Linux系统引导的顺序 Linux系统引导的顺序 BOIS的初始化和引导加载程序 什么是BIOS GRUB程序和grub.conf文件 什么是grub grub配置文件 ...
- 浅析 Linux 初始化 init 系统,第 1 部分: sysvinit 第 2 部分: UpStart 第 3 部分: Systemd
浅析 Linux 初始化 init 系统,第 1 部分: sysvinit 第 2 部分: UpStart 第 3 部分: Systemd http://www.ibm.com/developerw ...
- saltstack 初始化LINUX系统
前面我们已经了解了saltstack的基础功能,现在就可以使用saltstack为初始化新安装的linux系统. 初始化列表: 1.关闭selinux 3.修改sshd配置文件 4.内核优化 5.ul ...
- 温故之--Linux 初始化 init 系统
参选URL: http://www.ibm.com/developerworks/cn/linux/1407_liuming_init1/index.html 本系列一共三篇,看完记住,那水平就不一样 ...
随机推荐
- Cloneable注解使用
使用 clone()方法的类必须 implement Cloneable 如果没有继承,clone()方法会报错 java.lang.CloneNotSupportedException异常
- 【CF1218E】Product Tuples
题目大意:给定一个长度为 \(N\) 的序列,求从序列中选出 \(K\) 个数的集合乘积之和是多少. 题解: 由于是选出 \(K\) 个数字组成的集合,可知对于要计算的 \(K\) 元组来说是没有标号 ...
- SparkStreaming使用checkpoint存在的问题及解决方案
sparkstreaming关于偏移量的管理 在 Direct DStream初始化的时候,需要指定一个包含每个topic的每个分区的offset用于让Direct DStream从指定位置读取数据. ...
- laravel常用响应操作
- ueditor上粘贴从word中copy的图片和文字
图片的复制无非有两种方法,一种是图片直接上传到服务器,另外一种转换成二进制流的base64码目前限chrome浏览器使用首先以um-editor的二进制流保存为例:打开umeditor.js,找到UM ...
- Selenium常见异常分析及解决方案
pycharm中导入selenium报错 现象: pycharm中输入from selenium import webdriver, selenium标红 原因1: pycharm使用的虚拟环境中没有 ...
- node和npm版本引起的安装依赖和运行项目失败问题
问题:node版本不同导致的安装依赖版本不同而无法启动 https://www.jianshu.com/p/c07293c8c6d4 实际上问题分为两个部分: 1,npm包管理器安装依赖不成功,此时需 ...
- JavaScript设计模式—适配器模式
适配器模式介绍 旧接口格式和使用者不兼容,中间加一个适配器转换接口 在生活中,我们有许多的适配器,例如iPhone7以后的耳机接口从3.5mm圆孔接口更改成为了苹果专属的 lightning接口.许多 ...
- 1.7 JAVA异常总结
1.7 JAVA异常总结 异常有的是因为用户错误引起,有的是程序错误引起的,还有其它一些是因为物理错误引起的. 三种异常:分别为检查性异常(一般异常).运行时异常(非检查性异常).错误 Throwab ...
- 发布mybatis-generator-core 1.3.5的中文注释版
源码剖析介绍:基于mybatis-generator-core 1.3.5项目的修订版以及源码剖析 目前,我把该项目,发布到了Maven中央仓库中,可直接使用: 使用方式 在项目.pom中,添加以下部 ...