分享

shell优化系统

 土心园 2018-01-19
作者: admin 分类: shell 发布时间: 2018-01-05 13:40

功能:

时间同步

关闭防火墙 selinux

更换163 yum源

安装常用工具


#!/bin/bash
#Date: 13:19 2017-12-28
#Author: create by xpp
#QQ: 610109797
#Blog: www.
#version:1.1
. /etc/init.d/functions
##################################config######################################
#date
DATE=`date +"%y-%m-%d %H:%M:%S"`
#ip
IPADDR=`grep "IPADDR" /etc/sysconfig/network-scripts/ifcfg-eth0|cut -d= -f 2 `
#hostname
HOSTNAME=`hostname -s`
#user
USER=`whoami`
#disk_check
DISK_SDA=`df -h |grep -w "/" |awk '{print $5}'`
#cpu_average_check
cpu_uptime=`cat /proc/loadavg|awk '{print $1,$2,$3}'`
##################################function#####################################
#time sync
syncSysTime(){
echo "================配置时间同步====================="
  \cp /var/spool/cron/root /var/spool/cron/root.$(date +%F) 2>/dev/null
  NTPDATE=`grep ntpdate /var/spool/cron/root 2>/dev/null |wc -l`
  if [ $NTPDATE -eq 0 ];then
    echo "#times sync by lee at $(date +%F)" >>/var/spool/cron/root
    echo "*/5 * * * * /usr/sbin/ntpdate time.windows.com >/dev/null 2>&1" >> /var/spool/cron/root
  fi
  echo '#crontab -l'  
  crontab -l
action "配置时间同步完成" /bin/true
echo "================================================="
echo ""
  sleep 2
}
sysyh(){
echo "================系统优化====================="
/etc/init.d/iptables stop #这个是关闭防火墙命令,学习环境
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.cc #修改yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum update -y
yum install tree telnet dos2unix sysstat lrzsz nc nmap -y
yum groupinstall "Development Tools"
action "系统优化完成" /bin/true
echo "================================================="
echo ""
  sleep 2
}
: '
inlamp(){
}
'
###################################menu###################################################
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
while true
do
clear
echo "========================================"
echo '         Welcome to my tools            '  
echo "========================================"
cat << EOF
|------------------------------------------|
| DATE       :$DATE               |
| Author     :xpp                          |
| QQ         :610109797                    |
| Blog       :www.            |
| version    :1.1                          |
-------------------------------------------
|********是否执行下一步优化系统*******     |
-------------------------------------------
EOF
read -p "please input: [yes/no] : " input
if [ "$input" = "yes" ];then
syncSysTime
sysyh
elif [ "$input" = "no" ];then
exit 1
else
echo 'you must input yes or no'
echo 'input ERROR'
exit 4
fi
done

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约