初始化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系统的初始化脚本的更多相关文章

  1. centos系统将shell脚本改成systemctl启动的形式

    说明: CentOS 7的服务systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之分,像需要开机不登陆就能运行的程序,就将程序存在系统服务里,即 ...

  2. Ubuntu 系统服务器初始化配置、安全加固、内核优化和常用软件安装的Shell脚本分享

    转载自:https://www.bilibili.com/read/cv13875402?spm_id_from=333.999.0.0 描述: 适用于企业内部 Ubuntu 操作服务器初始化.系统安 ...

  3. CentOS7 系统服务器初始化配置、安全加固、内核升级优化常用软件安装的Shell脚本分享

    转载自:https://www.bilibili.com/read/cv13875630?spm_id_from=333.999.0.0 描述: 适用于企业内部 CentOS7 系列操作服务器初始化. ...

  4. centos系统初始化流程及实现系统裁剪

    Linux系统的初始化流程: POST:ROM+RAM BIOS: Boot Sequence MBR: 446:bootloader 64: 分区表 2: 5A kernel文件:基本磁盘分区 /s ...

  5. centos 系统初始化

    centos 系统初始化 #!/bin/bash # author cfwl create date of 2012-10-21 # blog http://cfwlxf.blog.51cto.com ...

  6. linux基础-第十单元 系统的初始化和服务

    第十单元 系统的初始化和服务 Linux系统引导的顺序 Linux系统引导的顺序 BOIS的初始化和引导加载程序 什么是BIOS GRUB程序和grub.conf文件 什么是grub grub配置文件 ...

  7. 浅析 Linux 初始化 init 系统,第 1 部分: sysvinit 第 2 部分: UpStart 第 3 部分: Systemd

    浅析 Linux 初始化 init 系统,第 1 部分: sysvinit  第 2 部分: UpStart 第 3 部分: Systemd http://www.ibm.com/developerw ...

  8. saltstack 初始化LINUX系统

    前面我们已经了解了saltstack的基础功能,现在就可以使用saltstack为初始化新安装的linux系统. 初始化列表: 1.关闭selinux 3.修改sshd配置文件 4.内核优化 5.ul ...

  9. 温故之--Linux 初始化 init 系统

    参选URL: http://www.ibm.com/developerworks/cn/linux/1407_liuming_init1/index.html 本系列一共三篇,看完记住,那水平就不一样 ...

随机推荐

  1. mpvue打小程序预览码

    喂,快给我打一个小程序预览码 前端大全 昨天 (点击上方公众号,可快速关注) 来源:写Bug segmentfault.com/a/1190000015336845 需求 开发小程序的朋友们随时都会听 ...

  2. Hbuilder 开发微信小程序的代码高亮

    一.点击“工具”-“选项”-搜索“文件关联” 二.点击“添加”文件类型,点击确定 三.在相关联的编辑器中点击“添加”按钮,选择CSS Editor,点击确定,重新打开 *.wxss 类型的文件即可 其 ...

  3. 【转载】SELENIUM2支持无界面操作(HTMLUNIT和PHANTOMJS)

    SELENIUM2支持无界面操作(HTMLUNIT和PHANTOMJS) selenium2支持通过各种driver(FirfoxDriver,IternetExplorerDriver,OperaD ...

  4. Java实现一行一行读取文件内容(进行编码处理)

    // 读取文件内容public String readFile(){ String path = ""; File file = new File(path); StringBui ...

  5. 洛谷P1363 幻想迷宫【dfs】

    题目:https://www.luogu.org/problemnew/show/P1363 题意: 有一个地图,起点是S,障碍物用#表示.可以将这个地图不断的在四周重复,问从起点开始是否可以走到无限 ...

  6. Codeforces Round #588 (Div. 2) E. Kamil and Making a Stream(DFS)

    链接: https://codeforces.com/contest/1230/problem/E 题意: Kamil likes streaming the competitive programm ...

  7. @Autowired @Primary @Qualifier

    1 2 3 4 5

  8. 【luoguP1991】 无线通讯网--最小生成树

    题目描述 国防部计划用无线网络连接若干个边防哨所.2 种不同的通讯技术用来搭建无线网络: 每个边防哨所都要配备无线电收发器:有一些哨所还可以增配卫星电话. 任意两个配备了一条卫星电话线路的哨所(两边都 ...

  9. 【线性代数】3-6:四个子空间的维度(Dimensions of the Four Subspaces)

    title: [线性代数]3-6:四个子空间的维度(Dimensions of the Four Subspaces) categories: Mathematic Linear Algebra ke ...

  10. 【CUDA 基础】5.3 减少全局内存访问

    title: [CUDA 基础]5.3 减少全局内存访问 categories: - CUDA - Freshman tags: - 共享内存 - 归约 toc: true date: 2018-06 ...