初始化脚本centos7andcentos8

#centos7
#!/bin/bash
host_information()
{
	EEN2="echo -e \E[1;32m"
	RED="\E[1;31m"
	GREEN="\E[1;32m"
	YELLOW="\E[1;33m"
	END1="\E[0m"
	echo -e "$RED---------------------------------HOSTINFORMASTION-----------------------------------------$END1"
	echo -e "HOSTNAME:     $GREEN    `hostname`$END1"
	echo -e "IPADDR:       $GREEN    `ip add list  | egrep -o "\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\>(\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\>){2}\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\>" | tr ‘\n‘ ‘ ‘ `$END1"
	echo -e "CPU:          $GREEN   `lscpu | grep "Model name" | tr -s ‘ ‘| cut -d: -f2 | tr ‘\n‘ ‘ ‘`$END1"
	echo -e "MEMORY:       $GREEN    `free -h | grep Mem | tr -s ‘ ‘ ‘%‘ | cut -d‘%‘ -f2`$END1"
	echo -e "DISK:         $GREEN    `lsblk | grep "^sd" |tr -s ‘ ‘ | cut -d‘ ‘ -f4 | tr ‘\n‘ ‘ ‘`$END1"
	echo -e "SYSTEM_VERSION:$GREEN   `cat  /etc/redhat-release` $END1"
	echo -e "KERNEL_VERSION:$GREEN   `uname -r` $END1"
	echo -e "$GREEN----------------------------------------------------------------------------------------$END1"
}
disable_selinux()
{
	sed -Ei.bak ‘s@(^SELINUX=)(.*)@\1disabled@‘ /etc/selinux/config 
	setenforce 0
	echo "selinux stop and disabled success"
}
disable_firewalld()
{
	systemctl disable --now  firewalld

}
write_yum_repo_centos7()
{
	cat >> /etc/yum.repo.d/local.repo <<-EOF
[local]
name=centos7
baseurl=https://mirrors.cloud.tencent.com/centos/7/os/x86_64/
gpgcheck=0
enable=1
[epel]
name=epel
baseurl=https://mirrors.cloud.tencent.com/epel/7/x86_64/
gpgcheck=0
enable=1
EOF
}
write_yum_repo_centos8()
{
    cat >> /etc/yum.repo.d/local.repo <<-EOF
[BaseOS]
name=BaseOS
baseurl=https://mirrors.cloud.tencent.com/centos/8/BaseOS/x86_64/os/
gpgcheck=1                         
                             
[AppStream]
name=AppStream
baseurl=https://mirrors.cloud.tencent.com/centos/8/AppStream/x86_64/os/
gpgcheck=0
EOF
[epel]
name=epel
baseurl=https://mirrors.cloud.tencent.com/epel/8/Everything/x86_64/
gpgcheck=0
enable=1
EOF


}



clean_repo()
{
	rm -rf  /etc/yum.repo.d/*.repo

}


change_netname(){
	sed -i.bak -E  ‘ s#(^GRUB_CMDLINE_LINUX=.*)(")#\1 net.ifnames=0 biosdevname=0 "#‘ /etc/default/grub 
	grub2-mkconfig -o /boot/grub2/grub.cfg &> /dev/null
	echo "configuration is complete,reboot to take effct"
}

vim_config(){
	cat >> .vimrc <<-eof
set ts=4
set expandtab
set ignorecase
set cursorline
set autoindent
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:		none") 
	call setline(5,"#QQ: 			none") 
	call setline(6,"#Date: 			".strftime("%Y-%m-%d"))
	call setline(7,"#FileName:		".expand("%"))
	call setline(8,"#URL: 			none")
	call setline(9,"#Description:		The  script") 
	call setline(10,"#Copyright (C): 	".strftime("%Y")." All rights reserved")
	call setline(11,"#********************************************************************") 
	call setline(12,"") 
	endif
endfunc
autocmd BufNewFile * normal G
eof
}
base_soft
{
 yum install -y  gcc make autoconf gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel  vim lrzsz tree tmux lsof tcpdump wget net-tools iotop bc bzip2 zip unzip nfs-utils man-pages bash-completion &> /dev/null && install babase-soft ok ....
}
host_information
disable_selinux
disable_firewalld
clean_repo
write_yum_repo_centos7
change_netname
vim_config
base_soft

#centos8
#!/bin/bash
host_information()
{
	EEN2="echo -e \E[1;32m"
	RED="\E[1;31m"
	GREEN="\E[1;32m"
	YELLOW="\E[1;33m"
	END1="\E[0m"
	echo -e "$RED---------------------------------HOSTINFORMASTION-----------------------------------------$END1"
	echo -e "HOSTNAME:     $GREEN    `hostname`$END1"
	echo -e "IPADDR:       $GREEN    `ip add list  | egrep -o "\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\>(\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\>){2}\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\>" | tr ‘\n‘ ‘ ‘ `$END1"
	echo -e "CPU:          $GREEN   `lscpu | grep "Model name" | tr -s ‘ ‘| cut -d: -f2 | tr ‘\n‘ ‘ ‘`$END1"
	echo -e "MEMORY:       $GREEN    `free -h | grep Mem | tr -s ‘ ‘ ‘%‘ | cut -d‘%‘ -f2`$END1"
	echo -e "DISK:         $GREEN    `lsblk | grep "^sd" |tr -s ‘ ‘ | cut -d‘ ‘ -f4 | tr ‘\n‘ ‘ ‘`$END1"
	echo -e "SYSTEM_VERSION:$GREEN   `cat  /etc/redhat-release` $END1"
	echo -e "KERNEL_VERSION:$GREEN   `uname -r` $END1"
	echo -e "$GREEN----------------------------------------------------------------------------------------$END1"
}
disable_selinux()
{
	sed -Ei.bak ‘s@(^SELINUX=)(.*)@\1disabled@‘ /etc/selinux/config 
	setenforce 0
	echo "selinux stop and disabled success"
}
disable_firewalld()
{
	systemctl disable --now  firewalld

}


write_yum_repo_centos8()
{
    cat >> /etc/yum.repo.d/local.repo <<-EOF
[BaseOS]
name=BaseOS
baseurl=https://mirrors.cloud.tencent.com/centos/8/BaseOS/x86_64/os/
gpgcheck=1                         
                             
[AppStream]
name=AppStream
baseurl=https://mirrors.cloud.tencent.com/centos/8/AppStream/x86_64/os/
gpgcheck=0
EOF
[epel]
name=epel
baseurl=https://mirrors.cloud.tencent.com/epel/8/Everything/x86_64/
gpgcheck=0
enable=1
EOF
}

clean_repo()
{
	rm -rf  /etc/yum.repo.d/*.repo

}

change_netname(){
	sed -i.bak -E  ‘ s#(^GRUB_CMDLINE_LINUX=.*)(")#\1 net.ifnames=0 biosdevname=0 "#‘ /etc/default/grub 
	grub2-mkconfig -o /boot/grub2/grub.cfg &> /dev/null
	echo "configuration is complete,reboot to take effct"
}

vim_config(){
	cat >> .vimrc <<-eof
set ts=4
set expandtab
set ignorecase
set cursorline
set autoindent
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:		none") 
	call setline(5,"#QQ: 			none") 
	call setline(6,"#Date: 			".strftime("%Y-%m-%d"))
	call setline(7,"#FileName:		".expand("%"))
	call setline(8,"#URL: 			none")
	call setline(9,"#Description:		The  script") 
	call setline(10,"#Copyright (C): 	".strftime("%Y")." All rights reserved")
	call setline(11,"#********************************************************************") 
	call setline(12,"") 
	endif
endfunc
autocmd BufNewFile * normal G
eof
}
base_soft
{
 yum install -y  gcc make autoconf gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel  vim lrzsz tree tmux lsof tcpdump wget net-tools iotop bc bzip2 zip unzip nfs-utils man-pages bash-completion &> /dev/null && install babase-soft ok ....
}
host_information
disable_selinux
disable_firewalld
clean_repo
write_yum_repo_centos8
change_netname
vim_config
base_soft











初始化脚本centos7andcentos8

上一篇:大日志文件查看方式


下一篇:【前端常用小脚本】下拉框的值发生改变时打开对应的页面