目录
一、脚本要求
二、检查本地服务器状态
1.检查系统版本
2.查看系统内核版本
三、shell脚本的注释模板配置
1.配置 ~/.vimrc
2.查看注释模板效果
四、编写 init.sh脚本
五、测试运行脚本
一、脚本要求
1.系统版本为centos7,最小化安装;
2.要求安装基本工具:vim/tree/git/wget/netstat/
3.配置好yum仓库源
4.配置好tab键补齐
5.关闭防火墙,selinux,开启包转发功能
6.git命令补全
二、检查本地服务器状态
1.检查系统版本
[root@node scripts]# cat /etc/centos-release CentOS Linux release 7.6.1810 (Core)
2.查看系统内核版本
[root@node scripts]# uname -r 3.10.0-957.el7.x86_64
三、shell脚本的注释模板配置
1.配置 ~/.vimrc
[root@node ~]# cat ~/.vimrc autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()" func SetTitle() if expand("%:e")=='sh' call setline(1,"#!/bin/bash") call setline(2,"##########################################################") call setline(3,"#File Name:".expand("%")) call setline(4,"#Version:V1.0") call setline(5,"#Aurhor:jqzheng") call setline(6,"#Emali:[email protected]") call setline(7,"#Created Time:".strftime("%F %T")) call setline(8,"#Description:") call setline(9,"##########################################################") call setline(10,"") endif endfunc
2.查看注释模板效果
#!/bin/bash ########################################################## #File Name:test.sh #Version:V1.0 #Aurhor:jqzheng #Emali:[email protected] #Created Time:2023-11-13 23:58:22 #Description: ########################################################## ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "test.sh" [New File]
四、编写 init.sh脚本
[root@node scripts]# cat init.sh #!/bin/bash ########################################################## #File Name:init.sh #Version:V1.0 #Aurhor:jqzheng #Emali:[email protected] #Created Time:2023-11-14 00:00:53 #Description: ########################################################## echo "########## 1- yum registry config ##############" curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo > /dev/null sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo > /dev/null echo "the yum registry finished!" echo "########## 2- intsall the tools ##############" yum -y install vim > /dev/null yum -y install tree > /dev/null yum -y install wget > /dev/null yum -y install bash-completion.noarch > /dev/null && yum -y install net-tools > /dev/null yum -y install git > /dev/null echo "the tools installed" echo "########## 3-Complete git command ##############" git clone https://github.com/markgandolfo/git-bash-completion.git > /dev/null cp -af git-bash-completion/git-completion.bash ~/.git-completion.bash if [ -f ~/.git-completion.bash ]; then . ~/.git-completion.bash fi echo " Complete git command finished" echo "########## 4-stop firewalld & selinux ##############" sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config setenforce 0 GET=$(getenforce) if [ $GET = Disabled ];then echo "the selinux disable" else echo "please check the selinux status" fi systemctl stop firewalld.service && systemctl disable firewalld.service > /dev/null echo " firewall disbale & stop" echo "########## 5- ip_forward ##############" sysctl -w net.ipv4.ip_forward=1 echo "All config finished"
五、测试运行脚本
[root@node scripts]# sh init.sh ########## 1- yum registry config ############## % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2523 100 2523 0 0 14546 0 --:--:-- --:--:-- --:--:-- 14583 the yum registry finished! ########## 2- intsall the tools ############## the tools installed ########## 3-Complete git command ############## fatal: destination path 'git-bash-completion' already exists and is not an empty directory. Complete git command finished ########## 4-stop firewalld & selinux ############## setenforce: SELinux is disabled the selinux disable firewall disbale & stop ########## 5- ip_forward ############## net.ipv4.ip_forward = 1 ########## 6- hostname ############## All config finished [root@node scripts]#