常用Linux系统优化脚本

本文发布时间: 2019-Mar-22
该脚本是我常用的系统安装后执行脚本,包括开机启动服务、内核、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 "vm.swappiness" /etc/sysctl.conf || cat >> /etc/sysctl.conf########################################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" /etc/security/limits.conf || cat >> /etc/security/limits.conf########################################* - nofile 1048576* - nproc 65536* - stack 1024EOFgrep -q "ulimit -n" /etc/profile || cat >> /etc/profile########################################ulimit -n 1048576ulimit -u 65536ulimit -s 1024alias 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########################################export PATH=/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


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:08pm
栏目列表