中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

CentOS7 reset腳本,用于初始化新的虛擬機

發布時間:2020-06-06 23:08:57 來源:網絡 閱讀:579 作者:lkjwer 欄目:系統運維

能用,有待完善
CentOS7測試

哈哈

reset2.0.sh(20190906)
#!/bin/bash
#**
#Author: 28
#QQ: ×××
#Date: 2019-08-01
#FileName: reset.sh
#URL: https://blog.51cto.com/14012942
#Description: The test script
#Copyright (C): 2019 Copyright ? 站點名稱 版權所有
#****
#set -e
RED="\033[0;31m"
GREEN="\033[0;32m"
NO_COLOR="\033[0m"

修改別名

modify_alias() {
cat >> ~/.bashrc <<EOF
alias cdnet='cd /etc/sysconfig/network-scripts/'
alias editnet='vim /etc/sysconfig/network-scripts/ifcfg-ens33'
alias rm='rm -i'
alias scandisk="echo ' - - - ' > /sys/class/scsi_host/host0/scan;echo ' - - - ' > /sys/class/scsi_host/host1/scan;echo ' - - - ' > /sys/class/scsi_host/host2/scan"
EOF
}

修改命令提示符

modify_PS1() {
echo 'PS1="[\e[1;34m][\u@\h \W]\$[\e[0m] "' >> /etc/profile.d/env.sh
}

安裝基本軟件

install_software() {
yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree screen lsof tcpdump wget ntpdate net-tools iotop bc zip unzip nfs-utils -y
}

替換yum源

replace_yum() {
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
}

vim

vimrc復制過來

modify_vimrc() {
cat > ~/.vimrc <<EOF
set ignorecase
set cursorline
set autoindent
set ai
autocmd BufNewFile *.sh exec ":call SetTitle()"

func SetTitle()
if expand("%:e") == 'sh'
call setline(1,"#!/bin/bash")
call setline(2,"#**")
call setline(3,"#Author: Linus")
call setline(4,"#QQ: ×××")
call setline(5,"#Date: ".strftime("%Y-%m-%d"))
call setline(6,"#FileName: ".expand("%"))
call setline(7,"#URL: https://blog.51cto.com/14012942")
call setline(8,"#Description: Initialize the new server")
call setline(9,"#Copyright (C): ".strftime("%Y")." Copyright ? 站點名稱 版權所有")
call setline(10,"#****")
call setline(11,"")
endif
endfunc
autocmd BufNewFile * normal G
EOF
}

關閉selinux和firewalld

iptables_selinux_stop() {
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

systemctl stop firewalld
systemctl disable firewalld

}

判斷是不是root

judge_root() {
[ $(id -u) != "0" ] && { echo -e "${RED}Error:${NO_COLOR} You must be root to run this script."; exit 1; }
}

判斷是不是CentOS7

Check_release() {
if [ -f /etc/redhat-release ];then
release="centos"
version=sed -r 's/.* ([0-9]+)\..*/\1/' /etc/redhat-release
if [ "$version" = "7" ];then
echo "Current release: CentOS7."
else {
echo -e "[${RED}Error${NO_COLOR}] This script can only be running on CentOS7."
exit 1
}
fi
else {
echo -e "[${RED}Error${NO_COLOR}] This script can only be running on CentOS7."
exit 1
}
fi
}

########################時區調整########################
timezone_adjust(){
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
}

#修改網卡為eth0
modify_eth_card() {
ip a | grep -q eth0
if [ "$?" -eq 1 ];then
sed -ri '/^GRUB_CMDLINE/s/(.*)"/\1 net.ifnames=0"/' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
fi
}

#自動補全
bash_completion() {
yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
}

#時間同步
time_sync(){
yum install chrony -y
sed '/^server/s/^/#/' /etc/chrony.conf -i
sed '1a server ntp.aliyun.com iburst' /etc/chrony.conf -i
sed '1a server 0.cn.pool.ntp.org iburst' /etc/chrony.conf -i
sed '1a server ntp1.aliyun.com iburst' /etc/chrony.conf -i
systemctl restart chronyd
systemctl enable chronyd

echo '/30 * /usr/sbin/ntpdate ntp.aliyun.com &>/dev/null' >> /var/spool/cron/root

}

#ssh調優
ssh_adjust(){
cp /etc/ssh/sshd_config{,_bak}
sed '/^GSSAPIAuthentication/d' /etc/ssh/sshd_config -i
sed '/^UseDNS/d' /etc/ssh/sshd_config -i
echo "GSSAPIAuthentication no" >> /etc/ssh/sshd_config
echo "UseDNS no" >> /etc/ssh/sshd_config
systemctl restart sshd
}

#最大文件打開數
limits_tune(){
echo '

  • soft nofile 128000
  • hard nofile 256000

root soft nofile 128000
root hard nofile 256000
' >> /etc/security/limits.conf
}

main() {
judge_root
Check_release
replace_yum
install_software
iptables_selinux_stop
modify_alias
modify_vimrc
timezone_adjust
time_sync
limits_tune
ssh_adjust
modify_PS1
modify_eth_card
bash_completion
}

main
reset1.0.sh(20190808)
#!/bin/bash
#**
#Author: 28
#QQ: ×××
#Date: 2019-08-01
#FileName: reset.sh
#URL: https://blog.51cto.com/14012942
#Description: The test script
#Copyright (C): 2019 Copyright ? 站點名稱 版權所有
#****
#set -e
RED="\033[0;31m"
GREEN="\033[0;32m"
NO_COLOR="\033[0m"

修改別名

modify_alias() {
cat >> ~/.bashrc <<EOF
alias cdnet='cd /etc/sysconfig/network-scripts/'
alias editnet='vim /etc/sysconfig/network-scripts/ifcfg-ens33'
alias rm='rm -i'
alias scandisk="echo ' - - - ' > /sys/class/scsi_host/host0/scan;echo ' - - - ' > /sys/class/scsi_host/host1/scan;echo ' - - - ' > /sys/class/scsi_host/host2/scan"
EOF
}

修改命令提示符

modify_PS1() {
echo 'PS1="[\e[1;34m][\u@\h \W]\$[\e[0m] "' >> /etc/profile.d/env.sh
}

安裝基本軟件

install_software() {
yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree screen lsof tcpdump wget ntpdate net-tools iotop bc zip unzip nfs-utils -y
}

替換yum源

replace_yum() {
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
}

vim

vimrc復制過來

modify_vimrc() {
cat > ~/.vimrc <<EOF
set ignorecase
set cursorline
set autoindent
set ai
autocmd BufNewFile *.sh exec ":call SetTitle()"

func SetTitle()
if expand("%:e") == 'sh'
call setline(1,"#!/bin/bash")
call setline(2,"#**")
call setline(3,"#Author: Linus")
call setline(4,"#QQ: ×××")
call setline(5,"#Date: ".strftime("%Y-%m-%d"))
call setline(6,"#FileName: ".expand("%"))
call setline(7,"#URL: https://blog.51cto.com/14012942")
call setline(8,"#Description: Initialize the new server")
call setline(9,"#Copyright (C): ".strftime("%Y")." Copyright ? 站點名稱 版權所有")
call setline(10,"#****")
call setline(11,"")
endif
endfunc
autocmd BufNewFile * normal G
EOF
}

關閉selinux和firewalld

iptables_selinux_stop() {
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

systemctl stop firewalld
systemctl disable firewalld

}

判斷是不是root

judge_root() {
[ $(id -u) != "0" ] && { echo -e "${RED}Error:${NO_COLOR} You must be root to run this script."; exit 1; }
}

判斷是不是CentOS7

Check_release() {
if [ -f /etc/redhat-release ];then
release="centos"
version=sed -r 's/.* ([0-9]+)\..*/\1/' /etc/redhat-release
if [ "$version" = "7" ];then
echo "Current release: CentOS7."
else {
echo -e "[${RED}Error${NO_COLOR}] This script can only be running on CentOS7."
exit 1
}
fi
else {
echo -e "[${RED}Error${NO_COLOR}] This script can only be running on CentOS7."
exit 1
}
fi
}

########################時區調整########################
timezone_adjust(){
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
}

#修改網卡為eth0
modify_eth_card() {
ip a | grep -q eth0
if [ "$?" -eq 1 ];then
sed -ri '/^GRUB_CMDLINE/s/(.*)"/\1 net.ifnames=0"/' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
fi
}

#自動補全
bash_completion() {
yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
}

main() {
judge_root
Check_release
replace_yum
install_software
iptables_selinux_stop
modify_alias
modify_vimrc
timezone_adjust
modify_PS1
modify_eth_card
bash_completion
}

main

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

刚察县| 库尔勒市| 土默特左旗| 六枝特区| 合山市| 滨海县| 三门县| 台北县| 长泰县| 太保市| 临江市| 洛川县| 鸡泽县| 闽侯县| 阳山县| 田林县| 基隆市| 海林市| 信阳市| 双桥区| 南漳县| 乐陵市| 泰州市| 永定县| 大洼县| 武清区| 富宁县| 沈丘县| 循化| 黎城县| 吕梁市| 左权县| 姚安县| 洞头县| 湟源县| 绩溪县| 清河县| 浮梁县| 泽库县| 利辛县| 万源市|