1
centos7一键优化脚本
652
10页
7次
墨值10
#!/bin/bash
#########################################################
#copyright by hwb --2019/7/23 #
#mobile 18825144300 #
#实现功能:一键系统优化 15 项脚本,适用于 Centos7.x #
#########################################################
#Source function library.
. /etc/init.d/functions
#date
DATE=`date +"%y-%m-%d %H:%M:%S"`
#ip
IPADDR=`ifconfig | grep "inet" | grep -vE 'inet6|127.0.0.1'|awk '{print $2}'`
#hostname
HOSTNAME=`hostname -s`
#user
USER=`whoami`
#disk_check (grep -w 用于字符串精确匹配)
DISK_SDA=`df -h |grep -w "/" |awk '{print $5}'`
#cpu_average_check
cpu_uptime=`cat /proc/loadavg|awk '{print $1,$2,$3}'`
#set LANG
export LANG=zh_CN.UTF-8
#Require root to run this script.
uid=`id | cut -d\( -f1 | cut -d= -f2`
if [ $uid -ne 0 ];then
action "Please run this script as root." /bin/false
exit 1
fi
#"stty erase ^H" 设置 backspace 为删除键
\cp /root/.bash_profile /root/.bash_profile_$(date +%F)
erase=`grep -wx "stty erase ^H" /root/.bash_profile |wc -l`
if [ $erase -lt 1 ];then
echo "stty erase ^H" >>/root/.bash_profile
source /root/.bash_profile
fi
#Config Yum CentOS-Bases.repo and save Yum file
configYum(){
echo "================更新为阿里 YUM =================="
for i in /etc/yum.repos.d/*.repo;do cp $i ${i%.repo}.bak;done
rm -rf /etc/yum.repos.d/*.repo
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo
>/dev/null 2>&1
#ping -c 1 mirrors.aliyun.com >/dev/null
#if [ $? -eq 0 ];then
# rm -rf /etc/yum.repos.d/*.repo
# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo
>/dev/null 2>&1
#else
# echo "本服务器无法连接网络。"
# exit $?
#fi
echo "================保存 YUM 源文件===================="
sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf
grep keepcache /etc/yum.conf
yum clean all;yum makecache;yum repolist
sleep 5
action "配置国内 YUM 完成" /bin/true
echo "================================================="
echo ""
sleep 2
}
#Charset zh_CN.UTF-8
initI18n(){
echo "================更改为中文字符集================="
\cp /etc/locale.conf /etc/locale.conf.$(date +%F)
cat >>/etc/locale.conf<<EOF
LANG="zh_CN.UTF-8"
#LANG="en_US.UTF-8"
EOF
source /etc/locale.conf
grep LANG /etc/locale.conf
action "更改字符集 zh_CN.UTF-8 完成" /bin/true
echo "================================================="
echo ""
sleep 2
}
#Close Selinux and Iptables
initFirewall(){
echo "============禁用 SELINUX 及关闭防火墙=============="
\cp /etc/selinux/config /etc/selinux/config.$(date +%F)
systemctl stop firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
systemctl status firewalld
echo '#grep SELINUX=disabled /etc/selinux/config '
grep SELINUX=disabled /etc/selinux/config
echo '#getenforce '
getenforce
action "禁用 selinux 及关闭防火墙完成" /bin/true
echo "================================================="
echo ""
sleep 2
}
#Init Auto Startup Service
initService(){
echo "===============精简开机自启动===================="
export LANG="en_US.UTF-8"
for A in `systemctl list-unit-files | grep enable|awk '{print $1}'`;do
systemctl $A off;done
for B in auditd.service crond.service irqbalance.service kdump.service
microcode.service rsyslog.service sshd.service sysstat.service \
systemd-readahead-collect.service multi-user.target remote-fs.target
runlevel2.target NetworkManager.service ;do systemctl enable $B;done
echo '+--------which services on---------+'
systemctl list-unit-files | grep enable
echo '+----------------------------------+'
export LANG="zh_CN.UTF-8"
action "精简开机自启动完成" /bin/true
echo "================================================="
echo ""
sleep 2
}
of 10
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜
近期活动
全部
暂无活动,敬请期待...
相关课程
全部