博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
常用Linux系统优化脚本
阅读量:7080 次
发布时间:2019-06-28

本文共 2242 字,大约阅读时间需要 7 分钟。

hot3.png

该脚本是我常用的系统安装后执行脚本,包括开机启动服务、内核、SSH优化。

#!/bin/sh# 服务优化,(sshd、network、crond、syslog、rsyslog)服务保持默认开机启动ServiceList=$(chkconfig --list | grep '0' | awk '{print $1}' | grep -Ev 'sshd|network|crond|syslog')for Service in $ServiceListdo    /etc/init.d/$Service stop    chkconfig --level 0123456 $Service offdone# 内核参数调优grep -q "net.ipv4.tcp_max_tw_buckets" /etc/sysctl.conf || cat >> /etc/sysctl.conf << EOF########################################net.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 = 600net.ipv4.tcp_keepalive_intvl = 30net.ipv4.tcp_keepalive_probes = 3net.ipv4.tcp_mem = 786432 1048576 1572864fs.aio-max-nr = 1048576fs.file-max = 6815744kernel.sem = 250 32000 100 128vm.swappiness = 10EOFsysctl -pgrep -q "* soft nofile 60000" /etc/security/limits.conf || cat >> /etc/security/limits.conf << EOF########################################* soft nofile 60000* hard nofile 65536EOFgrep -q "ulimit -Sn 60000" /etc/profile || cat >> /etc/profile << EOF########################################ulimit -Sn 60000ulimit -Hn 65536alias grep='grep --color=auto'export HISTTIMEFORMAT="%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/sshd restart# 脚本目录加入PATH环境变量grep -q "/App/script" $HOME/.bash_profile || cat >> $HOME/.bash_profile << EOF########################################export PATH=/App/script:\$PATHEOF# 新建常用脚本和源码文件包存放路径mkdir -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

本文出自 “” 博客,请务必保留此出处

转载于:https://my.oschina.net/dongsong/blog/417977

你可能感兴趣的文章