一键优化系统脚本 for centos6.x

#!/bin/bash

#set env

export LANG="en_US.UTF-8"

export PATH=$PATH:/bin/sbin:/usr/sbin

#whether root to running user

if [[ $(whoami) != root ]];then

echo "please su - root run the script."

fi

SERVICE=`which service`

CHKCONFIG=`which chkconfig`

. /etc/init.d/functions

#install packages

installTmout(){

echo "TMOUT 180" >> /etc/profile\

[ $? -eq 0 ] && action "TMOUT is ok" /bin/true || exit 1

}

installTool(){

yum -y install sysstat ntp net-snmp vmstat lrzsz rsync > /dev/vull 2>&1

[ $? -eq 0 ] && action "Tools is ok" /bin/true || exit 1

}

#update the system lang

initI18n(){

cat /etc/sysconfig/i18n > /etc/sysconfig/i18n.bak

echo "LANG="en_US.UTF-8"" >> /etc/sysconfig/i18n

source /etc/sysconfig/i18n

[ $? -eq 0 ] && action "LANG is ok" /bin/true || exit 1

sleep 1

}

#start iptables

initIptables(){

cat /etc/selinux/config > /etc/selinux/config.bak

setenforce 0

sleep 1

}

#close not need to service

initService(){

export LANG="en_US.UTF-8"

for i in `chkconfig --list | grep -i "3:on" | awk ‘{print $1}‘`;do chkconfig --level 3 $i off; done

for i in crond network rsyslog sshd;do chkconfig --level 3 $i on;done

[ $? -eq 0 ] && action "Service is ok" /bin/true || exit 1

sleep 1

}

#youhua for ssh

initSsh(){

cat /etc/ssh/sshd_config > /etc/ssh/sshd_config.bak

sed -i ‘s/#Port 22/Port 22022/‘ /etc/ssh/sshd_config

sed -i ‘s/#PermitEmptyPasswords no/PermitEmptyPasswords no/‘ /etc/ssh/sshd_config

sed -i ‘s/#UseDNS yes/UseDNS no/‘ /etc/ssh/sshd_config

/etc/init.d/sshd reload > /dev/null 2 >& 1

[ $? -eq 0 ] && action "Ssh is ok" /bin/true || exit 1

}

#sync time

syncSystemTime(){

ping www.baidu.com -c 1 > /dev/null 2 >& 1

if [ $? -eq 0 -a `grep pool.ntp.org /var/spool/cron/root | grep -v grep | wc -l` -lt 1 ]; then

echo "*/5 * * * * /usr/sbin/ntpdate time.windows.com > /dev/null 2>&1" >> /var/spool/cron/root

[ $? -eq 0 ] && action "SystemTime is ok" /bin/true || exit 1

fi

}

#change file inode

openFiles(){

cat /etc/security/limits.conf > /etc/security/limits.conf.bak

echo "ulimit -HSn 65535" >> /etc/security/limits.conf

sysctl -p

[ $? -eq 0 ] && action "limit is ok" /bin/true || exi 1

sleep 1

}

#youhua kernel

openKernel(){

cat /etc/sysctl.conf > /etc/sysctl.conf.bak

cat >> /etc/sysctl.conf << EOF

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.ip_local_port_range = 102465000

net.ipv4.tcp_max_syn_backlog = 8192

net.ipv4.tcp_max_tw_buckets = 5000

net.ipv4.tcp_mem = 192000 300000 732000

net.ipv4.tcp_rmem = 51200 131072 204800

net.ipv4.tcp_wmem = 51200 131072 204800

net.ipv4.tcp_orphan_retries = 3

net.ipv4.tcp_syn_retries = 3

net.ipv4.tcp_synack_retries = 3

net.ipv4.tcp_retries2 = 5

net.ipv4.tcp_fin_timeout = 30

net.ipv4.tcp_max_orphans = 2000

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_keepalive_time = 20

net.ipv4.tcp_keepalive_intvl = 5

net.ipv4.tcp_keepalive_probes = 2

vm.dirty_expire_centisecs = 1500

vm.dirty_writeback_centisecs = 1000

vm.dirty_ratio = 20

vm.dirty_background_ratio = 100

vm.min_free_kbytes=409600

vm.vfs_cache_pressure=200

vm.swappiness = 40

EOF

/sbin/sysctl -p && action "kernel is ok" /bin/true || action "kernel is faile" /bin/false

sleep 1

}

#init_snmp

init_snmp(){

cat /etc/snmp/snmpd.conf > /etc/snmp/snmpd.conf.bak

sed -i ‘s/#view all/view all/‘ /etc/snmp/snmpd.conf

sed -i ‘s/#access MyROGroup/access MyROGroup/‘ /etc/snmp/snmpd.conf

${CHKCONFIG} snmpd on

${SERVICE} snmpd start

[ $? -eq 0 ] && action "snmpd is starting" /bin/true \

|| action "snmpd is faile" /bin/false

}

installTool

initI18n

initSelinux

initService

initSsh

syncSystemTime

openFiles

openKernel

init_snmp

时间: 2024-12-22 20:31:36

一键优化系统脚本 for centos6.x的相关文章

优化系统脚本(简写)

#!/bin/bash #set env export LANG="en_US.UTF-8" export PATH=$PATH:/bin/sbin:/usr/sbin #whether root to running user if [[ $(whoami) != root ]];then echo "please su - root run the script." fi SERVICE=`which service` CHKCONFIG=`which chkc

centos一键优化脚本

centos一键优化脚本:细节:http://oldboy.blog.51cto.com/2561410/1336488网络状态优化:http://oldboy.blog.51cto.com/2561410/1184228定时任务优化:http://oldboy.blog.51cto.com/2561410/1216730一键脚本:较简单: http://mofansheng.blog.51cto.com/8792265/1710247较健全: http://chocolee.blog.51ct

linux服务器一键优化脚本

服务器一键优化脚本,高亮显示 内容:关闭selinux.时间同步设置.zabbix-agent安装.句柄数调优.常用软件安装.永久静态路由添加 #/bin/bash echo "####start shutdown selinux########" sed -i 's/SELINK=enforcing/SELINK=disabled/' /etc/selinux/config setenforce 0 value_selinux=`getenforce` if [ value_seli

httpd 一键编译安装脚本(centos6&amp;7_httpd2.2&amp;2.4)

httpd 一键编译安装脚本(centos6&7_httpd2.2&2.4) 说明 此安装脚本中涉及的服务启动脚本需要单独编写 httpd_install.sh #!/bin/bash # ***************************************************** # author : shchangming # date : 2018-06-06 # QQ : 414945814 # Description: this script is to insta

redha 精简开机,优化系统

我们用windows系统的时候,也经常碰到开机太慢.有很多的程序拖慢了我们的电脑,linux系统也是,也有这些不需要的程序.开机的时候自动开启.今天就分享两种方法,优化系统,把这些没必要的东西都关掉. 首先我们用chkconfig --list | grep "3:on" 查看有哪些程序都是开着的. 我用的是文本界面所以过滤的时候写的是3,如果是图形模式就改成5. 一.这种方法比较麻烦,需要一个一个的取消.     1)输入 setup 开启设置              2)这里就开

Rehat一键安装mysql脚本和备份数据库脚本

Rehat一键安装mysql脚本 ##说明:适用,Rehat 5 6 7 1.运行状态,运行成功输出mysql临时密码 2.代码如下 #!/bin/bash #获取系统信息 sudo cat /etc/issue>myfile aa=sudo grep '5.' myfile bb=sudo grep '6.' myfile cc=sudo grep '7.' myfile echo $aa echo "It is a test" > myfile #获取系统信息 sudo

LNMP一键安装shell脚本(v1.2)

鉴于搭建一个LNMP环境使用一步一步的方法安装比较笨拙,故将安装步骤编写成一个简单shell脚本,并且能实现大部分需求 适合的系统版本:CentOS6.5-6.7 64位 安装的前提准备: mysql-5.6.28.tar.gz cmake-3.4.3.tar.gz nginx-1.8.1.tar.gz libgd-2.1.1.tar.bz2 ibiconv-1.14.tar.gz jpegsrc.v6b.tar.gz php-5.6.20.tar.bz2 将以上的源码包download下来放并

Centos Denyhosts 一键安装配置脚本

一键安装denyhosts脚本并配置为常用配置.放置Linux服务器被暴力破解 由于不能上传tar文件.所以改为zip压缩. 将附件的zip压缩包解压后将整个文件夹上传到服务器. 然后进入denyhost文件夹 赋予脚本执行权限. chmod 700 denyhosts.sh ./ denyhosts.sh 脚本内容是: denyhosts.sh #!/bin/bash   # Copyright (c) 2015.6  Fenei # BY:封飞 # 2015年6月29日23点 # denyh

一键安装shell脚本

一.一键安装nginx脚本 #!/bin/bash #################################### #Name:nginx_install.sh #Author:doublelinux #version:1.1 #Date:2017/08/19 #################################### yum -y install pcre pcre-devel yum -y install openssl openssl-devel mkdir -p