#!/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. 转)ZooKeeper的实现分析

    最近在大量看关于Zookeeper的博客,发现一篇讲解ZK实现很详细的博客,特此转载一下: 原博客地址: http://my.oschina.net/zhengyang841117/blog/1866 ...

  2. spring cloud中利用sidecar整合异构语言(转)

    用spring cloud sidecar的整合异构语言,以前做过没有做笔记,现在再做由于各种坑又浪费了一天,这里记一下 首先是官网:http://cloud.spring.io/spring-clo ...

  3. Windows下配置 Nginx + PHP

    背景 经常倒腾系统,徘徊于 Windows 的便利和 Linux 的魔性,一旦折腾系统基本配置都要重弄,特此记录对 Nginx和PHP的基本启动.重启和退出 网上经验 网上这种东西一搜一大把,也有很多 ...

  4. JS中清空字符串前后空格

    在JS 操作的时候 长期会有对字符串的操作, 但是在JS 中不像在C#中 有字符串的方法 Trim() 来对字符串进行处理 .  所以自己写一个对字符串前后清楚空格的方法还是有必要的 以免以后忘记了 ...

  5. 最简单易懂的SpringCloudSleuth教程

    事务mapjvm 大佬对下面的说法是否同意呢 能否比较下zipkin,pinpoint,以及skywalking.该如何选型 回答: 他们都提供了分布式服务跟踪的能力,pinpoint以及skywal ...

  6. Nginx+Tomcat搭建高性能负载均衡集群

    一.       工具   nginx-1.8.0 apache-tomcat-6.0.33 二.    目标   实现高性能负载均衡的Tomcat集群: 三.    步骤   1.首先下载Nginx ...

  7. ScalaPB(5):用akka-stream实现reactive-gRPC

      在前面几篇讨论里我们介绍了scala-gRPC的基本功能和使用方法,我们基本确定了选择gRPC作为一种有效的内部系统集成工具,主要因为下面gRPC支持的几种服务模式: .Unary-Call:独立 ...

  8. CentOS6.5 安装Python2.7后, yum出现“No module named yum”错误

    安装如下方法安装python2.7: yum install –y python27 python27-devel python-docutils cd /usr/bin/ rm -rf python ...

  9. 底层网络技术以及IP编址

    网络信息的传输在最底层总是依托于物理介质来进行传输的,这里的传输介质分为两种: 有线介质  导线管(导向媒体).例如:双绞线.同轴电缆.光纤等 无线介质  电磁波(非导向媒体):利用各种波长的电磁波充 ...

  10. tomcat设置端口号,访问指定ip就访问指定项目

    1.修改背景: A.通常我们访问我们的web应用格式为: http://ip:端口号/项目名称 例如: http://127.0.0.1:8080/projectName B.如果想直接输入" ...