#!/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 function function Msg(){
if [ $? -eq 0 ];then
action "$1" /bin/true
else
action "$1" /bin/false
fi } # Defined Close selinux Functions
function selinux(){
[ if "/etc/selinux/config" ] && {
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
setenforce 0
Msg "Close selinux"
}
} # Defined add Ordinary users Functions function AddUser(){
id simon &>/dev/null
if [ $? -ne 0 ];then
useradd simon &>/dev/null
echo "123456"|passwd --stdin simon &>/dev/null &&\
sed -ir '98a simon ALL=(ALL) NOPASSWD:ALL' /etc/sudoers &&\
visudo -c &>/dev/null
Msg "AddUser simon"
else
echo "simon user is exist."
fi
} # Defined Hide the system version number Functions function HideVersion(){
[ -f "/etc/issue" ] && >/etc/issue
[ -f "/etc/issue.net"] && > /etc/issue.net
Msg "Hide sys info."
} # Defined sshd config Functions function sshd(){
sshd_file=/etc/ssh/sshd_config
if [ `grep "52113" $sshd_file|wc -l` -eq 0 ];then
sed -ir "13 iPort 52113\nPermitRootLogin no\nPermitEmptyPasswords no\nUseDNS no\nGSSAPIAuthentication no" $sshd_file
sed -i 's@#ListenAddress 0.0.0.0@ListenAddress '${IP}':52113@g' $sshd_file
/etc/init.d/sshd restart > /dev/null 2>&1
Msg "sshd config"
fi
} # Defined OPEN FILES Functions
function openfiles(){
if [ `grep "nofile 65535" /etc/security/limits.conf|wc -l` -eq 0 ];then
echo '* - nofile 65535' >> /etc/security/limits.conf
ulimit -SHn 65535
Msg "open files"
fi
} function hosts(){
if [ ! -f /server/scripts/hosts ];then
echo "/server/scripts/hosts is not exist,please solve this question"
sleep 300
exit 1 fi
/bin/cp /server/scripts/hosts /etc/hosts
} # Defined System Startup Services Functions function boot(){
export LANG=en
for simon in `chkconfig --list|grep "3:on"|awk '{print $1}'|egrep -v "crond|network|rsyslog|sshd|sysstat"`
do
chkconfig $simon off
done
Msg "BOOT config"
} # Deined Time Synchronization Functions
function Time(){
grep "time.nist.gov" /var/spool/cron/root > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "#time sync by simon at $(date +%F)" >>/var/spool/cron/root
echo "*/5 * * * * /usr/sbin/ntpdate time.nist.gov &>/dev/null" >>/var/spool/cron/root
fi
Msg "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 stop
Msg "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 $name
Msg "hostname" } # Defined main Functions
function main(){
AddUser
HideVersion
sshd
openfiles
hosts
boot
Time
Kernel
iptables
hostname
} main

  

Linux系统优化脚本的更多相关文章

  1. linux centos6 系统优化脚本-经典

    转载一篇Ricky的系统优化脚本,这个脚本只能针对centos6x 其他还没有测试,但centos7肯定不行的 #!/bin/bash # ID 201510192126 # Author Ricky ...

  2. Linux shell脚本编程(三)

    Linux shell脚本编程 流程控制: 循环语句:for,while,until while循环: while CONDITION; do 循环体 done 进入条件:当CONDITION为“真” ...

  3. Linux shell脚本编程(二)

    Linux shell脚本编程(二) 练习:求100以内所有偶数之和; 使用至少三种方法实现; 示例1: #!/bin/bash # declare -i sum=0 #声明一个变量求和,初始值为0 ...

  4. Linux shell脚本编程(一)

    Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...

  5. Linux Shell 脚本入门

    linux shell 脚本格式 #!/bin/sh#..... (注释)命令...命令... 使用vi 创建完成之后需设置权限 chmod +x filename.sh 执行命令: ./filena ...

  6. Linux Shell脚本入门--cut命令

    Linux Shell脚本入门--cut命令 cut cut 命令可以从一个文本文件或者文本流中提取文本列. cut语法 [root@www ~]# cut -d'分隔字符' -f fields &l ...

  7. Linux Shell脚本攻略 读书笔记

    Linux Shell脚本攻略 读书笔记 这是一本小书,总共253页,但内容却很丰富,书中的示例小巧而实用,对我这样总是在shell门前徘徊的人来说真是如获至宝:最有价值的当属文本处理,对这块我单独整 ...

  8. 阿里Linux Shell脚本面试25个经典问答

    转载: 阿里Linux Shell脚本面试25个经典问答 Q:1 Shell脚本是什么.它是必需的吗? 答:一个Shell脚本是一个文本文件,包含一个或多个命令.作为系统管理员,我们经常需要使用多个命 ...

  9. Linux Shell脚本教程

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

随机推荐

  1. 微信小游戏开发之四:使用three.js引擎

    一.前言 微信小游戏中最魔性的'跳一跳'就是基于three.js 引擎开发的 源码放到github上了:GitHub地址   请自行下载. 二.下载 three.min.js 打开页面,复制代码到本地 ...

  2. SQL语句的CRUD

    一.基础 .说明:创建数据库 CREATE DATABASE database-name .说明:删除数据库 drop database dbname .说明:备份sql server --- 创建 ...

  3. echart css样式弄了几个月了,样式一直都没有好好解决,好激动

    legend 图例,每个图表最多仅有一个图例.try this » 名称 默认值 描述 {string} orient 'horizontal' 布局方式,默认为水平布局,可选为:'horizonta ...

  4. 安装Twisted

    Python看到网络编程,讲到Twisted这个强大的网络框架,很有兴趣,配合 官方文档,打算研究一哈,但是一开始就碰壁了. 安装的时候 pip install Twisted报错了: 提示没有装什么 ...

  5. Tar专题

    下面的脚本根据当前的系统时间生成压缩文件名,并备份文件到指定目录: DIR=/www/webbackup/web/ FILE_NAME=`date +%y%m%d%H` FILE_NAME=$DIR/ ...

  6. Ueditor 专题

    https://github.com/xwjie/SpringBootUeditor 提交表单提交表单设置按照部署编辑器的教程,完成编辑器加载 把容器放到form表单里面,设置好要提交的路径,如下面代 ...

  7. 浅谈服务间通信【MQ在分布式系统中的使用场景】

    解决的问题 一项技术的产生必然是为了解决问题而生,了解了一项技术解决的问题,就能够很轻松的理解这项技术的设计根本,从而更好地理解与使用这项技术. 消息中间件和RPC从根本上来说都是为了解决分布式系统的 ...

  8. 你不知道的JavaScript--Item29 DOM基础详解

    看完JavaScript高级程序设计,整理了一下里面的DOM这一块的知识点,比较多,比较碎!DOM在整个页面的地位如图: DOM(文档对象模型)是针对HTML 和XML 文档的一个API(应用程序编程 ...

  9. 【转】linux系统中如何进入退出vim编辑器,方法及区别

    在linux家族中,vim编辑器是系统自带的文本编辑器,其功能强大自不必说了. 偶有小白,刚接触linux,要修改某个文本文件,不可能像WINDOWS那样操作,更有甚者,进入VI编辑器后,无法退出以致 ...

  10. 8. 使用ueditor添加文章

    ueditor是一个很好用的html编辑器,不仅提供了格式化编辑文本的功能,还提供了自动上传图片的功能,现在就使用该编辑器来实现博客文章的编辑功能.1. 使用ueditor过程中会请求一个后台js文件 ...