Linux系统优化脚本
#!/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系统优化脚本的更多相关文章
- linux centos6 系统优化脚本-经典
转载一篇Ricky的系统优化脚本,这个脚本只能针对centos6x 其他还没有测试,但centos7肯定不行的 #!/bin/bash # ID 201510192126 # Author Ricky ...
- Linux shell脚本编程(三)
Linux shell脚本编程 流程控制: 循环语句:for,while,until while循环: while CONDITION; do 循环体 done 进入条件:当CONDITION为“真” ...
- Linux shell脚本编程(二)
Linux shell脚本编程(二) 练习:求100以内所有偶数之和; 使用至少三种方法实现; 示例1: #!/bin/bash # declare -i sum=0 #声明一个变量求和,初始值为0 ...
- Linux shell脚本编程(一)
Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...
- Linux Shell 脚本入门
linux shell 脚本格式 #!/bin/sh#..... (注释)命令...命令... 使用vi 创建完成之后需设置权限 chmod +x filename.sh 执行命令: ./filena ...
- Linux Shell脚本入门--cut命令
Linux Shell脚本入门--cut命令 cut cut 命令可以从一个文本文件或者文本流中提取文本列. cut语法 [root@www ~]# cut -d'分隔字符' -f fields &l ...
- Linux Shell脚本攻略 读书笔记
Linux Shell脚本攻略 读书笔记 这是一本小书,总共253页,但内容却很丰富,书中的示例小巧而实用,对我这样总是在shell门前徘徊的人来说真是如获至宝:最有价值的当属文本处理,对这块我单独整 ...
- 阿里Linux Shell脚本面试25个经典问答
转载: 阿里Linux Shell脚本面试25个经典问答 Q:1 Shell脚本是什么.它是必需的吗? 答:一个Shell脚本是一个文本文件,包含一个或多个命令.作为系统管理员,我们经常需要使用多个命 ...
- Linux Shell脚本教程
v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...
随机推荐
- explicit的作用
用来修饰类的构造函数,被修饰的构造函数的类,不能发生相应的隐式类型转换,只能以显示的方式进行类型转换,例如:不加:Circle A = Circle(1.23) 加上之后:只能写:Circle A(1 ...
- PAT1027:Colors In Mars
1027. Colors in Mars (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People ...
- JAVA线程池shutdown和shutdownNow的区别
一.区别介绍 shutDown() 当线程池调用该方法时,线程池的状态则立刻变成SHUTDOWN状态.此时,则不能再往线程池中添加任何任务,否则将会抛出RejectedExecutionExcept ...
- 分布式服务跟踪及Spring Cloud的实现
在分布式服务架构中,需要对分布式服务进行治理——在分布式服务协同向用户提供服务时,每个请求都被哪些服务处理?在遇到问题时,在调用哪个服务上发生了问题?在分析性能时,调用各个服务都花了多长时间?哪些调用 ...
- c#Socket客户端和服务端的信息发送
这是我制作的界面信息,c# Socket通信的简单使用,刚开始学习,不对的地方请大家指教,目前是可以运行的,之后自己在慢慢添加新的东西.同时了解Tcp协议的三次握手.希望对跟我一样的初学者有所帮助. ...
- 纯CSS打造进度条
进度条效果如下: CSS部分 body { background-color: white; } .progress-bar { display: flex; flex-direction: row; ...
- Python数据库连接池DBUtils.PooledDB
DBUtils 是一套用于管理数据库连接池的包,为高频度高并发的数据库访问提供更好的性能,可以自动管理连接对象的创建和释放.最常用的两个外部接口是 PersistentDB 和 PooledDB,前者 ...
- Java Script 读书笔记 (三) 函数
1. 函数作用域 在函数内部定义的变量,外部无法读取,称为"局部变量"(local variable). 变量v在函数内部定义,所以是一个局部变量,函数之外就无法读取. 函数内部定 ...
- config.go
package blog4go import ( "encoding/xml" "errors" "io/ioutil" "os& ...
- CountDownLatch简介
CountDownLatch是并发包中提供的一个可用于控制多个线程同时开始某动作的类,可以看做是一个计数器,计数器操作是院子操作,同时只能有一个线程去操作这个计数器.可以向CountDownLatch ...