#!/bin/sh# 服务优化,(sshd、network、crond、syslog、rsyslog)服务保持默认开机启动ServiceList=$(chkconfig --list | grep‘0‘| awk‘{print $1}‘| grep-Ev ‘sshd|network|crond|syslog‘) forService in$ServiceListdo /etc/init.d/$Service stop chkconfig --level 0123456 $Service offdone# 内核参数调优grep-q "vm.swappiness = 0" /etc/sysctl.conf || cat>> /etc/sysctl.conf << EOF########################################vm.swappiness = 0net.core.rmem_default = 262144net.core.rmem_max = 16777216net.core.wmem_default = 262144net.core.wmem_max = 16777216net.core.somaxconn = 262144net.core.netdev_max_backlog = 262144net.ipv4.tcp_max_orphans = 262144net.ipv4.tcp_max_syn_backlog = 262144net.ipv4.tcp_max_tw_buckets = 10000net.ipv4.ip_local_port_range = 1024 65500net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_syncookies = 1net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_fin_timeout = 30net.ipv4.tcp_keepalive_time = 1200net.ipv4.tcp_mem = 786432 1048576 1572864fs.aio-max-nr = 1048576fs.file-max = 6815744kernel.sem = 250 32000 100 128fs.inotify.max_user_watches = 1048576EOFsysctl -pgrep-q "* - nofile 65536" /etc/security/limits.conf || cat>> /etc/security/limits.conf << EOF########################################* - nofile 1048576* - nproc 65536* - stack 1024EOFgrep-q "ulimit -n 65536" /etc/profile|| cat>> /etc/profile<< EOF########################################ulimit-n 1048576ulimit-u 65536ulimit-s 1024alias grep=‘grep --color=auto‘exportHISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "EOF# 禁用并关闭selinuxsed-i ‘s/SELINUX=enforcing/SELINUX=disabled/‘/etc/selinux/configsetenforce 0# 优化SSHsed-i ‘s/.*UseDNS yes/UseDNS no/‘/etc/ssh/sshd_configsed-i ‘s/.*GSSAPIAuthentication yes/GSSAPIAuthentication no/‘/etc/ssh/sshd_config/etc/init.d/sshdrestart# 脚本目录加入PATH环境变量grep -q "/App/script"$HOME/.bash_profile || cat>> $HOME/.bash_profile << EOF########################################exportPATH=/App/script:\$PATHEOFmkdir-p /App/script /App/src# 挂载tmpfs文件系统mount--bind /dev/shm/tmpgrep-q "/dev/shm"/etc/rc.local|| echo"/bin/mount --bind /dev/shm /tmp" >> /etc/rc.local
This article is from the It Dick thread blog, so be sure to keep this source http://68686789.blog.51cto.com/10438688/1717608
Common Linux system optimization scripts