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 本系列一共三篇,看完记住,那水平就不一样 ...
随机推荐
- 在Myeclipse中没有部署jeesite项目,但是每次运行其他项目时,还是会加载jeesite项目
解决办法: 一.在以下路径中找到jeesite文件,并删除 1.Tomcat 7.0\conf\Catalina\localhost 2.Tomcat 7.0\webapps 3.Tomcat 7.0 ...
- 用jquery实现Ping测试网络连接性
jquery的ping插件://要用的需要明白代码及自己改些地方 (function($) { $.fn.ping = function(options) { var opts = ...
- Modbus教程| Modbus协议,ASCII和RTU帧,Modbus工作
转载自:https://www.rfwireless-world.com/Tutorials/Modbus-Protocol-tutorial.html 这个Modbus教程涵盖了modbus协议基础 ...
- Codeforces Round #453 (Div. 1) 901C C. Bipartite Segments
题 http://codeforces.com/contest/901/problem/C codeforces 901C 解 首先因为图中没有偶数长度的环,所以: 1.图中的环长度全是奇数,也就是说 ...
- list深拷贝和浅拷贝
在Python中,经常要对一个list进行复制.对于复制,自然的就有深拷贝与浅拷贝问题.深拷贝与浅拷贝的区别在于,当从原本的list复制出的list之后,修改其中的任意一个是否会对另一个造成影响,即这 ...
- Linux下更换为阿里yum源
更新日期: 2018-08-06 1.yum源的工作原理 yum是为了解决安装包的依赖关系而生的,如果要源码安装一个软件,需要频繁下载各个包,并解决包的依赖关系.这就好比学门课程,要学会这门课程,就要 ...
- Selenium报错:StaleElementReferenceException
一个学生在操作页面跳转时遇到一个Selenium报错, 如下图所示: StaleElementReferenceException: Message: stale element reference: ...
- umei-spider
umei-spider 1 #!/usr/bin/python3 2 3 import requests 4 from bs4 import BeautifulSoup 5 from contextl ...
- Python3 Address already in use 解决方法
1.查看使用端口号netstat -ntlp 2.根据端口号找到pid 3.杀死程序 kill -9 pid 4.重新启动程序 简单粗暴 我使用python3时编写Socket,linux系统下使用c ...
- OpenDayLight安装Features
OpenDayLight 0.4.4-Beryllium-SR4 opendaylight-user@root>feature:install odl-restconf opendaylight ...