--------------------------------------------------------------------
注:如果你对python感兴趣,我这有个学习Python基地,里面有很多学习资料,感兴趣的+Q群:895817687
--------------------------------------------------------------------
--------------------- #!/bin/bash
##############################################################################
# File Name    :    Linux system config
# description   :   This script is used to set linux system
# Author         :   simon
# Mail             :   24731701@qq.com
##############################################################################
. /etc/init.d/functions
IP=`/sbin/ifconfig|awk -F '[ :]+' 'NR==2{print $4}'`# Defined result functionfunction Msg(){if [ $? -eq 0 ];thenaction "$1" /bin/trueelseaction "$1" /bin/falsefi}# Defined Close selinux Functions
function selinux(){[ if "/etc/selinux/config"  ] && {sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/configsetenforce 0Msg "Close selinux"           }
}# Defined add Ordinary users Functionsfunction AddUser(){id simon &>/dev/nullif [ $? -ne 0 ];thenuseradd simon &>/dev/nullecho "123456"|passwd --stdin simon &>/dev/null &&\sed -ir '98a simon    ALL=(ALL)    NOPASSWD:ALL' /etc/sudoers &&\visudo -c &>/dev/nullMsg "AddUser simon"elseecho "simon user is exist."fi
}# Defined Hide the system version number Functionsfunction HideVersion(){[ -f "/etc/issue" ] && >/etc/issue[ -f "/etc/issue.net"] && > /etc/issue.netMsg "Hide sys info."
}# Defined sshd config Functionsfunction sshd(){sshd_file=/etc/ssh/sshd_configif [ `grep "52113" $sshd_file|wc -l` -eq 0 ];thensed -ir "13 iPort 52113\nPermitRootLogin no\nPermitEmptyPasswords no\nUseDNS no\nGSSAPIAuthentication no" $sshd_filesed -i 's@#ListenAddress 0.0.0.0@ListenAddress '${IP}':52113@g' $sshd_file/etc/init.d/sshd restart > /dev/null 2>&1Msg "sshd config"fi
}# Defined OPEN FILES Functions
function openfiles(){if [ `grep "nofile 65535" /etc/security/limits.conf|wc -l` -eq 0 ];thenecho '*  -  nofile  65535' >> /etc/security/limits.confulimit -SHn 65535Msg "open files"fi
}function hosts(){if [ ! -f /server/scripts/hosts ];thenecho "/server/scripts/hosts is not exist,please solve this question"sleep 300exit 1fi/bin/cp /server/scripts/hosts  /etc/hosts
}# Defined System Startup Services Functionsfunction boot(){export LANG=enfor simon in `chkconfig --list|grep "3:on"|awk '{print $1}'|egrep -v "crond|network|rsyslog|sshd|sysstat"`dochkconfig $simon offdoneMsg "BOOT config"
}# Deined Time Synchronization Functions
function Time(){grep "time.nist.gov" /var/spool/cron/root > /dev/null 2>&1if [ $? -ne 0 ];thenecho "#time sync by simon at $(date +%F)" >>/var/spool/cron/rootecho "*/5 * * * * /usr/sbin/ntpdate time.nist.gov &>/dev/null" >>/var/spool/cron/rootfiMsg "Time Synchronization"}
# Defined Kernel parameters Functions
function Kernel(){/bin/cp /etc/sysctl.conf  /etc/sysctl.conf.$RANDOM/bin/cp /server/scripts/sysctl.conf /etc/Msg "kernel"}function iptables(){/etc/init.d/iptables stop/etc/init.d/iptables stopMsg "iptables"}function hostname(){ip=`/sbin/ifconfig eth1|awk -F "[: ]+" 'NR==2 {print $4}'`name=`grep -w "$ip" /etc/hosts |awk '{print $2}'`sed -i 's/HOSTNAME=*/HOSTNAME='"$name"'/g' /etc/sysconfig/network/bin/hostname  $nameMsg "hostname"}# Defined main Functions
function main(){AddUserHideVersionsshdopenfileshostsbootTimeKerneliptableshostname
}main

Linux系统优化脚本相关推荐

  1. linux系统优化脚本,linux系统优化脚本详解

    #!/bin/bash ###----1.强制限制密码长度,保证密码强壮----### vi /etc/login.defs 修改以下字段,强制限制最少的密码长度 PASS_MIN_LEN    12 ...

  2. Linux系统优化基础和系统监控

    系统优化 系统优化有其两面性,选择优化一个选项的时候,总会牺牲另一个选项的性能 优化的几个方向: 加硬件 架构 云(资源流动性)linux系统优化,调优 (微调)redhat官方文档 Red_Hat_ ...

  3. linux系统优化项目,Linux之系统优化

    查看系统版本 [root@luffy- /]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@luffy- /]# uname -m ...

  4. 学习笔记之Linux Shell脚本教程:30分钟玩转Shell脚本编程

    Linux Shell脚本教程:30分钟玩转Shell脚本编程 http://c.biancheng.net/cpp/shell/ 转载于:https://www.cnblogs.com/pegasu ...

  5. Linux shell脚本基础学习

    Linux shell脚本基础学习这里我们先来第一讲,介绍shell的语法基础,开头.注释.变量和 环境变量,向大家做一个基础的介绍,虽然不涉及具体东西,但是打好基础是以后学习轻松地前提. 1. Li ...

  6. linux 检查权限,检查目录下 文件的权限-linux shell脚本,

    检查目录下 文件的权限-linux shell脚本, #!/bin/bash #History: #2019/07/23    Fsq #This Program will check Permiss ...

  7. Linux~Sh脚本一点自己的总结

    从.netCore开源项目来看,eShopOnContainers来说,它的部署是跨平台的,可以部署在linux,docker上,在linux上运行它也可以写一些集成的小脚本,这是微信工程师为我们提供 ...

  8. 转-linux系统脚本 环境变量 的启动顺序

    linux系统脚本的常见启动顺序 由于相关变量定义不同, 所以以下启动顺序仅供参考 在Redhat Redflag centos fc linux系统里面脚本的启动 先后: 第一步:通过/boot/v ...

  9. Linux shell脚本数值计算个人心得

    Linux shell脚本数值计算个人心得 本篇博客为,个人对与bash数值计算的一些心得与用法. Bash对于数值是没有明确定义的,在shell里面所有的数值都默认为字符串,并不是单纯的数值. 比如 ...

最新文章

  1. SAP 零售商品listing不成功,补充listing的方法
  2. 「Python-Bug」错误requests.exceptions.proxyerror: httpsconnectionpool解决方法
  3. Java 8 Optional类深度解析
  4. android 表情退格,讯飞输入法Android V8.1.8212 嘘-别说话全套emoji表情上
  5. 解决win7资源监视器不能开启
  6. C/C++学习笔记: 字符串匹配Sunday算法
  7. 打开qq相册回收站一直显示服务器忙,qq照片回收站怎么打不开 手机qq回收站进不去怎么办...
  8. 4000元组装电脑配置清单2021 4000元台式电脑组装配置单
  9. Flutter 自定义TabBar指示器(indicator)实现秒杀UI样式
  10. 《OpenGL ES 3.x游戏开发(下卷)》一2.1 飘扬的旗帜
  11. CentOS Mac 安装zsh,使用oh-my-zsh
  12. Asp.NET Excel导入数据返回JSON字符
  13. 技术博客1鸿蒙系统和安卓的区别有哪些
  14. 服务器端包含SSI(Server Side Include)简介
  15. PX4飞行模式-多旋翼
  16. RXD与TXD如何连接
  17. U盘插入电脑后,有提示音,但不能显示出来,如何解决?
  18. 小程序接入流量主、banner广告、激励广告
  19. C Primer Plus 练习 P85
  20. [apk破解]百变遥控,无限积分,去除广告

热门文章

  1. LeetCode 25 K个一组翻转链表
  2. Yuhao and a Parenthesis
  3. Bookshelf 2
  4. matlab raw函数,用matlab处理Raw格式的图像文件的方法
  5. zabbix3.0 监控php,CentOS 6.8 搭建Zabbix 3.0.3监控系统
  6. JDBC批量操作批量增加批量修改
  7. 一些在线的WebEdit编辑器
  8. Java02-day02【运算符(赋值、关系、逻辑、三元、算数、自增自减)、分支语句(顺序结构、if语句)】
  9. JSP动作和内置对象
  10. 如何设计一个短URL地址系统